From 22a4b0861ac82b102006b91540cdf5563b133f58 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 26 Jul 2026 19:15:44 +0200 Subject: [PATCH 1/3] Prevent unnecessary getType() calls in BooleanOrHandler --- src/Analyser/ExprHandler/BooleanOrHandler.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Analyser/ExprHandler/BooleanOrHandler.php b/src/Analyser/ExprHandler/BooleanOrHandler.php index 77f7744702..da8d012c23 100644 --- a/src/Analyser/ExprHandler/BooleanOrHandler.php +++ b/src/Analyser/ExprHandler/BooleanOrHandler.php @@ -311,13 +311,16 @@ private function augmentBooleanOrTruthyWithConditionalHolders(TypeSpecifier $typ } $origType = $scope->getType($targetExpr); - $leftType = $leftTruthyScope->getType($targetExpr); - $rightType = $rightTruthyScope->getType($targetExpr); + $leftType = $leftTruthyScope->getType($targetExpr); $leftNarrowed = !$leftType->equals($origType) && $origType->isSuperTypeOf($leftType)->yes(); - $rightNarrowed = !$rightType->equals($origType) && $origType->isSuperTypeOf($rightType)->yes(); + if (!$leftNarrowed) { + continue; + } - if (!$leftNarrowed || !$rightNarrowed) { + $rightType = $rightTruthyScope->getType($targetExpr); + $rightNarrowed = !$rightType->equals($origType) && $origType->isSuperTypeOf($rightType)->yes(); + if (!$rightNarrowed) { continue; } From 0c6bac6bb5e58a4ab2afa4283b479839c5bff0f6 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 26 Jul 2026 19:24:35 +0200 Subject: [PATCH 2/3] lazier --- src/Analyser/ExprHandler/BooleanOrHandler.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Analyser/ExprHandler/BooleanOrHandler.php b/src/Analyser/ExprHandler/BooleanOrHandler.php index da8d012c23..de9eef1844 100644 --- a/src/Analyser/ExprHandler/BooleanOrHandler.php +++ b/src/Analyser/ExprHandler/BooleanOrHandler.php @@ -280,8 +280,8 @@ private function specifyTypesForFlattenedBooleanOr( */ private function augmentBooleanOrTruthyWithConditionalHolders(TypeSpecifier $typeSpecifier, MutatingScope $scope, MutatingScope $rightScope, BooleanOr|LogicalOr $expr, SpecifiedTypes $types): SpecifiedTypes { - $leftTruthyScope = $scope->filterByTruthyValue($expr->left); - $rightTruthyScope = $rightScope->filterByTruthyValue($expr->right); + $leftTruthyScope = null; + $rightTruthyScope = null; $seen = []; foreach ([$scope, $rightScope] as $sourceScope) { @@ -303,6 +303,9 @@ private function augmentBooleanOrTruthyWithConditionalHolders(TypeSpecifier $typ if (!$scope->hasExpressionType($targetExpr)->yes()) { continue; } + + $leftTruthyScope ??= $scope->filterByTruthyValue($expr->left); + $rightTruthyScope ??= $rightScope->filterByTruthyValue($expr->right); if (!$leftTruthyScope->hasExpressionType($targetExpr)->yes()) { continue; } From 690064515616ea266fd7cfc6a6fff9fc1aa40535 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 26 Jul 2026 19:25:11 +0200 Subject: [PATCH 3/3] Update BooleanOrHandler.php --- src/Analyser/ExprHandler/BooleanOrHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Analyser/ExprHandler/BooleanOrHandler.php b/src/Analyser/ExprHandler/BooleanOrHandler.php index de9eef1844..f9bb6e98fb 100644 --- a/src/Analyser/ExprHandler/BooleanOrHandler.php +++ b/src/Analyser/ExprHandler/BooleanOrHandler.php @@ -305,10 +305,10 @@ private function augmentBooleanOrTruthyWithConditionalHolders(TypeSpecifier $typ } $leftTruthyScope ??= $scope->filterByTruthyValue($expr->left); - $rightTruthyScope ??= $rightScope->filterByTruthyValue($expr->right); if (!$leftTruthyScope->hasExpressionType($targetExpr)->yes()) { continue; } + $rightTruthyScope ??= $rightScope->filterByTruthyValue($expr->right); if (!$rightTruthyScope->hasExpressionType($targetExpr)->yes()) { continue; }