Skip to content

Commit 8d60f3c

Browse files
authored
Merge branch '5.x' into 5.x-routebuilder-named-args
2 parents 5e1d738 + 63199da commit 8d60f3c

File tree

9 files changed

+96
-9
lines changed

9 files changed

+96
-9
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
prefer-lowest: 'prefer-lowest'
2525

2626
steps:
27-
- uses: actions/checkout@v5
27+
- uses: actions/checkout@v6
2828

2929
- name: Setup PHP
3030
uses: shivammathur/setup-php@v2
@@ -78,7 +78,7 @@ jobs:
7878
runs-on: ubuntu-22.04
7979

8080
steps:
81-
- uses: actions/checkout@v5
81+
- uses: actions/checkout@v6
8282

8383
- name: Setup PHP
8484
uses: shivammathur/setup-php@v2

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ The upgrade tool also includes rulesets for related tools and libraries:
103103

104104
- **chronos3** - Upgrade to Chronos 3.x
105105
- **migrations45** - Upgrade to Migrations 4.5
106+
- **migrations50** - Upgrade to Migrations 5.0
106107
- **phpunit80** - Upgrade to PHPUnit 8.0
107108

108109
```bash
@@ -114,6 +115,9 @@ bin/cake upgrade rector --rules chronos3 /path/to/your/app/src
114115
# Apply Migrations 4.5 upgrade rules
115116
bin/cake upgrade rector --rules migrations45 /path/to/your/app/config
116117

118+
# Apply Migrations 5.0 upgrade rules
119+
bin/cake upgrade rector --rules migrations50 /path/to/your/app/config
120+
117121
# Apply PHPUnit 8.0 upgrade rules
118122
bin/cake upgrade rector --rules phpunit80 /path/to/your/app/tests
119123
```

config/rector/migrations50.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use Cake\Upgrade\Rector\Set\CakePHPSetList;
5+
use Rector\Config\RectorConfig;
6+
7+
return static function (RectorConfig $rectorConfig): void {
8+
$rectorConfig->sets([CakePHPSetList::MIGRATIONS_50]);
9+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
use Rector\Config\RectorConfig;
5+
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector;
6+
use Rector\Renaming\ValueObject\RenameClassConstFetch;
7+
8+
/**
9+
* @see https://github.com/cakephp/migrations/releases/5.0.0/
10+
*/
11+
return static function (RectorConfig $rectorConfig): void {
12+
$rectorConfig->ruleWithConfiguration(RenameClassConstFetchRector::class, [
13+
// Standard types
14+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_STRING', 'TYPE_STRING'),
15+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_CHAR', 'TYPE_CHAR'),
16+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_TEXT', 'TYPE_TEXT'),
17+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_INTEGER', 'TYPE_INTEGER'),
18+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_TINY_INTEGER', 'TYPE_TINYINTEGER'),
19+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_SMALL_INTEGER', 'TYPE_SMALLINTEGER'),
20+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_BIG_INTEGER', 'TYPE_BIGINTEGER'),
21+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_FLOAT', 'TYPE_FLOAT'),
22+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_DECIMAL', 'TYPE_DECIMAL'),
23+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_DATETIME', 'TYPE_DATETIME'),
24+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_TIMESTAMP', 'TYPE_TIMESTAMP'),
25+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_TIME', 'TYPE_TIME'),
26+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_DATE', 'TYPE_DATE'),
27+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_BINARY', 'TYPE_BINARY'),
28+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_BINARYUUID', 'TYPE_BINARY_UUID'),
29+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_BOOLEAN', 'TYPE_BOOLEAN'),
30+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_JSON', 'TYPE_JSON'),
31+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_UUID', 'TYPE_UUID'),
32+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_NATIVEUUID', 'TYPE_NATIVE_UUID'),
33+
34+
// Geospatial types
35+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_GEOMETRY', 'TYPE_GEOMETRY'),
36+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_POINT', 'TYPE_POINT'),
37+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_LINESTRING', 'TYPE_LINESTRING'),
38+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_POLYGON', 'TYPE_POLYGON'),
39+
40+
// Geospatial array constant
41+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPES_GEOSPATIAL', 'TYPES_GEOSPATIAL'),
42+
43+
// Database-specific types
44+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_YEAR', 'TYPE_YEAR'),
45+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_CIDR', 'TYPE_CIDR'),
46+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_INET', 'TYPE_INET'),
47+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_MACADDR', 'TYPE_MACADDR'),
48+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', 'PHINX_TYPE_INTERVAL', 'TYPE_INTERVAL'),
49+
]);
50+
};

src/Command/RectorCommand.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,11 @@ protected function runRector(ConsoleIo $io, Arguments $args, string $autoload):
8383

8484
$cmdPath = ROOT . '/vendor/bin/rector process';
8585
$command = sprintf(
86-
'%s %s %s --autoload-file=%s --config=%s %s --clear-cache',
86+
'%s %s %s %s --autoload-file=%s --config=%s %s --clear-cache',
8787
$cmdPath,
8888
$args->getOption('dry-run') ? '--dry-run' : '',
89-
$args->getOption('verbose') ? '-vvvv' : '',
89+
$args->getOption('verbose') ? '--debug' : '',
90+
$args->getOption('no-diff') ? '--no-diff' : '',
9091
escapeshellarg($autoload),
9192
escapeshellarg($config),
9293
escapeshellarg($path),
@@ -199,6 +200,10 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption
199200
->addOption('dry-run', [
200201
'help' => 'Enable to get a preview of what modifications will be applied.',
201202
'boolean' => true,
203+
])
204+
->addOption('no-diff', [
205+
'help' => 'Disable rector diff output which can cause issues with large files.',
206+
'boolean' => true,
202207
]);
203208

204209
return $parser;

src/Rector/Rector/MethodCall/StaticConnectionHelperRector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ public function refactor(Node $node): ?Node
5151
$parent = $node->getAttribute(AttributeKey::PARENT_NODE);
5252
if ($parent instanceof Expression) {
5353
$this->removeNode($parent);
54-
55-
return null;
5654
}
5755
}
56+
57+
return null;
5858
}
5959

6060
// Ensure the node is a method call on the ConnectionHelper instance

src/Rector/Rector/Namespace_/AppUsesStaticCallToUseStatementRector.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use PhpParser\NodeVisitor;
1616
use PHPStan\Type\ObjectType;
1717
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
18-
use Rector\NodeTypeResolver\Node\AttributeKey;
1918
use Rector\PhpParser\Node\BetterNodeFinder;
2019
use Rector\PhpParser\Node\CustomNode\FileWithoutNamespace;
2120
use Rector\PhpParser\Node\Value\ValueResolver;
@@ -128,8 +127,13 @@ function (Node $subNode) use ($node, $appUsesStaticCalls, &$currentStmt) {
128127
return null;
129128
}
130129

131-
/** @var \PhpParser\Node\Stmt $currentStmt */
132-
unset($node->stmts[$currentStmt->getAttribute(AttributeKey::STMT_KEY)]);
130+
foreach ($node->stmts as $key => $stmt) {
131+
if ($stmt === $currentStmt) {
132+
unset($node->stmts[$key]);
133+
134+
return null;
135+
}
136+
}
133137

134138
return null;
135139
},

src/Rector/Set/CakePHPSetList.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ final class CakePHPSetList
9595
*/
9696
public const MIGRATIONS_45 = __DIR__ . '/../../../config/rector/sets/migrations45.php';
9797

98+
/**
99+
* @var string
100+
*/
101+
public const MIGRATIONS_50 = __DIR__ . '/../../../config/rector/sets/migrations50.php';
102+
98103
/**
99104
* @var string
100105
*/

tests/TestCase/Command/RectorCommandTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ public function testApplyAppDir()
6868
$this->assertOutputContains('Rector applied successfully');
6969
}
7070

71+
public function testApplyNoDiff()
72+
{
73+
$this->setupTestApp(__FUNCTION__);
74+
$this->exec('upgrade rector --rules cakephp40 --dry-run --no-diff ' . TEST_APP);
75+
76+
$this->assertExitSuccess();
77+
$this->assertOutputNotContains('begin diff');
78+
$this->assertOutputContains('Rector applied successfully');
79+
}
80+
7181
/**
7282
* @return void
7383
*/

0 commit comments

Comments
 (0)