From ca36485a2e8abbdb36873d55a59676080be306ed Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 7 May 2023 20:54:00 +0200 Subject: [PATCH] Defer type-resolving in SimplifyBoolIdenticalTrueRector (#3757) --- .../Identical/SimplifyBoolIdenticalTrueRector.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/rules/CodeQuality/Rector/Identical/SimplifyBoolIdenticalTrueRector.php b/rules/CodeQuality/Rector/Identical/SimplifyBoolIdenticalTrueRector.php index 2e39f02a422..8730f803613 100644 --- a/rules/CodeQuality/Rector/Identical/SimplifyBoolIdenticalTrueRector.php +++ b/rules/CodeQuality/Rector/Identical/SimplifyBoolIdenticalTrueRector.php @@ -64,17 +64,15 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - $leftType = $this->getType($node->left); - if ($leftType->isBoolean()->yes() && ! $this->valueResolver->isTrueOrFalse($node->left)) { + if (! $this->valueResolver->isTrueOrFalse($node->left) && $this->getType($node->left)->isBoolean()->yes()) { return $this->processBoolTypeToNotBool($node, $node->left, $node->right); } - $rightType = $this->getType($node->right); - if (! $rightType->isBoolean()->yes()) { + if ($this->valueResolver->isTrueOrFalse($node->right)) { return null; } - if ($this->valueResolver->isTrueOrFalse($node->right)) { + if (! $this->getType($node->right)->isBoolean()->yes()) { return null; } @@ -106,10 +104,8 @@ private function refactorIdentical(Expr $leftExpr, Expr $rightExpr): ?Expr return $leftExpr->expr; } - $leftExprType = $this->getType($leftExpr); - // keep as it is, readable enough - if ($leftExpr instanceof Variable && $leftExprType->isBoolean()->yes()) { + if ($leftExpr instanceof Variable && $this->getType($leftExpr)->isBoolean()->yes()) { return null; }