Skip to content

Commit dcfcbb3

Browse files
committed
Prevent double normalization of FuncCall nodes
1 parent 1da8b9e commit dcfcbb3

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

src/Analyser/MutatingScope.php

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
use PHPStan\Reflection\MethodReflection;
7272
use PHPStan\Reflection\Native\NativeParameterReflection;
7373
use PHPStan\Reflection\ParameterReflection;
74-
use PHPStan\Reflection\ParametersAcceptor;
7574
use PHPStan\Reflection\ParametersAcceptorSelector;
7675
use PHPStan\Reflection\PassedByReference;
7776
use PHPStan\Reflection\Php\DummyParameter;
@@ -2410,9 +2409,10 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
24102409
$functionName = $node->name->name;
24112410
}
24122411

2413-
if ($functionName !== null && $this->reflectionProvider->hasFunction($functionName, $this)) {
2412+
$normalizedNode = ArgumentsNormalizer::reorderFuncArguments($parametersAcceptor, $node);
2413+
if ($normalizedNode !== null && $functionName !== null && $this->reflectionProvider->hasFunction($functionName, $this)) {
24142414
$functionReflection = $this->reflectionProvider->getFunction($functionName, $this);
2415-
$resolvedType = $this->getDynamicFunctionReturnType($parametersAcceptor, $node, $functionReflection);
2415+
$resolvedType = $this->getDynamicFunctionReturnType($normalizedNode, $functionReflection);
24162416
if ($resolvedType !== null) {
24172417
return $resolvedType;
24182418
}
@@ -2471,7 +2471,7 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
24712471

24722472
return $cloneType;
24732473
}
2474-
$resolvedType = $this->getDynamicFunctionReturnType($parametersAcceptor, $normalizedNode, $functionReflection);
2474+
$resolvedType = $this->getDynamicFunctionReturnType($normalizedNode, $functionReflection);
24752475
if ($resolvedType !== null) {
24762476
return $resolvedType;
24772477
}
@@ -2483,23 +2483,20 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
24832483
return new MixedType();
24842484
}
24852485

2486-
private function getDynamicFunctionReturnType(ParametersAcceptor $parametersAcceptor, FuncCall $node, FunctionReflection $functionReflection): ?Type
2486+
private function getDynamicFunctionReturnType(FuncCall $normalizedNode, FunctionReflection $functionReflection): ?Type
24872487
{
2488-
$normalizedNode = ArgumentsNormalizer::reorderFuncArguments($parametersAcceptor, $node);
2489-
if ($normalizedNode !== null) {
2490-
foreach ($this->dynamicReturnTypeExtensionRegistry->getDynamicFunctionReturnTypeExtensions() as $dynamicFunctionReturnTypeExtension) {
2491-
if (!$dynamicFunctionReturnTypeExtension->isFunctionSupported($functionReflection)) {
2492-
continue;
2493-
}
2488+
foreach ($this->dynamicReturnTypeExtensionRegistry->getDynamicFunctionReturnTypeExtensions() as $dynamicFunctionReturnTypeExtension) {
2489+
if (!$dynamicFunctionReturnTypeExtension->isFunctionSupported($functionReflection)) {
2490+
continue;
2491+
}
24942492

2495-
$resolvedType = $dynamicFunctionReturnTypeExtension->getTypeFromFunctionCall(
2496-
$functionReflection,
2497-
$node,
2498-
$this,
2499-
);
2500-
if ($resolvedType !== null) {
2501-
return $resolvedType;
2502-
}
2493+
$resolvedType = $dynamicFunctionReturnTypeExtension->getTypeFromFunctionCall(
2494+
$functionReflection,
2495+
$normalizedNode,
2496+
$this,
2497+
);
2498+
if ($resolvedType !== null) {
2499+
return $resolvedType;
25032500
}
25042501
}
25052502

0 commit comments

Comments
 (0)