Skip to content
17 changes: 4 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```
Expand Down
9 changes: 9 additions & 0 deletions config/rector/migrations50.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);

use Cake\Upgrade\Rector\CakePHPSetList;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([CakePHPSetList::MIGRATIONS_50]);
};
57 changes: 57 additions & 0 deletions config/rector/sets/migrations50.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector;
use Rector\Renaming\ValueObject\RenameClassConstFetch;

/**
* @see https://github.com/cakephp/migrations/releases/5.0.0/
*/
return static function (RectorConfig $rectorConfig): void {

$constantMap = [
// Standard types
'PHINX_TYPE_STRING' => '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),
]);
}
};
7 changes: 6 additions & 1 deletion src/Command/RectorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
Expand Down
10 changes: 7 additions & 3 deletions src/Rector/Cake3/AppUsesStaticCallToUseStatementRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
},
Expand Down
4 changes: 2 additions & 2 deletions src/Rector/Cake5/StaticConnectionHelperRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/Rector/CakePHPSetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
10 changes: 10 additions & 0 deletions tests/TestCase/Command/RectorCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down