diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fcdc844d..716c7f36 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,13 +21,14 @@ jobs: steps: - uses: actions/checkout@v5 + - uses: actions/checkout@v6 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-version }} extensions: mbstring, intl - coverage: pcov + coverage: none - name: Cache composer dependencies id: composer-cache @@ -53,24 +54,14 @@ jobs: run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Run PHPUnit - run: | - if [[ "${{ matrix.php-version }}" == "8.1" && "${{ matrix.prefer-lowest }}" != "prefer-lowest" ]]; then - export CODECOVERAGE=1 - vendor/bin/phpunit --display-incomplete --display-skipped --coverage-clover=coverage.xml - else - vendor/bin/phpunit - fi - - - name: Submit code coverage - if: matrix.php-version == '8.1' && matrix.prefer-lowest != 'prefer-lowest' - uses: codecov/codecov-action@v5 + run: vendor/bin/phpunit --display-incomplete --display-skipped cs-stan: name: Coding Standard & Static Analysis runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/README.md b/README.md index 7755e9de..21be2ab2 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ The upgrade tool also includes rulesets for related tools and libraries: - **chronos3** - Upgrade to Chronos 3.x - **migrations45** - Upgrade to Migrations 4.5 +- **migrations50** - Upgrade to Migrations 5.0 - **phpunit80** - Upgrade to PHPUnit 8.0 ```bash @@ -114,6 +115,9 @@ bin/cake upgrade rector --rules chronos3 /path/to/your/app/src # Apply Migrations 4.5 upgrade rules bin/cake upgrade rector --rules migrations45 /path/to/your/app/config +# Apply Migrations 5.0 upgrade rules +bin/cake upgrade rector --rules migrations50 /path/to/your/app/config + # Apply PHPUnit 8.0 upgrade rules bin/cake upgrade rector --rules phpunit80 /path/to/your/app/tests ``` diff --git a/config/rector/migrations50.php b/config/rector/migrations50.php new file mode 100644 index 00000000..70ca4023 --- /dev/null +++ b/config/rector/migrations50.php @@ -0,0 +1,9 @@ +sets([CakePHPSetList::MIGRATIONS_50]); +}; diff --git a/config/rector/sets/migrations50.php b/config/rector/sets/migrations50.php new file mode 100644 index 00000000..4e29739e --- /dev/null +++ b/config/rector/sets/migrations50.php @@ -0,0 +1,57 @@ + 'TYPE_STRING', + 'PHINX_TYPE_CHAR' => 'TYPE_CHAR', + 'PHINX_TYPE_TEXT' => 'TYPE_TEXT', + 'PHINX_TYPE_INTEGER' => 'TYPE_INTEGER', + 'PHINX_TYPE_TINY_INTEGER' => 'TYPE_TINYINTEGER', + 'PHINX_TYPE_SMALL_INTEGER' => 'TYPE_SMALLINTEGER', + 'PHINX_TYPE_BIG_INTEGER' => 'TYPE_BIGINTEGER', + 'PHINX_TYPE_FLOAT' => 'TYPE_FLOAT', + 'PHINX_TYPE_DECIMAL' => 'TYPE_DECIMAL', + 'PHINX_TYPE_DATETIME' => 'TYPE_DATETIME', + 'PHINX_TYPE_TIMESTAMP' => 'TYPE_TIMESTAMP', + 'PHINX_TYPE_TIME' => 'TYPE_TIME', + 'PHINX_TYPE_DATE' => 'TYPE_DATE', + 'PHINX_TYPE_BINARY' => 'TYPE_BINARY', + 'PHINX_TYPE_BINARYUUID' => 'TYPE_BINARY_UUID', + 'PHINX_TYPE_BOOLEAN' => 'TYPE_BOOLEAN', + 'PHINX_TYPE_JSON' => 'TYPE_JSON', + 'PHINX_TYPE_UUID' => 'TYPE_UUID', + 'PHINX_TYPE_NATIVEUUID' => 'TYPE_NATIVE_UUID', + + // Geospatial types + 'PHINX_TYPE_GEOMETRY' => 'TYPE_GEOMETRY', + 'PHINX_TYPE_POINT' => 'TYPE_POINT', + 'PHINX_TYPE_LINESTRING' => 'TYPE_LINESTRING', + 'PHINX_TYPE_POLYGON' => 'TYPE_POLYGON', + + // Geospatial array constant + 'PHINX_TYPES_GEOSPATIAL' => 'TYPES_GEOSPATIAL', + + // Database-specific types + 'PHINX_TYPE_YEAR' => 'TYPE_YEAR', + 'PHINX_TYPE_CIDR' => 'TYPE_CIDR', + 'PHINX_TYPE_INET' => 'TYPE_INET', + 'PHINX_TYPE_MACADDR' => 'TYPE_MACADDR', + 'PHINX_TYPE_INTERVAL', 'TYPE_INTERVAL', + ]; + + foreach ($constantMap as $oldConstant => $newConstant) { + $rectorConfig->ruleWithConfiguration(RenameClassConstFetchRector::class, [ + new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', $oldConstant, $newConstant), + ]); + } +}; diff --git a/src/Command/RectorCommand.php b/src/Command/RectorCommand.php index 8703421f..2e3810fd 100644 --- a/src/Command/RectorCommand.php +++ b/src/Command/RectorCommand.php @@ -257,6 +257,10 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption 'help' => 'Enable to get a preview of what modifications will be applied.', 'boolean' => true, 'short' => 'd', + ]) + ->addOption('no-diff', [ + 'help' => 'Disable rector diff output which can cause issues with large files.', + 'boolean' => true, ]); return $parser; @@ -274,10 +278,11 @@ protected function buildCommand(Arguments $args, string $autoload, string $confi $cmdPath = ROOT . '/vendor/bin/rector process'; return sprintf( - '%s %s %s --autoload-file=%s --config=%s %s --clear-cache', + '%s %s %s %s --autoload-file=%s --config=%s %s --clear-cache', $cmdPath, $args->getOption('dry-run') ? '--dry-run' : '', $args->getOption('verbose') ? '--debug' : '', + $args->getOption('no-diff') ? '--no-diffs' : '', escapeshellarg($autoload), escapeshellarg($config), escapeshellarg($path), diff --git a/src/Rector/Cake3/AppUsesStaticCallToUseStatementRector.php b/src/Rector/Cake3/AppUsesStaticCallToUseStatementRector.php index af1db4b8..1664a96c 100644 --- a/src/Rector/Cake3/AppUsesStaticCallToUseStatementRector.php +++ b/src/Rector/Cake3/AppUsesStaticCallToUseStatementRector.php @@ -14,7 +14,6 @@ use PhpParser\NodeVisitor; use PHPStan\Type\ObjectType; use Rector\Contract\PhpParser\Node\StmtsAwareInterface; -use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\PhpParser\Node\BetterNodeFinder; use Rector\PhpParser\Node\CustomNode\FileWithoutNamespace; use Rector\PhpParser\Node\Value\ValueResolver; @@ -127,8 +126,13 @@ function (Node $subNode) use ($node, $appUsesStaticCalls, &$currentStmt) { return null; } - /** @var \PhpParser\Node\Stmt $currentStmt */ - unset($node->stmts[$currentStmt->getAttribute(AttributeKey::STMT_KEY)]); + foreach ($node->stmts as $key => $stmt) { + if ($stmt === $currentStmt) { + unset($node->stmts[$key]); + + return null; + } + } return null; }, diff --git a/src/Rector/Cake5/StaticConnectionHelperRector.php b/src/Rector/Cake5/StaticConnectionHelperRector.php index 44728d4c..530a845e 100644 --- a/src/Rector/Cake5/StaticConnectionHelperRector.php +++ b/src/Rector/Cake5/StaticConnectionHelperRector.php @@ -51,10 +51,10 @@ public function refactor(Node $node): ?Node $parent = $node->getAttribute(AttributeKey::PARENT_NODE); if ($parent instanceof Expression) { $this->removeNode($parent); - - return null; } } + + return null; } // Ensure the node is a method call on the ConnectionHelper instance diff --git a/src/Rector/CakePHPSetList.php b/src/Rector/CakePHPSetList.php index 3b1f8695..bbc9bd3b 100644 --- a/src/Rector/CakePHPSetList.php +++ b/src/Rector/CakePHPSetList.php @@ -100,6 +100,11 @@ final class CakePHPSetList */ public const MIGRATIONS_45 = __DIR__ . '/../../config/rector/sets/migrations45.php'; + /** + * @var string + */ + public const MIGRATIONS_50 = __DIR__ . '/../../config/rector/sets/migrations50.php'; + /** * @var string */ diff --git a/tests/TestCase/Command/RectorCommandTest.php b/tests/TestCase/Command/RectorCommandTest.php index 3cbf9dd7..91f92979 100644 --- a/tests/TestCase/Command/RectorCommandTest.php +++ b/tests/TestCase/Command/RectorCommandTest.php @@ -67,6 +67,16 @@ public function testApplyAppDir() $this->assertOutputContains('begin diff'); } + public function testApplyNoDiff() + { + $this->setupTestApp(__FUNCTION__); + $this->exec('upgrade rector --rules cakephp40 --dry-run --no-diff ' . TEST_APP); + + $this->assertExitSuccess(); + $this->assertOutputNotContains('begin diff'); + $this->assertOutputContains('Rector completed successfully'); + } + /** * @return void */