Skip to content

Commit

Permalink
Defer type-resolving in SimplifyBoolIdenticalTrueRector (#3757)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed May 7, 2023
1 parent 3e5c7ba commit ca36485
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit ca36485

Please sign in to comment.