Skip to content

Commit

Permalink
Merge pull request #1735 from cakephp/cleanup
Browse files Browse the repository at this point in the history
Fix phpstan issues.
  • Loading branch information
saeideng authored Apr 10, 2020
2 parents 415000c + 9a7454d commit 4b3ed1a
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 98 deletions.
43 changes: 0 additions & 43 deletions phpstan-baseline.neon

This file was deleted.

4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
includes:
- phpstan-baseline.neon
parameters:
level: 5
treatPhpDocTypesAsCertain: false
ignoreErrors:
- '#Unsafe usage of new static\(\)\.#'
- '#Parameter \#2 \$callback of function array_filter expects callable\(mixed, mixed\): bool, .+ given.#'
- '#Access to undefined constant PDO::SQLSRV_ATTR_ENCODING.#'
4 changes: 3 additions & 1 deletion src/Phinx/Console/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ protected function configure()
*/
public function bootstrap(InputInterface $input, OutputInterface $output)
{
if (!$this->getConfig()) {
/** @var \Phinx\Config\ConfigInterface|null $config */
$config = $this->getConfig();
if (!$config) {
$this->loadConfig($input, $output);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Phinx/Db/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public function getAdapterType()
*/
public function isValidColumnType(Column $column)
{
return $column->getType() instanceof Literal || in_array($column->getType(), $this->getColumnTypes());
return $column->getType() instanceof Literal || in_array($column->getType(), $this->getColumnTypes(), true);
}

/**
Expand Down Expand Up @@ -410,6 +410,6 @@ protected function removeCreatedTable($tableName)
*/
protected function hasCreatedTable($tableName)
{
return in_array($tableName, $this->createdTables);
return in_array($tableName, $this->createdTables, true);
}
}
2 changes: 1 addition & 1 deletion src/Phinx/Db/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ public function isValidColumnType(Column $column);
* @param string $type
* @param int|null $limit
*
* @return string[]
* @return array
*/
public function getSqlType($type, $limit = null);

Expand Down
10 changes: 5 additions & 5 deletions src/Phinx/Db/Adapter/MysqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ protected function getRenameColumnInstructions($tableName, $columnName, $newColu

foreach ($rows as $row) {
if (strcasecmp($row['Field'], $columnName) === 0) {
$null = ($row['Null'] == 'NO') ? 'NOT NULL' : 'NULL';
$null = ($row['Null'] === 'NO') ? 'NOT NULL' : 'NULL';
$comment = isset($row['Comment']) ? ' COMMENT ' . '\'' . addslashes($row['Comment']) . '\'' : '';
$extra = ' ' . strtoupper($row['Extra']);
if (($row['Default'] !== null)) {
Expand Down Expand Up @@ -590,7 +590,7 @@ protected function getAddIndexInstructions(Table $table, Index $index)
{
$instructions = new AlterInstructions();

if ($index->getType() == Index::FULLTEXT) {
if ($index->getType() === Index::FULLTEXT) {
// Must be executed separately
// SQLSTATE[HY000]: General error: 1795 InnoDB presently supports one FULLTEXT index creation at a time
$alter = sprintf(
Expand Down Expand Up @@ -1080,7 +1080,7 @@ public function getPhinxType($sqlTypeDef)
'scale' => $scale,
];

if ($type == static::PHINX_TYPE_ENUM || $type == static::PHINX_TYPE_SET) {
if ($type === static::PHINX_TYPE_ENUM || $type === static::PHINX_TYPE_SET) {
$phinxType['values'] = explode("','", trim($matches[6], "()'"));
}

Expand Down Expand Up @@ -1188,11 +1188,11 @@ protected function getIndexSqlDefinition(Index $index)
$def = '';
$limit = '';

if ($index->getType() == Index::UNIQUE) {
if ($index->getType() === Index::UNIQUE) {
$def .= ' UNIQUE';
}

if ($index->getType() == Index::FULLTEXT) {
if ($index->getType() === Index::FULLTEXT) {
$def .= ' FULLTEXT';
}

Expand Down
4 changes: 2 additions & 2 deletions src/Phinx/Db/Adapter/PostgresAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ protected function getColumnSqlDefinition(Column $column)
{
$buffer = [];
if ($column->isIdentity()) {
$buffer[] = $column->getType() == 'biginteger' ? 'BIGSERIAL' : 'SERIAL';
$buffer[] = $column->getType() === 'biginteger' ? 'BIGSERIAL' : 'SERIAL';
} elseif ($column->getType() instanceof Literal) {
$buffer[] = (string)$column->getType();
} else {
Expand Down Expand Up @@ -1382,7 +1382,7 @@ protected function isArrayType($columnType)

$baseType = $matches[1];

return in_array($baseType, $this->getColumnTypes());
return in_array($baseType, $this->getColumnTypes(), true);
}

/**
Expand Down
33 changes: 24 additions & 9 deletions src/Phinx/Db/Adapter/SQLiteAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@
*/
class SQLiteAdapter extends PdoAdapter
{
// list of supported Phinx column types with their SQL equivalents
// some types have an affinity appended to ensure they do not receive NUMERIC affinity
/**
* List of supported Phinx column types with their SQL equivalents
* some types have an affinity appended to ensure they do not receive NUMERIC affinity
*
* @var string[]
*/
protected static $supportedColumnTypes = [
self::PHINX_TYPE_BIG_INTEGER => 'biginteger',
self::PHINX_TYPE_BINARY => 'binary_blob',
Expand All @@ -54,7 +58,11 @@ class SQLiteAdapter extends PdoAdapter
self::PHINX_TYPE_VARBINARY => 'varbinary_blob',
];

// list of aliases of supported column types
/**
* List of aliases of supported column types
*
* @var string[]
*/
protected static $supportedColumnTypeAliases = [
'varchar' => self::PHINX_TYPE_STRING,
'tinyint' => self::PHINX_TYPE_SMALL_INTEGER,
Expand All @@ -73,7 +81,11 @@ class SQLiteAdapter extends PdoAdapter
'real' => self::PHINX_TYPE_FLOAT,
];

// list of known but unsupported Phinx column types
/**
* List of known but unsupported Phinx column types
*
* @var string[]
*/
protected static $unsupportedColumnTypes = [
self::PHINX_TYPE_BIT,
self::PHINX_TYPE_CIDR,
Expand All @@ -90,6 +102,9 @@ class SQLiteAdapter extends PdoAdapter
self::PHINX_TYPE_SET,
];

/**
* @var string[]
*/
protected $definitionsWithLimits = [
'CHAR',
'CHARACTER',
Expand Down Expand Up @@ -557,7 +572,7 @@ protected function parseDefaultValue($v, $t)
} elseif (preg_match('/^[+-]?\d+$/i', $vBare)) {
$int = (int)$vBare;
// integer literal
if ($t === self::PHINX_TYPE_BOOLEAN && ($int == 0 || $int == 1)) {
if ($t === self::PHINX_TYPE_BOOLEAN && ($int === 0 || $int === 1)) {
return (bool)$int;
} else {
return $int;
Expand Down Expand Up @@ -784,7 +799,7 @@ protected function copyAndDropTmpTable($instructions, $tableName)
*
* @throws \InvalidArgumentException
*
* @return \Phinx\Db\Util\AlterInstructions
* @return array
*/
protected function calculateNewTableColumns($tableName, $columnName, $newColumnName)
{
Expand All @@ -798,7 +813,7 @@ protected function calculateNewTableColumns($tableName, $columnName, $newColumnN
$selectName = $column['name'];
$writeName = $selectName;

if ($selectName == $columnName) {
if ($selectName === $columnName) {
$writeName = $newColumnName;
$found = true;
$columnType = $column['type'];
Expand Down Expand Up @@ -1390,7 +1405,7 @@ public function getPhinxType($sqlTypeDef)
if (isset(self::$supportedColumnTypes[$typeLC])) {
// the type is an explicitly supported type
$name = $typeLC;
} elseif ($typeLC === 'tinyint' && $limit == 1) {
} elseif ($typeLC === 'tinyint' && $limit === 1) {
// the type is a MySQL-style boolean
$name = static::PHINX_TYPE_BOOLEAN;
$limit = null;
Expand Down Expand Up @@ -1463,7 +1478,7 @@ protected function getColumnSqlDefinition(Column $column)
$sqlType = $this->getSqlType($column->getType());
$def = strtoupper($sqlType['name']);

$limitable = in_array(strtoupper($sqlType['name']), $this->definitionsWithLimits);
$limitable = in_array(strtoupper($sqlType['name']), $this->definitionsWithLimits, true);
if (($column->getLimit() || isset($sqlType['limit'])) && $limitable) {
$def .= '(' . ($column->getLimit() ?: $sqlType['limit']) . ')';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Phinx/Db/Plan/Plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ protected function resolveConflicts()
// but it is a conflicting action. Luckily solving the conflict can be done by moving
// the ChangeColumn action to another AlterTable
->unfold(new ActionSplitter(RenameColumn::class, ChangeColumn::class, function (RenameColumn $a, ChangeColumn $b) {
return $a->getNewName() == $b->getColumnName();
return $a->getNewName() === $b->getColumnName();
}))
->toList();

Expand Down
8 changes: 6 additions & 2 deletions src/Phinx/Migration/Manager/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,15 @@ public function getAdapter()
->getWrapper($options['wrapper'], $adapter);
}

if ($this->getInput()) {
/** @var \Symfony\Component\Console\Input\InputInterface|null $input */
$input = $this->getInput();
if ($input) {
$adapter->setInput($this->getInput());
}

if ($this->getOutput()) {
/** @var \Symfony\Component\Console\Output\OutputInterface|null $output */
$output = $this->getOutput();
if ($output) {
$adapter->setOutput($this->getOutput());
}

Expand Down
1 change: 1 addition & 0 deletions tests/Phinx/Config/ConfigReplaceTokensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ConfigReplaceTokensTest extends AbstractConfigTest
{
/**
* Data to be saved to $_SERVER and checked later
*
* @var array
*/
protected static $server = [
Expand Down
26 changes: 13 additions & 13 deletions tests/Phinx/Db/Adapter/PostgresAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ private static function isPostgresAvailable()
{
static $available;

if (is_null($available)) {
$available = in_array('pgsql', \PDO::getAvailableDrivers());
if ($available === null) {
$available = in_array('pgsql', \PDO::getAvailableDrivers(), true);
}

return $available;
Expand Down Expand Up @@ -482,7 +482,7 @@ public function testAddColumnWithDefaultValue()
->save();
$columns = $this->adapter->getColumns('table1');
foreach ($columns as $column) {
if ($column->getName() == 'default_zero') {
if ($column->getName() === 'default_zero') {
$this->assertEquals("test", $column->getDefault());
}
}
Expand All @@ -496,7 +496,7 @@ public function testAddColumnWithDefaultZero()
->save();
$columns = $this->adapter->getColumns('table1');
foreach ($columns as $column) {
if ($column->getName() == 'default_zero') {
if ($column->getName() === 'default_zero') {
$this->assertNotNull($column->getDefault());
$this->assertEquals('0', $column->getDefault());
}
Expand All @@ -513,15 +513,15 @@ public function testAddColumnWithDefaultBoolean()
->save();
$columns = $this->adapter->getColumns('table1');
foreach ($columns as $column) {
if ($column->getName() == 'default_true') {
if ($column->getName() === 'default_true') {
$this->assertNotNull($column->getDefault());
$this->assertEquals('true', $column->getDefault());
}
if ($column->getName() == 'default_false') {
if ($column->getName() === 'default_false') {
$this->assertNotNull($column->getDefault());
$this->assertEquals('false', $column->getDefault());
}
if ($column->getName() == 'default_null') {
if ($column->getName() === 'default_null') {
$this->assertNull($column->getDefault());
}
}
Expand Down Expand Up @@ -569,7 +569,7 @@ public function testAddColumnWithDefaultLiteral()
->save();
$columns = $this->adapter->getColumns('table1');
foreach ($columns as $column) {
if ($column->getName() == 'default_ts') {
if ($column->getName() === 'default_ts') {
$this->assertNotNull($column->getDefault());
$this->assertEquals('now()', (string)$column->getDefault());
}
Expand Down Expand Up @@ -638,12 +638,12 @@ public function testAddDecimalWithPrecisionAndScale()
->save();
$columns = $this->adapter->getColumns('table1');
foreach ($columns as $column) {
if ($column->getName() == 'number') {
if ($column->getName() === 'number') {
$this->assertEquals("10", $column->getPrecision());
$this->assertEquals("2", $column->getScale());
}

if ($column->getName() == 'number2') {
if ($column->getName() === 'number2') {
$this->assertEquals("12", $column->getPrecision());
$this->assertEquals("0", $column->getScale());
}
Expand All @@ -660,15 +660,15 @@ public function testAddTimestampWithPrecision()
->save();
$columns = $this->adapter->getColumns('table1');
foreach ($columns as $column) {
if ($column->getName() == 'timestamp1') {
if ($column->getName() === 'timestamp1') {
$this->assertEquals("0", $column->getPrecision());
}

if ($column->getName() == 'timestamp2') {
if ($column->getName() === 'timestamp2') {
$this->assertEquals("4", $column->getPrecision());
}

if ($column->getName() == 'timestamp3') {
if ($column->getName() === 'timestamp3') {
$this->assertEquals("6", $column->getPrecision());
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Phinx/Db/Adapter/SQLiteAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ public function testAddColumnWithComment()
$rows = $this->adapter->fetchAll('select * from sqlite_master where `type` = \'table\'');

foreach ($rows as $row) {
if ($row['tbl_name'] == 'table1') {
if ($row['tbl_name'] === 'table1') {
$sql = $row['sql'];
}
}
Expand Down
Loading

0 comments on commit 4b3ed1a

Please sign in to comment.