From efcd52f30fe93e60589a0697e59f91f78dc5df93 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 10 Oct 2026 20:03:00 +0200 Subject: [PATCH 1/2] add standalone RectorRegistry to filter active rectors per file path --- src/Application/RectorRegistry.php | 50 +++++++++++++++++++ .../LazyContainerFactory.php | 2 + tests/Application/RectorRegistryTest.php | 48 ++++++++++++++++++ tests/Application/Source/SkippableRector.php | 27 ++++++++++ 4 files changed, 127 insertions(+) create mode 100644 src/Application/RectorRegistry.php create mode 100644 tests/Application/RectorRegistryTest.php create mode 100644 tests/Application/Source/SkippableRector.php diff --git a/src/Application/RectorRegistry.php b/src/Application/RectorRegistry.php new file mode 100644 index 00000000000..187d76726f6 --- /dev/null +++ b/src/Application/RectorRegistry.php @@ -0,0 +1,50 @@ +rectors = $rectors; + } + + /** + * @return RectorInterface[] + * + * @api used in tests + */ + public function forPath(string $filePath): array + { + $rectorsForPath = []; + foreach ($this->rectors as $rector) { + if ($this->skipper->shouldSkipRectorAndFile($rector, $filePath)) { + continue; + } + + $rectorsForPath[] = $rector; + } + + return $rectorsForPath; + } +} diff --git a/src/DependencyInjection/LazyContainerFactory.php b/src/DependencyInjection/LazyContainerFactory.php index c31bb18f62d..1a06549745f 100644 --- a/src/DependencyInjection/LazyContainerFactory.php +++ b/src/DependencyInjection/LazyContainerFactory.php @@ -16,6 +16,7 @@ use PHPStan\Reflection\ReflectionProvider; use Rector\Application\FileProcessor; use Rector\Application\Provider\CurrentFileProvider; +use Rector\Application\RectorRegistry; use Rector\BetterPhpDocParser\Comment\CommentsMerger; use Rector\BetterPhpDocParser\Contract\BasePhpDocNodeVisitorInterface; use Rector\BetterPhpDocParser\PhpDocNodeVisitor\ArrayTypePhpDocNodeVisitor; @@ -168,6 +169,7 @@ private function registerFileProcessing(RectorConfig $rectorConfig): void { $rectorConfig->singleton(FileProcessor::class); $rectorConfig->singleton(PostFileProcessor::class); + $rectorConfig->singleton(RectorRegistry::class); // shared state: collects used skips across the skipper, the path skipper and the file processor $rectorConfig->singleton(UsedSkipCollector::class); diff --git a/tests/Application/RectorRegistryTest.php b/tests/Application/RectorRegistryTest.php new file mode 100644 index 00000000000..f20fbd0acff --- /dev/null +++ b/tests/Application/RectorRegistryTest.php @@ -0,0 +1,48 @@ + ['*/skipped_directory/*'], + ]); + + $this->rectorRegistry = $this->make(RectorRegistry::class); + $this->rectorRegistry->refreshRectors([new SkippableRector()]); + } + + protected function tearDown(): void + { + SimpleParameterProvider::setParameter(Option::SKIP, []); + } + + public function testForPathSkipsRectorForSkippedPath(): void + { + $rectorsForPath = $this->rectorRegistry->forPath(__DIR__ . '/skipped_directory/some_file.php'); + + $this->assertSame([], $rectorsForPath); + } + + public function testForPathKeepsRectorForOtherPath(): void + { + $rectorsForPath = $this->rectorRegistry->forPath(__DIR__ . '/some_file.php'); + + $this->assertCount(1, $rectorsForPath); + $this->assertInstanceOf(SkippableRector::class, $rectorsForPath[0]); + } +} diff --git a/tests/Application/Source/SkippableRector.php b/tests/Application/Source/SkippableRector.php new file mode 100644 index 00000000000..d7a63644f10 --- /dev/null +++ b/tests/Application/Source/SkippableRector.php @@ -0,0 +1,27 @@ + Date: Sat, 10 Oct 2026 18:04:18 +0000 Subject: [PATCH 2/2] [ci-review] Rector Rectify --- src/Application/RectorRegistry.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Application/RectorRegistry.php b/src/Application/RectorRegistry.php index 187d76726f6..4e2679f3b57 100644 --- a/src/Application/RectorRegistry.php +++ b/src/Application/RectorRegistry.php @@ -7,6 +7,9 @@ use Rector\Contract\Rector\RectorInterface; use Rector\Skipper\Skipper\Skipper; +/** + * @see \Rector\Tests\Application\RectorRegistryTest + */ final class RectorRegistry { /**