diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon deleted file mode 100644 index 4bc4b682c..000000000 --- a/phpstan-baseline.neon +++ /dev/null @@ -1,43 +0,0 @@ -parameters: - ignoreErrors: - - - message: "#^Negated boolean expression is always false\\.$#" - count: 1 - path: src/Phinx/Console/Command/AbstractCommand.php - - - message: "#^Method Phinx\\\\Db\\\\Adapter\\\\MysqlAdapter::getSqlType\\(\\) should return array but returns array\\.$#" - count: 13 - path: src/Phinx/Db/Adapter/MysqlAdapter.php - - - message: "#^Method Phinx\\\\Db\\\\Adapter\\\\PostgresAdapter::getSqlType\\(\\) should return array but returns array\\.$#" - count: 7 - path: src/Phinx/Db/Adapter/PostgresAdapter.php - - - message: "#^Method Phinx\\\\Db\\\\Adapter\\\\SQLiteAdapter::calculateNewTableColumns\\(\\) should return Phinx\\\\Db\\\\Util\\\\AlterInstructions but returns array\\.$#" - count: 1 - path: src/Phinx/Db/Adapter/SQLiteAdapter.php - - - message: "#^Cannot access offset 'selectColumns' on Phinx\\\\Db\\\\Util\\\\AlterInstructions\\.$#" - count: 1 - path: src/Phinx/Db/Adapter/SQLiteAdapter.php - - - message: "#^Instanceof between string and Phinx\\\\Util\\\\Literal will always evaluate to false\\.$#" - count: 1 - path: src/Phinx/Db/Adapter/SQLiteAdapter.php - - - message: "#^Method Phinx\\\\Db\\\\Adapter\\\\SQLiteAdapter::getSqlType\\(\\) should return array but returns array\\.$#" - count: 1 - path: src/Phinx/Db/Adapter/SQLiteAdapter.php - - - message: "#^Access to undefined constant PDO::SQLSRV_ATTR_ENCODING\\.$#" - count: 1 - path: src/Phinx/Db/Adapter/SqlServerAdapter.php - - - message: "#^Method Phinx\\\\Db\\\\Adapter\\\\SqlServerAdapter::getSqlType\\(\\) should return array but returns array\\.$#" - count: 2 - path: src/Phinx/Db/Adapter/SqlServerAdapter.php - - - - message: "#^If condition is always true\\.$#" - count: 2 - path: src/Phinx/Migration/Manager/Environment.php diff --git a/phpstan.neon b/phpstan.neon index fe9518595..4410e2e0b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -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.#' diff --git a/src/Phinx/Console/Command/AbstractCommand.php b/src/Phinx/Console/Command/AbstractCommand.php index c6bbe73ce..b69218af7 100644 --- a/src/Phinx/Console/Command/AbstractCommand.php +++ b/src/Phinx/Console/Command/AbstractCommand.php @@ -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); } diff --git a/src/Phinx/Db/Adapter/AbstractAdapter.php b/src/Phinx/Db/Adapter/AbstractAdapter.php index fe69a5171..26a201bc5 100644 --- a/src/Phinx/Db/Adapter/AbstractAdapter.php +++ b/src/Phinx/Db/Adapter/AbstractAdapter.php @@ -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); } /** @@ -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); } } diff --git a/src/Phinx/Db/Adapter/AdapterInterface.php b/src/Phinx/Db/Adapter/AdapterInterface.php index af561c43d..774fb1f5d 100644 --- a/src/Phinx/Db/Adapter/AdapterInterface.php +++ b/src/Phinx/Db/Adapter/AdapterInterface.php @@ -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); diff --git a/src/Phinx/Db/Adapter/MysqlAdapter.php b/src/Phinx/Db/Adapter/MysqlAdapter.php index 2fc5778e8..e09fb384e 100644 --- a/src/Phinx/Db/Adapter/MysqlAdapter.php +++ b/src/Phinx/Db/Adapter/MysqlAdapter.php @@ -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)) { @@ -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( @@ -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], "()'")); } @@ -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'; } diff --git a/src/Phinx/Db/Adapter/PostgresAdapter.php b/src/Phinx/Db/Adapter/PostgresAdapter.php index ddc970862..eaaf05cd0 100644 --- a/src/Phinx/Db/Adapter/PostgresAdapter.php +++ b/src/Phinx/Db/Adapter/PostgresAdapter.php @@ -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 { @@ -1382,7 +1382,7 @@ protected function isArrayType($columnType) $baseType = $matches[1]; - return in_array($baseType, $this->getColumnTypes()); + return in_array($baseType, $this->getColumnTypes(), true); } /** diff --git a/src/Phinx/Db/Adapter/SQLiteAdapter.php b/src/Phinx/Db/Adapter/SQLiteAdapter.php index c194b62c9..ab7c3add7 100644 --- a/src/Phinx/Db/Adapter/SQLiteAdapter.php +++ b/src/Phinx/Db/Adapter/SQLiteAdapter.php @@ -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', @@ -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, @@ -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, @@ -90,6 +102,9 @@ class SQLiteAdapter extends PdoAdapter self::PHINX_TYPE_SET, ]; + /** + * @var string[] + */ protected $definitionsWithLimits = [ 'CHAR', 'CHARACTER', @@ -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; @@ -784,7 +799,7 @@ protected function copyAndDropTmpTable($instructions, $tableName) * * @throws \InvalidArgumentException * - * @return \Phinx\Db\Util\AlterInstructions + * @return array */ protected function calculateNewTableColumns($tableName, $columnName, $newColumnName) { @@ -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']; @@ -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; @@ -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']) . ')'; } diff --git a/src/Phinx/Db/Plan/Plan.php b/src/Phinx/Db/Plan/Plan.php index f7413ccb5..4833f4dc1 100644 --- a/src/Phinx/Db/Plan/Plan.php +++ b/src/Phinx/Db/Plan/Plan.php @@ -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(); diff --git a/src/Phinx/Migration/Manager/Environment.php b/src/Phinx/Migration/Manager/Environment.php index 89f2257c1..2115e6b1a 100644 --- a/src/Phinx/Migration/Manager/Environment.php +++ b/src/Phinx/Migration/Manager/Environment.php @@ -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()); } diff --git a/tests/Phinx/Config/ConfigReplaceTokensTest.php b/tests/Phinx/Config/ConfigReplaceTokensTest.php index eeb16756b..56d8937e2 100644 --- a/tests/Phinx/Config/ConfigReplaceTokensTest.php +++ b/tests/Phinx/Config/ConfigReplaceTokensTest.php @@ -13,6 +13,7 @@ class ConfigReplaceTokensTest extends AbstractConfigTest { /** * Data to be saved to $_SERVER and checked later + * * @var array */ protected static $server = [ diff --git a/tests/Phinx/Db/Adapter/PostgresAdapterTest.php b/tests/Phinx/Db/Adapter/PostgresAdapterTest.php index 25ba8170f..adecbf78a 100644 --- a/tests/Phinx/Db/Adapter/PostgresAdapterTest.php +++ b/tests/Phinx/Db/Adapter/PostgresAdapterTest.php @@ -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; @@ -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()); } } @@ -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()); } @@ -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()); } } @@ -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()); } @@ -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()); } @@ -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()); } } diff --git a/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php b/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php index efe0b59fb..961b365ca 100644 --- a/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php +++ b/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php @@ -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']; } } diff --git a/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php b/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php index 015c78aa3..d4fcaba22 100644 --- a/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php +++ b/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php @@ -366,7 +366,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()); } } @@ -380,7 +380,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()); } @@ -395,7 +395,7 @@ public function testAddColumnWithDefaultNull() ->save(); $columns = $this->adapter->getColumns('table1'); foreach ($columns as $column) { - if ($column->getName() == 'default_null') { + if ($column->getName() === 'default_null') { $this->assertNull($column->getDefault()); } } @@ -411,10 +411,10 @@ public function testAddColumnWithDefaultBool() ->save(); $columns = $this->adapter->getColumns('table1'); foreach ($columns as $column) { - if ($column->getName() == 'default_false') { + if ($column->getName() === 'default_false') { $this->assertSame(0, $column->getDefault()); } - if ($column->getName() == 'default_true') { + if ($column->getName() === 'default_true') { $this->assertSame(1, $column->getDefault()); } } @@ -463,7 +463,7 @@ public function testChangeColumnType() $this->assertTrue($this->adapter->hasColumn('t', 'column1')); $columns = $this->adapter->getColumns('t'); foreach ($columns as $column) { - if ($column->getName() == 'column1') { + if ($column->getName() === 'column1') { $this->assertEquals('string', $column->getType()); } } @@ -483,7 +483,7 @@ public function testChangeColumnNameAndNull() $this->assertTrue($this->adapter->hasColumn('t', 'column2')); $columns = $this->adapter->getColumns('t'); foreach ($columns as $column) { - if ($column->getName() == 'column2') { + if ($column->getName() === 'column2') { $this->assertTrue($column->isNull()); } } diff --git a/tests/Phinx/Db/Adapter/TablePrefixAdapterTest.php b/tests/Phinx/Db/Adapter/TablePrefixAdapterTest.php index 4c74645a3..e43c5f7de 100644 --- a/tests/Phinx/Db/Adapter/TablePrefixAdapterTest.php +++ b/tests/Phinx/Db/Adapter/TablePrefixAdapterTest.php @@ -100,7 +100,7 @@ public function testCreateTable() ->method('createTable') ->with($this->callback( function ($table) { - return $table->getName() == 'pre_table_suf'; + return $table->getName() === 'pre_table_suf'; } )); @@ -197,7 +197,7 @@ public function testAddColumn() ->method('addColumn') ->with($this->callback( function ($table) { - return $table->getName() == 'pre_table_suf'; + return $table->getName() === 'pre_table_suf'; }, $this->equalTo($column) )); @@ -335,7 +335,7 @@ public function testAddForeignKey() ->method('addForeignKey') ->with($this->callback( function ($table) { - return $table->getName() == 'pre_table_suf'; + return $table->getName() === 'pre_table_suf'; }, $this->equalTo($foreignKey) )); @@ -369,7 +369,7 @@ public function testInsertData() ->method('bulkinsert') ->with($this->callback( function ($table) { - return $table->getName() == 'pre_table_suf'; + return $table->getName() === 'pre_table_suf'; }, $this->equalTo($row) )); diff --git a/tests/Phinx/Migration/ManagerTest.php b/tests/Phinx/Migration/ManagerTest.php index d9aa80f11..23a673da6 100644 --- a/tests/Phinx/Migration/ManagerTest.php +++ b/tests/Phinx/Migration/ManagerTest.php @@ -5783,7 +5783,7 @@ public function testBreakpointsTogglingOperateAsExpected() // ensure no other data has changed. foreach ($originalVersions as $originalVersionKey => $originalVersion) { foreach ($originalVersion as $column => $value) { - if (!is_numeric($column) && $column != 'breakpoint') { + if (!is_numeric($column) && $column !== 'breakpoint') { $this->assertEquals($value, $firstToggle[$originalVersionKey][$column]); } } @@ -5803,7 +5803,7 @@ public function testBreakpointsTogglingOperateAsExpected() // ensure no other data has changed. foreach ($originalVersions as $originalVersionKey => $originalVersion) { foreach ($originalVersion as $column => $value) { - if (!is_numeric($column) && $column != 'breakpoint') { + if (!is_numeric($column) && $column !== 'breakpoint') { $this->assertEquals($value, $secondToggle[$originalVersionKey][$column]); } } @@ -5845,7 +5845,7 @@ public function testBreakpointsTogglingOperateAsExpected() // ensure no other data has changed. foreach ($originalVersions as $originalVersionKey => $originalVersion) { foreach ($originalVersion as $column => $value) { - if (!is_numeric($column) && $column != 'breakpoint') { + if (!is_numeric($column) && $column !== 'breakpoint') { $this->assertEquals($value, $setLastVersions[$originalVersionKey][$column]); } } @@ -5865,7 +5865,7 @@ public function testBreakpointsTogglingOperateAsExpected() // ensure no other data has changed. foreach ($originalVersions as $originalVersionKey => $originalVersion) { foreach ($originalVersion as $column => $value) { - if (!is_numeric($column) && $column != 'breakpoint') { + if (!is_numeric($column) && $column !== 'breakpoint') { $this->assertEquals($value, $resetVersions[$originalVersionKey][$column]); } } @@ -5885,7 +5885,7 @@ public function testBreakpointsTogglingOperateAsExpected() // ensure no other data has changed. foreach ($originalVersions as $originalVersionKey => $originalVersion) { foreach ($originalVersion as $column => $value) { - if (!is_numeric($column) && $column != 'breakpoint') { + if (!is_numeric($column) && $column !== 'breakpoint') { $this->assertEquals($value, $unsetLastVersions[$originalVersionKey][$column]); } }