Skip to content

Commit 76b65b4

Browse files
committed
Resolve StaticType coming from dynamic return type extensions
1 parent ec4e7ed commit 76b65b4

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/Analyser/MutatingScope.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -4637,9 +4637,8 @@ private function methodCallReturnType(Type $calledOnType, Type $typeWithMethod,
46374637

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

4640+
$resolvedTypes = [];
46404641
if ($typeWithMethod instanceof TypeWithClassName) {
4641-
$resolvedTypes = [];
4642-
46434642
if ($methodCall instanceof MethodCall) {
46444643
foreach ($this->dynamicReturnTypeExtensionRegistry->getDynamicMethodReturnTypeExtensionsForClass($typeWithMethod->getClassName()) as $dynamicMethodReturnTypeExtension) {
46454644
if (!$dynamicMethodReturnTypeExtension->isMethodSupported($methodReflection)) {
@@ -4657,16 +4656,17 @@ private function methodCallReturnType(Type $calledOnType, Type $typeWithMethod,
46574656
$resolvedTypes[] = $dynamicStaticMethodReturnTypeExtension->getTypeFromStaticMethodCall($methodReflection, $methodCall, $this);
46584657
}
46594658
}
4660-
if (count($resolvedTypes) > 0) {
4661-
return TypeCombinator::union(...$resolvedTypes);
4662-
}
46634659
}
46644660

4665-
$methodReturnType = ParametersAcceptorSelector::selectFromArgs(
4666-
$this,
4667-
$methodCall->args,
4668-
$methodReflection->getVariants()
4669-
)->getReturnType();
4661+
if (count($resolvedTypes) > 0) {
4662+
$methodReturnType = TypeCombinator::union(...$resolvedTypes);
4663+
} else {
4664+
$methodReturnType = ParametersAcceptorSelector::selectFromArgs(
4665+
$this,
4666+
$methodCall->args,
4667+
$methodReflection->getVariants()
4668+
)->getReturnType();
4669+
}
46704670

46714671
if ($methodCall instanceof MethodCall) {
46724672
$calledOnThis = $calledOnType instanceof StaticType && $this->isInClass();

tests/PHPStan/Analyser/NodeScopeResolverTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3235,7 +3235,7 @@ public function dataBinaryOperations(): array
32353235
'$simpleXMLWrongXpath',
32363236
],
32373237
[
3238-
'array<static(SimpleXMLElement)>|false',
3238+
'array<SimpleXMLElement>|false',
32393239
'$simpleXMLUnknownXpath',
32403240
],
32413241
];

0 commit comments

Comments
 (0)