Skip to content

Commit f783b70

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

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

src/Analyser/MutatingScope.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,9 +2410,10 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
24102410
$functionName = $node->name->name;
24112411
}
24122412

2413-
if ($functionName !== null && $this->reflectionProvider->hasFunction($functionName, $this)) {
2413+
$normalizedNode = ArgumentsNormalizer::reorderFuncArguments($parametersAcceptor, $node);
2414+
if ($normalizedNode !== null && $functionName !== null && $this->reflectionProvider->hasFunction($functionName, $this)) {
24142415
$functionReflection = $this->reflectionProvider->getFunction($functionName, $this);
2415-
$resolvedType = $this->getDynamicFunctionReturnType($parametersAcceptor, $node, $functionReflection);
2416+
$resolvedType = $this->getDynamicFunctionReturnType($normalizedNode, $functionReflection);
24162417
if ($resolvedType !== null) {
24172418
return $resolvedType;
24182419
}
@@ -2471,7 +2472,7 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
24712472

24722473
return $cloneType;
24732474
}
2474-
$resolvedType = $this->getDynamicFunctionReturnType($parametersAcceptor, $normalizedNode, $functionReflection);
2475+
$resolvedType = $this->getDynamicFunctionReturnType($normalizedNode, $functionReflection);
24752476
if ($resolvedType !== null) {
24762477
return $resolvedType;
24772478
}
@@ -2483,23 +2484,20 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
24832484
return new MixedType();
24842485
}
24852486

2486-
private function getDynamicFunctionReturnType(ParametersAcceptor $parametersAcceptor, FuncCall $node, FunctionReflection $functionReflection): ?Type
2487+
private function getDynamicFunctionReturnType(FuncCall $normalizedNode, FunctionReflection $functionReflection): ?Type
24872488
{
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-
}
2489+
foreach ($this->dynamicReturnTypeExtensionRegistry->getDynamicFunctionReturnTypeExtensions() as $dynamicFunctionReturnTypeExtension) {
2490+
if (!$dynamicFunctionReturnTypeExtension->isFunctionSupported($functionReflection)) {
2491+
continue;
2492+
}
24942493

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

0 commit comments

Comments
 (0)