Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this path we invoked getDynamicFunctionReturnType without beeing normalized beforehand.

if ($resolvedType !== null) {
return $resolvedType;
}
Expand Down Expand Up @@ -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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this path $node was already normalized in line 2449 and before this PR will get normalized again within getDynamicFunctionReturnType

if ($resolvedType !== null) {
return $resolvedType;
}
Expand All @@ -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;
}
}

Expand Down
Loading