Skip to content

Commit

Permalink
remove just reprinted verify on RectifiedAnalyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jun 11, 2023
1 parent 4591daf commit 66ba1ba
Showing 1 changed file with 1 addition and 36 deletions.
37 changes: 1 addition & 36 deletions src/ProcessAnalyzer/RectifiedAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* This service verify if the Node:
*
* - already applied same Rector rule before current Rector rule on last previous Rector rule.
* - just re-printed but token start still >= 0
*/
final class RectifiedAnalyzer
{
Expand All @@ -21,21 +20,7 @@ final class RectifiedAnalyzer
*/
public function hasRectified(string $rectorClass, Node $node): bool
{
$originalNode = $node->getAttribute(AttributeKey::ORIGINAL_NODE);

if ($this->hasConsecutiveCreatedByRule($rectorClass, $node, $originalNode)) {
return true;
}

return $this->isJustReprintedOverlappedTokenStart($node, $originalNode);
}

/**
* @param class-string<RectorInterface> $rectorClass
*/
private function hasConsecutiveCreatedByRule(string $rectorClass, Node $node, ?Node $originalNode): bool
{
$createdByRuleNode = $originalNode ?? $node;
$createdByRuleNode = $node->getAttribute(AttributeKey::ORIGINAL_NODE) ?? $node;
/** @var class-string<RectorInterface>[] $createdByRule */
$createdByRule = $createdByRuleNode->getAttribute(AttributeKey::CREATED_BY_RULE) ?? [];

Expand All @@ -45,24 +30,4 @@ private function hasConsecutiveCreatedByRule(string $rectorClass, Node $node, ?N

return end($createdByRule) === $rectorClass;
}

private function isJustReprintedOverlappedTokenStart(Node $node, ?Node $originalNode): bool
{
if ($originalNode instanceof Node) {
return false;
}

if ($node->hasAttribute(AttributeKey::ORIGINAL_NODE)) {
return false;
}

/**
* Start token pos must be < 0 to continue, as the node and parent node just re-printed
*
* - Node's original node is null
* - Parent Node's original node is null
*/
$startTokenPos = $node->getStartTokenPos();
return $startTokenPos >= 0;
}
}

0 comments on commit 66ba1ba

Please sign in to comment.