Skip to content

Commit a53aa7e

Browse files
committed
[dx] immutable node visitor
1 parent d48ab7c commit a53aa7e

11 files changed

+616
-37
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@
133133
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-if-php.patch",
134134
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-case-php.patch",
135135
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-elseif-php.patch",
136-
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-namespace-php.patch",
137-
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-nodetraverser-php.patch"
136+
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-namespace-php.patch"
138137
]
139138
},
140139
"composer-exit-on-patch-failure": true,

phpstan.neon

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ parameters:
217217

218218
# optional as changes behavior, should be used explicitly outside PHP upgrade
219219
- '#Register "Rector\\Php73\\Rector\\FuncCall\\JsonThrowOnErrorRector" service to "php73\.php" config set#'
220-
- '#Register "Rector\\Php81\\Rector\\ClassMethod\\NewInInitializerRector" service to "php81\.php" config set#'
221220
- '#Register "Rector\\Php80\\Rector\\NotIdentical\\MbStrContainsRector" service to "php80\.php" config set#'
222221
- '#Register "Rector\\Php85\\Rector\\StmtsAwareInterface\\SequentialAssignmentsToPipeOperatorRector" service to "php85\.php" config set#'
223222
- '#Register "Rector\\Php85\\Rector\\Expression\\NestedFuncCallsToPipeOperatorRector" service to "php85\.php" config set#'
@@ -356,6 +355,27 @@ parameters:
356355

357356
- '#Method Rector\\Utils\\Rector\\RemoveRefactorDuplicatedNodeInstanceCheckRector\:\:getInstanceofNodeClass\(\) should return class\-string<PhpParser\\Node>\|null but returns class\-string#'
358357

358+
# helper classes for bin script
359359
-
360-
path: bin/list-unused-rules.php
360+
path: scripts
361361
identifier: symplify.multipleClassLikeInFile
362+
363+
# copied from /vendor, to keep as original as possible
364+
-
365+
identifier: symplify.forbiddenNode
366+
path: src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php
367+
-
368+
identifier: missingType.iterableValue
369+
path: src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php
370+
-
371+
identifier: symplify.noDynamicName
372+
path: src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php
373+
-
374+
identifier: offsetAccess.nonArray
375+
path: src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php
376+
-
377+
message: '#Property PhpParser\\Node\\Stmt\\ClassMethod\:\:\$stmts \(array<PhpParser\\Node\\Stmt>\|null\) does not accept array<PhpParser\\Node>#'
378+
path: scripts/create-immutable-node-visitor.php
379+
-
380+
message: '#Property Rector\\PhpParser\\NodeTraverser\\AbstractImmutableNodeTraverser\:\:\$visitors \(list<PhpParser\\NodeVisitor>\) does not accept array<int\|string, PhpParser\\NodeVisitor>#'
381+
path: src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php

rector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828
->withPhpSets()
2929
->withPaths([
3030
__DIR__ . '/bin',
31+
__DIR__ . '/config',
3132
__DIR__ . '/src',
3233
__DIR__ . '/rules',
3334
__DIR__ . '/rules-tests',
3435
__DIR__ . '/tests',
3536
__DIR__ . '/utils',
36-
__DIR__ . '/config',
37+
__DIR__ . '/scripts',
3738
__DIR__ . '/build/build-preload.php',
3839
])
3940
->withRootFiles()

scripts/avoid-short-node-names-in-fixtures.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@
99
use Symfony\Component\Console\Input\ArrayInput;
1010
use Symfony\Component\Console\Output\ConsoleOutput;
1111
use Symfony\Component\Console\Style\SymfonyStyle;
12+
use Symfony\Component\Finder\Finder;
13+
use Symfony\Component\Finder\SplFileInfo;
1214

1315
require __DIR__ . '/../vendor/autoload.php';
1416

1517
$fixtureFiles = FixtureFinder::find([__DIR__ . '/../tests', __DIR__ . '/../rules-tests']);
1618

1719
// get short node names
1820

19-
$nodeFileFinder = \Symfony\Component\Finder\Finder::create()
21+
$nodeFileFinder = Finder::create()
2022
->files()
2123
->name('*.php')
2224
->in(__DIR__ . '/../vendor/nikic/php-parser/lib/PhpParser/Node');
2325

24-
/** @var \Symfony\Component\Finder\SplFileInfo[] $nodeFileInfos */
26+
/** @var SplFileInfo[] $nodeFileInfos */
2527
$nodeFileInfos = iterator_to_array($nodeFileFinder->getIterator());
2628

2729
$shortNodeClassNames = [];
@@ -33,10 +35,10 @@
3335

3436
$hasErrors = false;
3537

36-
foreach ($fixtureFiles as $fixtureFileInfo) {
38+
foreach ($fixtureFiles as $fixtureFile) {
3739
$shortClassNameMatch = Strings::match(
38-
$fixtureFileInfo->getContents(),
39-
'/\b(?:class|interface)\s+(?<name>[A-Z][A-Za-z0-9_]*)/'
40+
$fixtureFile->getContents(),
41+
'/\b(?:class|interface)\s+(?<name>[A-Z]\w*)/'
4042
);
4143
if ($shortClassNameMatch === null) {
4244
continue;
@@ -52,7 +54,7 @@
5254
$fixtureClassName,
5355
PHP_EOL,
5456
PHP_EOL,
55-
$fixtureFileInfo->getRealPath(),
57+
$fixtureFile->getRealPath(),
5658
PHP_EOL
5759
));
5860

scripts/check-before-after-same-fixtures.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
declare(strict_types=1);
44

55
use Nette\Utils\Strings;
6+
use Rector\Scripts\Finder\FixtureFinder;
67

78
require __DIR__ . '/../vendor/autoload.php';
89

@@ -27,7 +28,7 @@ public function __construct()
2728
*/
2829
public function run(array $testDirectories): int
2930
{
30-
$fixtureFiles = \Rector\Scripts\Finder\FixtureFinder::find($testDirectories);
31+
$fixtureFiles = FixtureFinder::find($testDirectories);
3132

3233
$invalidFixturePaths = [];
3334
foreach ($fixtureFiles as $fixtureFile) {

scripts/copy-and-create-immuatable-node-visitor.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)