Skip to content

Commit

Permalink
Resolve StaticType coming from dynamic return type extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 8, 2021
1 parent ec4e7ed commit 76b65b4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -4637,9 +4637,8 @@ private function methodCallReturnType(Type $calledOnType, Type $typeWithMethod,

$methodReflection = $typeWithMethod->getMethod($methodName, $this);

$resolvedTypes = [];
if ($typeWithMethod instanceof TypeWithClassName) {
$resolvedTypes = [];

if ($methodCall instanceof MethodCall) {
foreach ($this->dynamicReturnTypeExtensionRegistry->getDynamicMethodReturnTypeExtensionsForClass($typeWithMethod->getClassName()) as $dynamicMethodReturnTypeExtension) {
if (!$dynamicMethodReturnTypeExtension->isMethodSupported($methodReflection)) {
Expand All @@ -4657,16 +4656,17 @@ private function methodCallReturnType(Type $calledOnType, Type $typeWithMethod,
$resolvedTypes[] = $dynamicStaticMethodReturnTypeExtension->getTypeFromStaticMethodCall($methodReflection, $methodCall, $this);
}
}
if (count($resolvedTypes) > 0) {
return TypeCombinator::union(...$resolvedTypes);
}
}

$methodReturnType = ParametersAcceptorSelector::selectFromArgs(
$this,
$methodCall->args,
$methodReflection->getVariants()
)->getReturnType();
if (count($resolvedTypes) > 0) {
$methodReturnType = TypeCombinator::union(...$resolvedTypes);
} else {
$methodReturnType = ParametersAcceptorSelector::selectFromArgs(
$this,
$methodCall->args,
$methodReflection->getVariants()
)->getReturnType();
}

if ($methodCall instanceof MethodCall) {
$calledOnThis = $calledOnType instanceof StaticType && $this->isInClass();
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3235,7 +3235,7 @@ public function dataBinaryOperations(): array
'$simpleXMLWrongXpath',
],
[
'array<static(SimpleXMLElement)>|false',
'array<SimpleXMLElement>|false',
'$simpleXMLUnknownXpath',
],
];
Expand Down

0 comments on commit 76b65b4

Please sign in to comment.