diff --git a/composer.json b/composer.json index 864453af0..d4e589058 100644 --- a/composer.json +++ b/composer.json @@ -76,7 +76,7 @@ "stan-setup": "phive install", "lowest": "validate-prefer-lowest", "lowest-setup": "composer update --prefer-lowest --prefer-stable --prefer-dist --no-interaction && cp composer.json composer.backup && composer require --dev dereuromark/composer-prefer-lowest && mv composer.backup composer.json", - "rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:\"~2.3.1\" phpstan/phpstan:\"~2.1.40\" && mv composer.backup composer.json", + "rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:\"~2.7.0\" phpstan/phpstan:\"~2.3.0\" && mv composer.backup composer.json", "rector-check": "vendor/bin/rector process --dry-run", "rector-fix": "vendor/bin/rector process", "test": "phpunit", diff --git a/phpcs.xml b/phpcs.xml index e89659f62..3f98c58c2 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -18,6 +18,15 @@ + + */src/* + */tests/* + + + + + + 0 diff --git a/rector.php b/rector.php index a93e7edcf..fd378e4a1 100644 --- a/rector.php +++ b/rector.php @@ -3,12 +3,16 @@ use Rector\Caching\ValueObject\Storage\FileCacheStorage; use Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector; -use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector; +use Rector\CodeQuality\Rector\If_\ArrayExplicitBoolCompareRector; +use Rector\CodeQuality\Rector\If_\ObjectExplicitBoolCompareRector; use Rector\CodingStyle\Rector\Assign\SplitDoubleAssignRector; use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector; use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector; use Rector\Config\RectorConfig; +use Rector\DeadCode\Rector\ClassMethod\RemoveDuplicatedReturnSelfDocblockRector; +use Rector\DeadCode\Rector\ClassMethod\RemoveMixedDocblockOverruledByNativeTypeRector; use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector; +use Rector\DeadCode\Rector\ClassMethod\RemoveUselessUnionReturnDocblockRector; use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; use Rector\Set\ValueObject\SetList; @@ -49,6 +53,10 @@ ReturnTypeFromStrictFluentReturnRector::class, SplitDoubleAssignRector::class, NewlineAfterStatementRector::class, - ExplicitBoolCompareRector::class, TypedPropertyFromCreateMockAssignRector::class, + ArrayExplicitBoolCompareRector::class, + ObjectExplicitBoolCompareRector::class, + RemoveUselessUnionReturnDocblockRector::class, + RemoveMixedDocblockOverruledByNativeTypeRector::class, + RemoveDuplicatedReturnSelfDocblockRector::class, ]); diff --git a/src/Command/BakeMigrationDiffCommand.php b/src/Command/BakeMigrationDiffCommand.php index e03c8b1eb..5150b12b2 100644 --- a/src/Command/BakeMigrationDiffCommand.php +++ b/src/Command/BakeMigrationDiffCommand.php @@ -312,9 +312,7 @@ protected function getColumns(): void if ($attribute === 'length') { $phinxAttributeName = 'limit'; } - if (!isset($changedAttributes[$phinxAttributeName])) { - $changedAttributes[$phinxAttributeName] = $column[$attribute]; - } + $changedAttributes[$phinxAttributeName] ??= $column[$attribute]; } // Only convert unsigned to signed if it actually changed @@ -352,9 +350,7 @@ protected function getColumns(): void unset($changedAttributes['limit']); } elseif (isset($changedAttributes['length'])) { // For non-decimal columns, convert 'length' to 'limit' - if (!isset($changedAttributes['limit'])) { - $changedAttributes['limit'] = $changedAttributes['length']; - } + $changedAttributes['limit'] ??= $changedAttributes['length']; unset($changedAttributes['length']); } @@ -363,9 +359,7 @@ protected function getColumns(): void } // columns deletion - if (!isset($this->templateData[$table]['columns']['remove'])) { - $this->templateData[$table]['columns']['remove'] = []; - } + $this->templateData[$table]['columns']['remove'] ??= []; $removedColumns = array_diff($oldColumns, $currentColumns); foreach ($removedColumns as $columnName) { $column = $this->safeGetColumn($this->dumpSchema[$table], $columnName); @@ -484,9 +478,7 @@ protected function getIndexes(): void } // indexes deletion - if (!isset($this->templateData[$table]['indexes']['remove'])) { - $this->templateData[$table]['indexes']['remove'] = []; - } + $this->templateData[$table]['indexes']['remove'] ??= []; $removedIndexes = array_diff($oldIndexes, $currentIndexes); $parts = []; diff --git a/src/Db/Adapter/MysqlAdapter.php b/src/Db/Adapter/MysqlAdapter.php index b3f0002bf..c5fe4a00e 100644 --- a/src/Db/Adapter/MysqlAdapter.php +++ b/src/Db/Adapter/MysqlAdapter.php @@ -441,14 +441,12 @@ protected function mapColumnData(array $data): array break; } } - if ($data['length'] === null) { - $data['length'] = match ($data['type']) { - self::PHINX_TYPE_TINYBLOB => TableSchema::LENGTH_TINY, - self::PHINX_TYPE_MEDIUMBLOB => TableSchema::LENGTH_MEDIUM, - self::PHINX_TYPE_LONGBLOB => TableSchema::LENGTH_LONG, - default => null, - }; - } + $data['length'] ??= match ($data['type']) { + self::PHINX_TYPE_TINYBLOB => TableSchema::LENGTH_TINY, + self::PHINX_TYPE_MEDIUMBLOB => TableSchema::LENGTH_MEDIUM, + self::PHINX_TYPE_LONGBLOB => TableSchema::LENGTH_LONG, + default => null, + }; $data['type'] = 'binary'; } elseif ($data['type'] === self::TYPE_INTEGER) { if (isset($data['length']) && $data['length'] === self::INT_BIG) { diff --git a/src/Db/Adapter/SqliteAdapter.php b/src/Db/Adapter/SqliteAdapter.php index 9736f38f4..e9de11bc2 100644 --- a/src/Db/Adapter/SqliteAdapter.php +++ b/src/Db/Adapter/SqliteAdapter.php @@ -710,7 +710,7 @@ protected function bufferIndicesAndTriggers(AlterInstructions $instructions, str case 'index': $info = $indexMap[$row['name']]; $columns = array_map( - function ($column) { + function ($column): ?string { if ($column === null) { return null; } diff --git a/src/Db/Plan/Plan.php b/src/Db/Plan/Plan.php index 4fe9d7f24..22afad999 100644 --- a/src/Db/Plan/Plan.php +++ b/src/Db/Plan/Plan.php @@ -432,14 +432,10 @@ protected function gatherUpdates(array $actions): void $name = $table->getName(); if ($action instanceof RemoveColumn) { - if (!isset($this->columnRemoves[$name])) { - $this->columnRemoves[$name] = new AlterTable($table); - } + $this->columnRemoves[$name] ??= new AlterTable($table); $this->columnRemoves[$name]->addAction($action); } else { - if (!isset($this->tableUpdates[$name])) { - $this->tableUpdates[$name] = new AlterTable($table); - } + $this->tableUpdates[$name] ??= new AlterTable($table); $this->tableUpdates[$name]->addAction($action); } } @@ -465,9 +461,7 @@ protected function gatherTableMoves(array $actions): void $table = $action->getTable(); $name = $table->getName(); - if (!isset($this->tableMoves[$name])) { - $this->tableMoves[$name] = new AlterTable($table); - } + $this->tableMoves[$name] ??= new AlterTable($table); $this->tableMoves[$name]->addAction($action); } @@ -492,9 +486,7 @@ protected function gatherIndexes(array $actions): void $table = $action->getTable(); $name = $table->getName(); - if (!isset($this->indexes[$name])) { - $this->indexes[$name] = new AlterTable($table); - } + $this->indexes[$name] ??= new AlterTable($table); $this->indexes[$name]->addAction($action); } @@ -522,9 +514,7 @@ protected function gatherConstraints(array $actions): void $table = $action->getTable(); $name = $table->getName(); - if (!isset($this->constraints[$name])) { - $this->constraints[$name] = new AlterTable($table); - } + $this->constraints[$name] ??= new AlterTable($table); $this->constraints[$name]->addAction($action); } @@ -553,9 +543,7 @@ protected function gatherPartitions(array $actions): void $table = $action->getTable(); $name = $table->getName(); - if (!isset($this->partitions[$name])) { - $this->partitions[$name] = new AlterTable($table); - } + $this->partitions[$name] ??= new AlterTable($table); $this->partitions[$name]->addAction($action); } @@ -581,9 +569,7 @@ protected function gatherViewsAndTriggers(array $actions): void $table = $action->getTable(); $name = $table->getName(); - if (!isset($this->viewsAndTriggers[$name])) { - $this->viewsAndTriggers[$name] = new AlterTable($table); - } + $this->viewsAndTriggers[$name] ??= new AlterTable($table); $this->viewsAndTriggers[$name]->addAction($action); } diff --git a/src/TestSuite/Migrator.php b/src/TestSuite/Migrator.php index d62397c20..80a25c728 100644 --- a/src/TestSuite/Migrator.php +++ b/src/TestSuite/Migrator.php @@ -93,9 +93,7 @@ public function runMany( $options[$i] = $migrationSet; $connectionName = $migrationSet['connection']; - if (!isset($connectionsList[$connectionName])) { - $connectionsList[$connectionName] = ['name' => $connectionName, 'skip' => $skip]; - } + $connectionsList[$connectionName] ??= ['name' => $connectionName, 'skip' => $skip]; // Sets sharing a connection and a plugin also share a migration history, // while each of them only has its own source directory on disk. Group diff --git a/src/View/Helper/MigrationHelper.php b/src/View/Helper/MigrationHelper.php index 5cc4cd399..f505967e1 100644 --- a/src/View/Helper/MigrationHelper.php +++ b/src/View/Helper/MigrationHelper.php @@ -424,10 +424,7 @@ public function getColumnOption(array $options): array } else { // Convert CakePHP's precision (decimal places) to Migrations' scale // Only convert if scale is not already set (for decimal columns from diff) - if (!isset($columnOptions['scale'])) { - $columnOptions['scale'] = $columnOptions['precision']; - } - + $columnOptions['scale'] ??= $columnOptions['precision']; if (isset($columnOptions['limit'])) { $columnOptions['precision'] = $columnOptions['limit']; unset($columnOptions['limit']); diff --git a/tests/Fixture/ArticlesFixture.php b/tests/Fixture/ArticlesFixture.php index 67efcd532..c4e6b20c5 100644 --- a/tests/Fixture/ArticlesFixture.php +++ b/tests/Fixture/ArticlesFixture.php @@ -1,4 +1,6 @@