From 7978e9836e0ee230c389d7dc0afb9ccedbd4b774 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 10 Oct 2026 22:24:30 +0200 Subject: [PATCH 1/2] merge SkipSkipper into Skipper --- .../skip_after_defined_configured_rule.php | 7 +++---- src/Application/RectorRegistry.php | 3 +++ src/Rector/RectorRunner.php | 16 ++++++++-------- src/Reporting/UnusedSkipResolver.php | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/rules-tests/Renaming/Rector/Name/RenameClassRector/config/skip_after_defined_configured_rule.php b/rules-tests/Renaming/Rector/Name/RenameClassRector/config/skip_after_defined_configured_rule.php index 4ab81ef9905..9f54e63d47f 100644 --- a/rules-tests/Renaming/Rector/Name/RenameClassRector/config/skip_after_defined_configured_rule.php +++ b/rules-tests/Renaming/Rector/Name/RenameClassRector/config/skip_after_defined_configured_rule.php @@ -10,10 +10,9 @@ return static function (RectorConfig $rectorConfig): void { $rectorConfig->removeUnusedImports(); - $rectorConfig - ->ruleWithConfiguration(RenameClassRector::class, [ - OldClass::class => NewClass::class, - ]); + $rectorConfig->ruleWithConfiguration(RenameClassRector::class, [ + OldClass::class => NewClass::class, + ]); // skip the path after defined $rectorConfig->skip([ diff --git a/src/Application/RectorRegistry.php b/src/Application/RectorRegistry.php index 31dba5a7fc3..cccf5c46c70 100644 --- a/src/Application/RectorRegistry.php +++ b/src/Application/RectorRegistry.php @@ -41,6 +41,9 @@ public function forFile(File $file): array { $rectorsForPath = []; foreach ($this->rectors as $rector) { + var_dump($rector); + var_dump($file->getFilePath()); + if ($this->skipper->shouldSkipRectorAndFile($rector, $file->getFilePath())) { continue; } diff --git a/src/Rector/RectorRunner.php b/src/Rector/RectorRunner.php index b8b90593ede..fd63dbdcb6a 100644 --- a/src/Rector/RectorRunner.php +++ b/src/Rector/RectorRunner.php @@ -71,14 +71,14 @@ public function run(RectorInterface $rector, Node $node): int|Node|null|array // class/path skip is configured for this rule and file: run the rule on a deep clone to learn // whether it would actually have changed anything. Only a skip that prevents a real change // counts as used; the original node is left untouched, so the file stays skipped either way. - $skipMatch = $this->skipper->matchSkip($rector, $filePath); - if ($skipMatch instanceof SkipMatch) { - if ($rector->refactor($this->cloneNode($node)) !== null) { - $this->skipper->markSkipUsed($skipMatch); - } - - return null; - } + // $skipMatch = $this->skipper->matchSkip($rector, $filePath); + // if ($skipMatch instanceof SkipMatch) { + // if ($rector->refactor($this->cloneNode($node)) !== null) { + // $this->skipper->markSkipUsed($skipMatch); + // } + // + // return null; + // } // ensure origNode pulled before refactor to avoid changed during refactor, ref https://3v4l.org/YMEGN $originalNode = $node->getAttribute(AttributeKey::ORIGINAL_NODE) ?? $node; diff --git a/src/Reporting/UnusedSkipResolver.php b/src/Reporting/UnusedSkipResolver.php index 81fe5515b25..dac0212045b 100644 --- a/src/Reporting/UnusedSkipResolver.php +++ b/src/Reporting/UnusedSkipResolver.php @@ -7,8 +7,8 @@ use Rector\Configuration\Option; use Rector\Configuration\Parameter\SimpleParameterProvider; use Rector\FileSystem\FilePathHelper; -use Rector\Skipper\Skipper\Skipper; use Rector\Skipper\SkipCriteriaResolver\SkippedPathsResolver; +use Rector\Skipper\Skipper\Skipper; use Rector\ValueObject\ProcessResult; /** From c434ac68dbad4d4f010fae1e32cb6acc9e236540 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 10 Oct 2026 22:54:32 +0200 Subject: [PATCH 2/2] make sue of rector runner --- src/Application/FileProcessor.php | 4 ++++ src/Application/RectorRegistry.php | 9 -------- .../NodeTraverser/RectorNodeTraverser.php | 1 - .../Application/PostFileProcessor.php | 4 ---- src/Rector/RectorRunner.php | 22 +++++++------------ tests/Application/RectorRegistryTest.php | 5 ----- 6 files changed, 12 insertions(+), 33 deletions(-) diff --git a/src/Application/FileProcessor.php b/src/Application/FileProcessor.php index 1fc05375392..48e6a470341 100644 --- a/src/Application/FileProcessor.php +++ b/src/Application/FileProcessor.php @@ -44,6 +44,7 @@ public function __construct( private RectorParser $rectorParser, private NodeScopeAndMetadataDecorator $nodeScopeAndMetadataDecorator, private UsedImportsResolver $usedImportsResolver, + private RectorRegistry $rectorRegistry, ) { } @@ -59,6 +60,9 @@ public function processFile(File $file, Configuration $configuration): FileProce $fileHasChanged = false; $filePath = $file->getFilePath(); + $currentRectors = $this->rectorRegistry->forFile($file); + $this->rectorNodeTraverser->refreshPhpRectors($currentRectors); + do { $file->changeHasChanged(false); diff --git a/src/Application/RectorRegistry.php b/src/Application/RectorRegistry.php index cccf5c46c70..33051dee352 100644 --- a/src/Application/RectorRegistry.php +++ b/src/Application/RectorRegistry.php @@ -6,7 +6,6 @@ use Rector\Contract\Rector\HTMLAverseRectorInterface; use Rector\Contract\Rector\RectorInterface; -use Rector\Skipper\Skipper\Skipper; use Rector\ValueObject\Application\File; /** @@ -19,7 +18,6 @@ final class RectorRegistry */ public function __construct( private array $rectors, - private readonly Skipper $skipper ) { } @@ -41,13 +39,6 @@ public function forFile(File $file): array { $rectorsForPath = []; foreach ($this->rectors as $rector) { - var_dump($rector); - var_dump($file->getFilePath()); - - if ($this->skipper->shouldSkipRectorAndFile($rector, $file->getFilePath())) { - continue; - } - if ($rector instanceof HTMLAverseRectorInterface && $file->containsHTML()) { continue; } diff --git a/src/PhpParser/NodeTraverser/RectorNodeTraverser.php b/src/PhpParser/NodeTraverser/RectorNodeTraverser.php index a076c16c92c..b26aa8a54b7 100644 --- a/src/PhpParser/NodeTraverser/RectorNodeTraverser.php +++ b/src/PhpParser/NodeTraverser/RectorNodeTraverser.php @@ -62,7 +62,6 @@ public function traverse(array $nodes): array /** * @param RectorInterface[] $rectors - * @api used in tests to update the active rules * * @internal Used only in Rector core, not supported outside. Might change any time. */ diff --git a/src/PostRector/Application/PostFileProcessor.php b/src/PostRector/Application/PostFileProcessor.php index 7d1c8a0e338..2fe43fb7b89 100644 --- a/src/PostRector/Application/PostFileProcessor.php +++ b/src/PostRector/Application/PostFileProcessor.php @@ -71,10 +71,6 @@ public function traverse(array $stmts, File $file): array */ private function shouldSkipPostRector(PostRectorInterface $postRector, string $filePath, array $stmts): bool { - if ($this->skipper->shouldSkipRectorAndFile($postRector, $filePath)) { - return true; - } - // skip renaming if rename class rector is skipped if ($postRector instanceof ClassRenamingPostRector && $this->skipper->shouldSkipRectorAndFile( $this->renameClassRector, diff --git a/src/Rector/RectorRunner.php b/src/Rector/RectorRunner.php index fd63dbdcb6a..e0690dc744d 100644 --- a/src/Rector/RectorRunner.php +++ b/src/Rector/RectorRunner.php @@ -13,7 +13,6 @@ use Rector\Application\ChangedNodeScopeRefresher; use Rector\Application\Provider\CurrentFileProvider; use Rector\ChangesReporting\ValueObject\RectorWithLineChange; -use Rector\Contract\Rector\HTMLAverseRectorInterface; use Rector\Contract\Rector\RectorInterface; use Rector\Exception\ShouldNotHappenException; use Rector\NodeDecorator\CreatedByRuleDecorator; @@ -56,11 +55,6 @@ public function __construct( public function run(RectorInterface $rector, Node $node): int|Node|null|array { $file = $this->getFile(); - - if ($rector instanceof HTMLAverseRectorInterface && $file->containsHTML()) { - return null; - } - $filePath = $file->getFilePath(); // node already changed by this rule in a previous pass → hard skip @@ -71,14 +65,14 @@ public function run(RectorInterface $rector, Node $node): int|Node|null|array // class/path skip is configured for this rule and file: run the rule on a deep clone to learn // whether it would actually have changed anything. Only a skip that prevents a real change // counts as used; the original node is left untouched, so the file stays skipped either way. - // $skipMatch = $this->skipper->matchSkip($rector, $filePath); - // if ($skipMatch instanceof SkipMatch) { - // if ($rector->refactor($this->cloneNode($node)) !== null) { - // $this->skipper->markSkipUsed($skipMatch); - // } - // - // return null; - // } + $skipMatch = $this->skipper->matchSkip($rector, $filePath); + if ($skipMatch instanceof SkipMatch) { + if ($rector->refactor($this->cloneNode($node)) !== null) { + $this->skipper->markSkipUsed($skipMatch); + } + + return null; + } // ensure origNode pulled before refactor to avoid changed during refactor, ref https://3v4l.org/YMEGN $originalNode = $node->getAttribute(AttributeKey::ORIGINAL_NODE) ?? $node; diff --git a/tests/Application/RectorRegistryTest.php b/tests/Application/RectorRegistryTest.php index 4c97439ecbf..ab8c4e9c281 100644 --- a/tests/Application/RectorRegistryTest.php +++ b/tests/Application/RectorRegistryTest.php @@ -34,11 +34,6 @@ protected function tearDown(): void public function testForFile(): void { - $file = new File(__DIR__ . '/skipped_directory/some_file.php', ''); - $rectorsForPath = $this->rectorRegistry->forFile($file); - - $this->assertSame([], $rectorsForPath); - $file = new File(__DIR__ . '/some_file.php', ''); $rectorsForPath = $this->rectorRegistry->forFile($file);