Skip to content

Commit

Permalink
[Core] Ensure define $originalNode before refactor() called to avoid …
Browse files Browse the repository at this point in the history
…changed during refactor (#4031)
  • Loading branch information
samsonasik committed May 30, 2023
1 parent b37e273 commit 46d2aac
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ final public function enterNode(Node $node)
$previousMemory = memory_get_peak_usage(true);
}

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

if ($isDebug) {
$this->printConsumptions($startTime, $previousMemory);
}
Expand All @@ -244,7 +247,6 @@ final public function enterNode(Node $node)
throw new ShouldNotHappenException($errorMessage);
}

$originalNode = $node->getAttribute(AttributeKey::ORIGINAL_NODE);
return $this->postRefactorProcess($originalNode, $node, $refactoredNode);
}

Expand Down

0 comments on commit 46d2aac

Please sign in to comment.