Skip to content

Commit 72e878d

Browse files
author
Benjamin Rambaud
committed
fix: call all involved class for MethodTypeSpecifyingExtension and StaticMethodTypeSpecifyingExtension
For the moment, we only want to try a modification to see if existing tests passed. The next steps is to implement a test to reproduce the error then we'll re-implement the modification for real.
1 parent 2fe4e0f commit 72e878d

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -519,19 +519,28 @@ public function specifyTypesInCondition(
519519
$methodReflection = $scope->getMethodReflection($methodCalledOnType, $expr->name->name);
520520
if ($methodReflection !== null) {
521521
$referencedClasses = $methodCalledOnType->getObjectClassNames();
522-
if (
523-
count($referencedClasses) === 1
524-
&& $this->reflectionProvider->hasClass($referencedClasses[0])
525-
) {
526-
$methodClassReflection = $this->reflectionProvider->getClass($referencedClasses[0]);
522+
$specifiedTypes = null;
523+
foreach ($referencedClasses as $referencedClass) {
524+
if (!$this->reflectionProvider->hasClass($referencedClass)) {
525+
continue;
526+
}
527+
528+
$methodClassReflection = $this->reflectionProvider->getClass($referencedClass);
527529
foreach ($this->getMethodTypeSpecifyingExtensionsForClass($methodClassReflection->getName()) as $extension) {
528530
if (!$extension->isMethodSupported($methodReflection, $expr, $context)) {
529531
continue;
530532
}
531533

532-
return $extension->specifyTypes($methodReflection, $expr, $scope, $context);
534+
if ($specifiedTypes !== null) {
535+
$specifiedTypes = $specifiedTypes->unionWith($extension->specifyTypes($methodReflection, $expr, $scope, $context));
536+
} else {
537+
$specifiedTypes = $extension->specifyTypes($methodReflection, $expr, $scope, $context);
538+
}
533539
}
534540
}
541+
if ($specifiedTypes !== null) {
542+
return $specifiedTypes;
543+
}
535544

536545
// lazy create parametersAcceptor, as creation can be expensive
537546
$parametersAcceptor = null;
@@ -572,19 +581,28 @@ public function specifyTypesInCondition(
572581
$staticMethodReflection = $scope->getMethodReflection($calleeType, $expr->name->name);
573582
if ($staticMethodReflection !== null) {
574583
$referencedClasses = $calleeType->getObjectClassNames();
575-
if (
576-
count($referencedClasses) === 1
577-
&& $this->reflectionProvider->hasClass($referencedClasses[0])
578-
) {
579-
$staticMethodClassReflection = $this->reflectionProvider->getClass($referencedClasses[0]);
584+
$specifiedTypes = null;
585+
foreach ($referencedClasses as $referencedClass) {
586+
if (!$this->reflectionProvider->hasClass($referencedClass)) {
587+
continue;
588+
}
589+
590+
$staticMethodClassReflection = $this->reflectionProvider->getClass($referencedClass);
580591
foreach ($this->getStaticMethodTypeSpecifyingExtensionsForClass($staticMethodClassReflection->getName()) as $extension) {
581592
if (!$extension->isStaticMethodSupported($staticMethodReflection, $expr, $context)) {
582593
continue;
583594
}
584595

585-
return $extension->specifyTypes($staticMethodReflection, $expr, $scope, $context);
596+
if ($specifiedTypes !== null) {
597+
$specifiedTypes = $specifiedTypes->unionWith($extension->specifyTypes($staticMethodReflection, $expr, $scope, $context));
598+
} else {
599+
$specifiedTypes = $extension->specifyTypes($staticMethodReflection, $expr, $scope, $context);
600+
}
586601
}
587602
}
603+
if ($specifiedTypes !== null) {
604+
return $specifiedTypes;
605+
}
588606

589607
// lazy create parametersAcceptor, as creation can be expensive
590608
$parametersAcceptor = null;

0 commit comments

Comments
 (0)