Skip to content
Closed
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
14 changes: 8 additions & 6 deletions src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,21 @@ final public function enterNode(Node $node): int|Node|null|array
// 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($this, $filePath);
$nodeToRefactor = $skipMatch instanceof SkipMatch ? $this->cloneNode($node) : $node;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite hard to read.


// ensure origNode pulled before refactor to avoid changed during refactor, ref https://3v4l.org/YMEGN
$originalNode = $node->getAttribute(AttributeKey::ORIGINAL_NODE) ?? $node;

$refactoredNodeOrState = $this->refactor($nodeToRefactor);

if ($skipMatch instanceof SkipMatch) {
if ($this->refactor($this->cloneNode($node)) !== null) {
if ($refactoredNodeOrState !== 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;

$refactoredNodeOrState = $this->refactor($node);

// nothing to change → continue
if ($refactoredNodeOrState === null) {
return null;
Expand Down
Loading