From ae2daa4dd29bcfebdc07f70a984d76328c8944d4 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 10 Oct 2026 19:19:06 +0200 Subject: [PATCH] Narrow Skipper::shouldSkipRectorAndFile() to accept Rector object only --- src/PostRector/Application/PostFileProcessor.php | 9 +++++---- src/Skipper/Skipper/Skipper.php | 4 ++-- tests/Skipper/Skipper/SkipperTest.php | 14 +++++++------- tests/Skipper/Skipper/UsedSkipCollectorTest.php | 6 +++--- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/PostRector/Application/PostFileProcessor.php b/src/PostRector/Application/PostFileProcessor.php index 63536e11e70..7d1c8a0e338 100644 --- a/src/PostRector/Application/PostFileProcessor.php +++ b/src/PostRector/Application/PostFileProcessor.php @@ -34,7 +34,8 @@ public function __construct( private readonly ClassRenamingPostRector $classRenamingPostRector, private readonly DocblockNameImportingPostRector $docblockNameImportingPostRector, private readonly UnusedImportRemovingPostRector $unusedImportRemovingPostRector, - private readonly RenamedClassesDataCollector $renamedClassesDataCollector + private readonly RenamedClassesDataCollector $renamedClassesDataCollector, + private readonly RenameClassRector $renameClassRector ) { } @@ -70,13 +71,13 @@ public function traverse(array $stmts, File $file): array */ private function shouldSkipPostRector(PostRectorInterface $postRector, string $filePath, array $stmts): bool { - if ($this->skipper->shouldSkipElementAndFilePath($postRector, $filePath)) { + if ($this->skipper->shouldSkipRectorAndFile($postRector, $filePath)) { return true; } // skip renaming if rename class rector is skipped - if ($postRector instanceof ClassRenamingPostRector && $this->skipper->shouldSkipElementAndFilePath( - RenameClassRector::class, + if ($postRector instanceof ClassRenamingPostRector && $this->skipper->shouldSkipRectorAndFile( + $this->renameClassRector, $filePath )) { return true; diff --git a/src/Skipper/Skipper/Skipper.php b/src/Skipper/Skipper/Skipper.php index 8cd52c5f4b4..9b144c793a3 100644 --- a/src/Skipper/Skipper/Skipper.php +++ b/src/Skipper/Skipper/Skipper.php @@ -32,9 +32,9 @@ public function shouldSkipFilePath(string $filePath): bool return $this->pathSkipper->shouldSkip($filePath); } - public function shouldSkipElementAndFilePath(string|object $element, string $filePath): bool + public function shouldSkipRectorAndFile(object $rector, string $filePath): bool { - $skipMatch = $this->matchSkip($element, $filePath); + $skipMatch = $this->matchSkip($rector, $filePath); if (! $skipMatch instanceof SkipMatch) { return false; } diff --git a/tests/Skipper/Skipper/SkipperTest.php b/tests/Skipper/Skipper/SkipperTest.php index 8fa8ae21b92..d64748f52bc 100644 --- a/tests/Skipper/Skipper/SkipperTest.php +++ b/tests/Skipper/Skipper/SkipperTest.php @@ -69,9 +69,9 @@ public static function provideDataShouldSkipFilePath(): Iterator } #[DataProvider('provideCheckerAndFile')] - public function testSkipElementAndFilePath(string $element, string $filePath, bool $expectedSkip): void + public function testSkipRectorAndFile(object $rector, string $filePath, bool $expectedSkip): void { - $resolvedSkip = $this->skipper->shouldSkipElementAndFilePath($element, $filePath); + $resolvedSkip = $this->skipper->shouldSkipRectorAndFile($rector, $filePath); $this->assertSame($expectedSkip, $resolvedSkip); } @@ -80,12 +80,12 @@ public function testSkipElementAndFilePath(string $element, string $filePath, bo */ public static function provideCheckerAndFile(): Iterator { - yield [FifthElement::class, __DIR__ . '/Fixture', true]; + yield [new FifthElement(), __DIR__ . '/Fixture', true]; - yield [AnotherClassToSkip::class, __DIR__ . '/Fixture/someFile', true]; - yield [AnotherClassToSkip::class, __DIR__ . '/Fixture/someDirectory/anotherFile.php', true]; + yield [new AnotherClassToSkip(), __DIR__ . '/Fixture/someFile', true]; + yield [new AnotherClassToSkip(), __DIR__ . '/Fixture/someDirectory/anotherFile.php', true]; - yield [NotSkippedClass::class, __DIR__ . '/Fixture/someFile', false]; - yield [NotSkippedClass::class, __DIR__ . '/Fixture/someOtherFile', false]; + yield [new NotSkippedClass(), __DIR__ . '/Fixture/someFile', false]; + yield [new NotSkippedClass(), __DIR__ . '/Fixture/someOtherFile', false]; } } diff --git a/tests/Skipper/Skipper/UsedSkipCollectorTest.php b/tests/Skipper/Skipper/UsedSkipCollectorTest.php index 9e12d70c48a..3b6c862db55 100644 --- a/tests/Skipper/Skipper/UsedSkipCollectorTest.php +++ b/tests/Skipper/Skipper/UsedSkipCollectorTest.php @@ -50,7 +50,7 @@ protected function tearDown(): void public function testCollectsOnlyMatchedSkips(): void { $this->skipper->shouldSkipFilePath('tests/Skipper/Skipper/Fixture/SomeSkippedPath/any.txt'); - $this->skipper->shouldSkipElementAndFilePath(FifthElement::class, __FILE__); + $this->skipper->shouldSkipRectorAndFile(new FifthElement(), __FILE__); $usedSkips = $this->usedSkipCollector->provide(); @@ -76,8 +76,8 @@ public function testCollectsMatchedPathNotRuleClassForRuleScopedSkip(): void ], ]); - $this->skipper->shouldSkipElementAndFilePath( - AnotherClassToSkip::class, + $this->skipper->shouldSkipRectorAndFile( + new AnotherClassToSkip(), __DIR__ . '/Fixture/someDirectory/anotherFile.php' );