diff --git a/rules/CodeQuality/Rector/Identical/BooleanNotIdenticalToNotIdenticalRector.php b/rules/CodeQuality/Rector/Identical/BooleanNotIdenticalToNotIdenticalRector.php index f254210f11b..c974136d5cb 100644 --- a/rules/CodeQuality/Rector/Identical/BooleanNotIdenticalToNotIdenticalRector.php +++ b/rules/CodeQuality/Rector/Identical/BooleanNotIdenticalToNotIdenticalRector.php @@ -95,20 +95,19 @@ public function refactor(Node $node): ?Node private function processIdentical(Identical $identical): ?NotIdentical { - $leftType = $this->getType($identical->left); - if (! $leftType->isBoolean()->yes()) { + // cheap structural guard first, so getType() runs only on the "!$a === $b" shape + if (! $identical->left instanceof BooleanNot) { return null; } - $rightType = $this->getType($identical->right); - if (! $rightType->isBoolean()->yes()) { + if (! $this->getType($identical->left)->isBoolean()->yes()) { return null; } - if ($identical->left instanceof BooleanNot) { - return new NotIdentical($identical->left->expr, $identical->right); + if (! $this->getType($identical->right)->isBoolean()->yes()) { + return null; } - return null; + return new NotIdentical($identical->left->expr, $identical->right); } }