Skip to content

Commit ee7ad10

Browse files
authored
Merge pull request #368 from cakephp/6.x-merge
6.x merge
2 parents 32cf8a7 + 4343754 commit ee7ad10

File tree

9 files changed

+104
-19
lines changed

9 files changed

+104
-19
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ jobs:
2121

2222
steps:
2323
- uses: actions/checkout@v5
24+
- uses: actions/checkout@v6
2425

2526
- name: Setup PHP
2627
uses: shivammathur/setup-php@v2
2728
with:
2829
php-version: ${{ matrix.php-version }}
2930
extensions: mbstring, intl
30-
coverage: pcov
31+
coverage: none
3132

3233
- name: Cache composer dependencies
3334
id: composer-cache
@@ -53,24 +54,14 @@ jobs:
5354
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
5455

5556
- name: Run PHPUnit
56-
run: |
57-
if [[ "${{ matrix.php-version }}" == "8.1" && "${{ matrix.prefer-lowest }}" != "prefer-lowest" ]]; then
58-
export CODECOVERAGE=1
59-
vendor/bin/phpunit --display-incomplete --display-skipped --coverage-clover=coverage.xml
60-
else
61-
vendor/bin/phpunit
62-
fi
63-
64-
- name: Submit code coverage
65-
if: matrix.php-version == '8.1' && matrix.prefer-lowest != 'prefer-lowest'
66-
uses: codecov/codecov-action@v5
57+
run: vendor/bin/phpunit --display-incomplete --display-skipped
6758

6859
cs-stan:
6960
name: Coding Standard & Static Analysis
7061
runs-on: ubuntu-22.04
7162

7263
steps:
73-
- uses: actions/checkout@v5
64+
- uses: actions/checkout@v6
7465

7566
- name: Setup PHP
7667
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\CakePHPSetList;
5+
use Rector\Config\RectorConfig;
6+
7+
return static function (RectorConfig $rectorConfig): void {
8+
$rectorConfig->sets([CakePHPSetList::MIGRATIONS_50]);
9+
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
13+
$constantMap = [
14+
// Standard types
15+
'PHINX_TYPE_STRING' => 'TYPE_STRING',
16+
'PHINX_TYPE_CHAR' => 'TYPE_CHAR',
17+
'PHINX_TYPE_TEXT' => 'TYPE_TEXT',
18+
'PHINX_TYPE_INTEGER' => 'TYPE_INTEGER',
19+
'PHINX_TYPE_TINY_INTEGER' => 'TYPE_TINYINTEGER',
20+
'PHINX_TYPE_SMALL_INTEGER' => 'TYPE_SMALLINTEGER',
21+
'PHINX_TYPE_BIG_INTEGER' => 'TYPE_BIGINTEGER',
22+
'PHINX_TYPE_FLOAT' => 'TYPE_FLOAT',
23+
'PHINX_TYPE_DECIMAL' => 'TYPE_DECIMAL',
24+
'PHINX_TYPE_DATETIME' => 'TYPE_DATETIME',
25+
'PHINX_TYPE_TIMESTAMP' => 'TYPE_TIMESTAMP',
26+
'PHINX_TYPE_TIME' => 'TYPE_TIME',
27+
'PHINX_TYPE_DATE' => 'TYPE_DATE',
28+
'PHINX_TYPE_BINARY' => 'TYPE_BINARY',
29+
'PHINX_TYPE_BINARYUUID' => 'TYPE_BINARY_UUID',
30+
'PHINX_TYPE_BOOLEAN' => 'TYPE_BOOLEAN',
31+
'PHINX_TYPE_JSON' => 'TYPE_JSON',
32+
'PHINX_TYPE_UUID' => 'TYPE_UUID',
33+
'PHINX_TYPE_NATIVEUUID' => 'TYPE_NATIVE_UUID',
34+
35+
// Geospatial types
36+
'PHINX_TYPE_GEOMETRY' => 'TYPE_GEOMETRY',
37+
'PHINX_TYPE_POINT' => 'TYPE_POINT',
38+
'PHINX_TYPE_LINESTRING' => 'TYPE_LINESTRING',
39+
'PHINX_TYPE_POLYGON' => 'TYPE_POLYGON',
40+
41+
// Geospatial array constant
42+
'PHINX_TYPES_GEOSPATIAL' => 'TYPES_GEOSPATIAL',
43+
44+
// Database-specific types
45+
'PHINX_TYPE_YEAR' => 'TYPE_YEAR',
46+
'PHINX_TYPE_CIDR' => 'TYPE_CIDR',
47+
'PHINX_TYPE_INET' => 'TYPE_INET',
48+
'PHINX_TYPE_MACADDR' => 'TYPE_MACADDR',
49+
'PHINX_TYPE_INTERVAL', 'TYPE_INTERVAL',
50+
];
51+
52+
foreach ($constantMap as $oldConstant => $newConstant) {
53+
$rectorConfig->ruleWithConfiguration(RenameClassConstFetchRector::class, [
54+
new RenameClassConstFetch('Migrations\Db\Adapter\AdapterInterface', $oldConstant, $newConstant),
55+
]);
56+
}
57+
};

src/Command/RectorCommand.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption
257257
'help' => 'Enable to get a preview of what modifications will be applied.',
258258
'boolean' => true,
259259
'short' => 'd',
260+
])
261+
->addOption('no-diff', [
262+
'help' => 'Disable rector diff output which can cause issues with large files.',
263+
'boolean' => true,
260264
]);
261265

262266
return $parser;
@@ -274,10 +278,11 @@ protected function buildCommand(Arguments $args, string $autoload, string $confi
274278
$cmdPath = ROOT . '/vendor/bin/rector process';
275279

276280
return sprintf(
277-
'%s %s %s --autoload-file=%s --config=%s %s --clear-cache',
281+
'%s %s %s %s --autoload-file=%s --config=%s %s --clear-cache',
278282
$cmdPath,
279283
$args->getOption('dry-run') ? '--dry-run' : '',
280284
$args->getOption('verbose') ? '--debug' : '',
285+
$args->getOption('no-diff') ? '--no-diffs' : '',
281286
escapeshellarg($autoload),
282287
escapeshellarg($config),
283288
escapeshellarg($path),

src/Rector/Cake3/AppUsesStaticCallToUseStatementRector.php

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

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

133137
return null;
134138
},

src/Rector/Cake5/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/CakePHPSetList.php

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

103+
/**
104+
* @var string
105+
*/
106+
public const MIGRATIONS_50 = __DIR__ . '/../../config/rector/sets/migrations50.php';
107+
103108
/**
104109
* @var string
105110
*/

tests/TestCase/Command/RectorCommandTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ public function testApplyAppDir()
6767
$this->assertOutputContains('begin diff');
6868
}
6969

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

0 commit comments

Comments
 (0)