ExpressionTypeHolder: re-use objects more often by staabm · Pull Request #4801 · phpstan/phpstan-src

Expand Up @@ -34,23 +34,26 @@ public function equals(self $other): bool return false; }
return $this->type->equals($other->type); return $this->type === $other->type || $this->type->equals($other->type); }
public function and(self $other): self { if ($this->type === $other->type || $this->type->equals($other->type)) { if ($this->certainty->equals($other->certainty)) { if ($this->certainty->and($other->certainty)->yes()) { return $this; }
$type = $this->type; } else { $type = TypeCombinator::union($this->type, $other->type); if ($this->certainty->maybe()) { return $this; }
return $other; }
return new self( $this->expr, $type, TypeCombinator::union($this->type, $other->type), $this->certainty->and($other->certainty), ); } Expand Down