diff --git a/rules-tests/CodeQuality/Rector/NotEqual/CommonNotEqualRector/Fixture/multi_line_compare.php.inc b/rules-tests/CodeQuality/Rector/NotEqual/CommonNotEqualRector/Fixture/multi_line_compare.php.inc new file mode 100644 index 00000000000..6b086f19c9a --- /dev/null +++ b/rules-tests/CodeQuality/Rector/NotEqual/CommonNotEqualRector/Fixture/multi_line_compare.php.inc @@ -0,0 +1,29 @@ + $two; + } +} + +?> +----- + diff --git a/rules/CodeQuality/Rector/NotEqual/CommonNotEqualRector.php b/rules/CodeQuality/Rector/NotEqual/CommonNotEqualRector.php index 5caf971b692..f443f49b641 100644 --- a/rules/CodeQuality/Rector/NotEqual/CommonNotEqualRector.php +++ b/rules/CodeQuality/Rector/NotEqual/CommonNotEqualRector.php @@ -6,7 +6,6 @@ use PhpParser\Node; use PhpParser\Node\Expr\BinaryOp\NotEqual; -use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -59,29 +58,18 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?NotEqual { - if (! $this->doesNotEqualContainsShipCompareToken($node)) { - return null; - } - - // invoke override to default "!=" - $node->setAttribute(AttributeKey::ORIGINAL_NODE, null); - - return $node; - } - - private function doesNotEqualContainsShipCompareToken(NotEqual $notEqual): bool - { - $tokenStartPos = $notEqual->getStartTokenPos(); - $tokenEndPos = $notEqual->getEndTokenPos(); + $tokenStartPos = $node->getStartTokenPos(); + $tokenEndPos = $node->getEndTokenPos(); for ($i = $tokenStartPos; $i < $tokenEndPos; ++$i) { $token = $this->file->getOldTokens()[$i]; if ((string) $token === '<>') { - return true; + $token->text = '!='; + return $node; } } - return false; + return null; } }