From f57ad1d2a93977d393a93662528570d3677ce7c0 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 3 Feb 2026 15:25:56 +0100 Subject: [PATCH 1/2] Prevent repetitive calls to ParametersAcceptorSelector::selectFromArgs() --- ...ReplaceFunctionsDynamicReturnTypeExtension.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Type/Php/ReplaceFunctionsDynamicReturnTypeExtension.php b/src/Type/Php/ReplaceFunctionsDynamicReturnTypeExtension.php index 5df70cd0ed6..d4e4b587cc1 100644 --- a/src/Type/Php/ReplaceFunctionsDynamicReturnTypeExtension.php +++ b/src/Type/Php/ReplaceFunctionsDynamicReturnTypeExtension.php @@ -73,21 +73,22 @@ private function getPreliminarilyResolvedTypeFromFunctionCall( FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope, - ): Type + ): ?Type { $subjectArgumentType = $this->getSubjectType($functionReflection, $functionCall, $scope); $args = $functionCall->getArgs(); - $defaultReturnType = ParametersAcceptorSelector::selectFromArgs( - $scope, - $args, - $functionReflection->getVariants(), - )->getReturnType(); if ($subjectArgumentType === null) { - return $defaultReturnType; + return null; } if ($subjectArgumentType instanceof MixedType) { + $defaultReturnType = ParametersAcceptorSelector::selectFromArgs( + $scope, + $args, + $functionReflection->getVariants(), + )->getReturnType(); + return TypeUtils::toBenevolentUnion($defaultReturnType); } From 32808033807bb6890d8e85c3d82115e1954963d4 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 3 Feb 2026 16:05:32 +0100 Subject: [PATCH 2/2] Update ReplaceFunctionsDynamicReturnTypeExtension.php --- ...aceFunctionsDynamicReturnTypeExtension.php | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/Type/Php/ReplaceFunctionsDynamicReturnTypeExtension.php b/src/Type/Php/ReplaceFunctionsDynamicReturnTypeExtension.php index d4e4b587cc1..4b2b3a8f983 100644 --- a/src/Type/Php/ReplaceFunctionsDynamicReturnTypeExtension.php +++ b/src/Type/Php/ReplaceFunctionsDynamicReturnTypeExtension.php @@ -58,11 +58,11 @@ public function getTypeFromFunctionCall( FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope, - ): Type + ): ?Type { $type = $this->getPreliminarilyResolvedTypeFromFunctionCall($functionReflection, $functionCall, $scope); - if ($this->canReturnNull($functionReflection, $functionCall, $scope)) { + if ($type !== null && $this->canReturnNull($functionReflection, $functionCall, $scope)) { $type = TypeCombinator::addNull($type); } @@ -88,7 +88,7 @@ private function getPreliminarilyResolvedTypeFromFunctionCall( $args, $functionReflection->getVariants(), )->getReturnType(); - + return TypeUtils::toBenevolentUnion($defaultReturnType); } @@ -230,18 +230,11 @@ private function canReturnNull( ) { return false; } - } - - $possibleTypes = ParametersAcceptorSelector::selectFromArgs( - $scope, - $args, - $functionReflection->getVariants(), - )->getReturnType(); - // resolve conditional return types - $possibleTypes = TypeUtils::resolveLateResolvableTypes($possibleTypes); + return true; + } - return TypeCombinator::containsNull($possibleTypes); + return false; } }