From 8d2627ddd9cf2e783b247726731b4902f53f3870 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 10 Oct 2026 10:41:57 +0200 Subject: [PATCH] [perf] Skip native type resolution in SimplifyBoolIdenticalTrueRector unless a true/false literal is present --- .../Identical/SimplifyBoolIdenticalTrueRector.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rules/CodeQuality/Rector/Identical/SimplifyBoolIdenticalTrueRector.php b/rules/CodeQuality/Rector/Identical/SimplifyBoolIdenticalTrueRector.php index 8df17c82beb..3349aa1aa92 100644 --- a/rules/CodeQuality/Rector/Identical/SimplifyBoolIdenticalTrueRector.php +++ b/rules/CodeQuality/Rector/Identical/SimplifyBoolIdenticalTrueRector.php @@ -71,11 +71,17 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - if ($this->isBooleanButNotTrueAndFalse($node->left)) { - return $this->processBoolTypeToNotBool($node, $node->left, $node->right); + // the rule only applies when one side is a true/false constant; + // check it first to avoid the expensive native type resolution below + if ($this->valueResolver->isTrueOrFalse($node->right)) { + if ($this->isBooleanButNotTrueAndFalse($node->left)) { + return $this->processBoolTypeToNotBool($node, $node->left, $node->right); + } + + return null; } - if ($this->isBooleanButNotTrueAndFalse($node->right)) { + if ($this->valueResolver->isTrueOrFalse($node->left) && $this->isBooleanButNotTrueAndFalse($node->right)) { return $this->processBoolTypeToNotBool($node, $node->right, $node->left); }