From 52da11c93c9030cdb739efc3e6e031eaadad2be0 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 9 Oct 2026 15:51:36 +0200 Subject: [PATCH] Skip skip-probe deep clone unless unused-skip reporting is on --- .../config/skip_used_tracking_configured_rule.php | 3 +++ src/Rector/RectorRunner.php | 12 ++++++++---- src/Testing/PHPUnit/AbstractRectorTestCase.php | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/rules-tests/Renaming/Rector/Name/RenameClassRector/config/skip_used_tracking_configured_rule.php b/rules-tests/Renaming/Rector/Name/RenameClassRector/config/skip_used_tracking_configured_rule.php index 487d0cde776..529448a3ea1 100644 --- a/rules-tests/Renaming/Rector/Name/RenameClassRector/config/skip_used_tracking_configured_rule.php +++ b/rules-tests/Renaming/Rector/Name/RenameClassRector/config/skip_used_tracking_configured_rule.php @@ -17,4 +17,7 @@ $rectorConfig->skip([ RenameClassRector::class => ['*skip_used_renames_old_class*', '*skip_unused_no_old_class*'], ]); + + // skip-use tracking only runs when unused-skip reporting is on + $rectorConfig->reportUnusedSkips(); }; diff --git a/src/Rector/RectorRunner.php b/src/Rector/RectorRunner.php index a4548a97216..6eed1bbab31 100644 --- a/src/Rector/RectorRunner.php +++ b/src/Rector/RectorRunner.php @@ -12,6 +12,8 @@ use Rector\Application\ChangedNodeScopeRefresher; use Rector\Application\Provider\CurrentFileProvider; use Rector\ChangesReporting\ValueObject\RectorWithLineChange; +use Rector\Configuration\Option; +use Rector\Configuration\Parameter\SimpleParameterProvider; use Rector\Contract\Rector\HTMLAverseRectorInterface; use Rector\Contract\Rector\RectorInterface; use Rector\Exception\ShouldNotHappenException; @@ -68,12 +70,14 @@ public function run(RectorInterface $rector, Node $node): int|Node|null|array return null; } - // 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. + // class/path skip is configured for this rule and file: only when unused-skip reporting is on, + // 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 clone keeps the original node untouched. + // With reporting off (the default), the clone is pure overhead, so it is skipped entirely. $skipMatch = $this->skipper->matchSkip($rector, $filePath); if ($skipMatch instanceof SkipMatch) { - if ($rector->refactor($this->cloneNode($node)) !== null) { + if (SimpleParameterProvider::provideBoolParameter(Option::REPORT_UNUSED_SKIPS, false) + && $rector->refactor($this->cloneNode($node)) !== null) { $this->skipper->markSkipUsed($skipMatch); } diff --git a/src/Testing/PHPUnit/AbstractRectorTestCase.php b/src/Testing/PHPUnit/AbstractRectorTestCase.php index 65917eb0415..82c6fdbf72e 100644 --- a/src/Testing/PHPUnit/AbstractRectorTestCase.php +++ b/src/Testing/PHPUnit/AbstractRectorTestCase.php @@ -60,6 +60,7 @@ public static function tearDownAfterClass(): void SimpleParameterProvider::setParameter(Option::NEW_LINE_ON_FLUENT_CALL, false); SimpleParameterProvider::setParameter(Option::TREAT_CLASSES_AS_FINAL, false); + SimpleParameterProvider::setParameter(Option::REPORT_UNUSED_SKIPS, false); // reset PHP version to the test default, so a version-bound test class // does not leak its phpVersion() into the next class in the same process