Skip to content

Commit 5f3f959

Browse files
committed
Prevent double normalization of FuncCall nodes
1 parent 38ea1ab commit 5f3f959

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
@@ -2383,9 +2383,10 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
23832383
$functionName = $node->name->name;
23842384
}
23852385

2386-
if ($functionName !== null && $this->reflectionProvider->hasFunction($functionName, $this)) {
2386+
$normalizedNode = ArgumentsNormalizer::reorderFuncArguments($parametersAcceptor, $node);
2387+
if ($normalizedNode !== null && $functionName !== null && $this->reflectionProvider->hasFunction($functionName, $this)) {
23872388
$functionReflection = $this->reflectionProvider->getFunction($functionName, $this);
2388-
$resolvedType = $this->getDynamicFunctionReturnType($parametersAcceptor, $node, $functionReflection);
2389+
$resolvedType = $this->getDynamicFunctionReturnType($normalizedNode, $functionReflection);
23892390
if ($resolvedType !== null) {
23902391
return $resolvedType;
23912392
}
@@ -2444,7 +2445,7 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
24442445

24452446
return $cloneType;
24462447
}
2447-
$resolvedType = $this->getDynamicFunctionReturnType($parametersAcceptor, $normalizedNode, $functionReflection);
2448+
$resolvedType = $this->getDynamicFunctionReturnType($normalizedNode, $functionReflection);
24482449
if ($resolvedType !== null) {
24492450
return $resolvedType;
24502451
}
@@ -2456,23 +2457,20 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
24562457
return new MixedType();
24572458
}
24582459

2459-
private function getDynamicFunctionReturnType(ParametersAcceptor $parametersAcceptor, FuncCall $node, FunctionReflection $functionReflection): ?Type
2460+
private function getDynamicFunctionReturnType(FuncCall $normalizedNode, FunctionReflection $functionReflection): ?Type
24602461
{
2461-
$normalizedNode = ArgumentsNormalizer::reorderFuncArguments($parametersAcceptor, $node);
2462-
if ($normalizedNode !== null) {
2463-
foreach ($this->dynamicReturnTypeExtensionRegistry->getDynamicFunctionReturnTypeExtensions() as $dynamicFunctionReturnTypeExtension) {
2464-
if (!$dynamicFunctionReturnTypeExtension->isFunctionSupported($functionReflection)) {
2465-
continue;
2466-
}
2462+
foreach ($this->dynamicReturnTypeExtensionRegistry->getDynamicFunctionReturnTypeExtensions() as $dynamicFunctionReturnTypeExtension) {
2463+
if (!$dynamicFunctionReturnTypeExtension->isFunctionSupported($functionReflection)) {
2464+
continue;
2465+
}
24672466

2468-
$resolvedType = $dynamicFunctionReturnTypeExtension->getTypeFromFunctionCall(
2469-
$functionReflection,
2470-
$node,
2471-
$this,
2472-
);
2473-
if ($resolvedType !== null) {
2474-
return $resolvedType;
2475-
}
2467+
$resolvedType = $dynamicFunctionReturnTypeExtension->getTypeFromFunctionCall(
2468+
$functionReflection,
2469+
$normalizedNode,
2470+
$this,
2471+
);
2472+
if ($resolvedType !== null) {
2473+
return $resolvedType;
24762474
}
24772475
}
24782476

0 commit comments

Comments
 (0)