From dcfcbb3dfd2a6b4926ab49bfc54757ddeb23c6a2 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 19 Dec 2025 10:33:28 +0100 Subject: [PATCH] Prevent double normalization of FuncCall nodes --- src/Analyser/MutatingScope.php | 35 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index 646e1b2fc7..5f491f4a8b 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -71,7 +71,6 @@ use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\Native\NativeParameterReflection; use PHPStan\Reflection\ParameterReflection; -use PHPStan\Reflection\ParametersAcceptor; use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Reflection\PassedByReference; use PHPStan\Reflection\Php\DummyParameter; @@ -2410,9 +2409,10 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu $functionName = $node->name->name; } - if ($functionName !== null && $this->reflectionProvider->hasFunction($functionName, $this)) { + $normalizedNode = ArgumentsNormalizer::reorderFuncArguments($parametersAcceptor, $node); + if ($normalizedNode !== null && $functionName !== null && $this->reflectionProvider->hasFunction($functionName, $this)) { $functionReflection = $this->reflectionProvider->getFunction($functionName, $this); - $resolvedType = $this->getDynamicFunctionReturnType($parametersAcceptor, $node, $functionReflection); + $resolvedType = $this->getDynamicFunctionReturnType($normalizedNode, $functionReflection); if ($resolvedType !== null) { return $resolvedType; } @@ -2471,7 +2471,7 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu return $cloneType; } - $resolvedType = $this->getDynamicFunctionReturnType($parametersAcceptor, $normalizedNode, $functionReflection); + $resolvedType = $this->getDynamicFunctionReturnType($normalizedNode, $functionReflection); if ($resolvedType !== null) { return $resolvedType; } @@ -2483,23 +2483,20 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu return new MixedType(); } - private function getDynamicFunctionReturnType(ParametersAcceptor $parametersAcceptor, FuncCall $node, FunctionReflection $functionReflection): ?Type + private function getDynamicFunctionReturnType(FuncCall $normalizedNode, FunctionReflection $functionReflection): ?Type { - $normalizedNode = ArgumentsNormalizer::reorderFuncArguments($parametersAcceptor, $node); - if ($normalizedNode !== null) { - foreach ($this->dynamicReturnTypeExtensionRegistry->getDynamicFunctionReturnTypeExtensions() as $dynamicFunctionReturnTypeExtension) { - if (!$dynamicFunctionReturnTypeExtension->isFunctionSupported($functionReflection)) { - continue; - } + foreach ($this->dynamicReturnTypeExtensionRegistry->getDynamicFunctionReturnTypeExtensions() as $dynamicFunctionReturnTypeExtension) { + if (!$dynamicFunctionReturnTypeExtension->isFunctionSupported($functionReflection)) { + continue; + } - $resolvedType = $dynamicFunctionReturnTypeExtension->getTypeFromFunctionCall( - $functionReflection, - $node, - $this, - ); - if ($resolvedType !== null) { - return $resolvedType; - } + $resolvedType = $dynamicFunctionReturnTypeExtension->getTypeFromFunctionCall( + $functionReflection, + $normalizedNode, + $this, + ); + if ($resolvedType !== null) { + return $resolvedType; } }