Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
12 changes: 8 additions & 4 deletions src/Rector/RectorRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions src/Testing/PHPUnit/AbstractRectorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading