|
6 | 6 | use PHPStan\Analyser\Scope; |
7 | 7 | use PHPStan\Reflection\MethodReflection; |
8 | 8 | use PHPStan\Type\Constant\ConstantBooleanType; |
9 | | -use PHPStan\Type\Constant\ConstantStringType; |
10 | 9 | use PHPStan\Type\DynamicMethodReturnTypeExtension; |
11 | 10 | use PHPStan\Type\MixedType; |
12 | 11 | use PHPStan\Type\ObjectType; |
@@ -46,25 +45,30 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method |
46 | 45 | return $mixedType; |
47 | 46 | } |
48 | 47 | $argType = $scope->getType($methodCall->getArgs()[0]->value); |
49 | | - if (!$argType instanceof ConstantStringType) { |
| 48 | + if (count($argType->getConstantStrings()) === 0) { |
50 | 49 | return $mixedType; |
51 | 50 | } |
52 | 51 |
|
53 | | - $type = new ObjectType($argType->getValue()); |
54 | | - if ( |
55 | | - $methodReflection->getName() === 'getByType' |
56 | | - && count($methodCall->getArgs()) >= 2 |
57 | | - ) { |
58 | | - $throwType = $scope->getType($methodCall->getArgs()[1]->value); |
| 52 | + $types = []; |
| 53 | + foreach ($argType->getConstantStrings() as $constantString) { |
| 54 | + $type = new ObjectType($constantString->getValue()); |
59 | 55 | if ( |
60 | | - !$throwType instanceof ConstantBooleanType |
61 | | - || !$throwType->getValue() |
| 56 | + $methodReflection->getName() === 'getByType' |
| 57 | + && count($methodCall->getArgs()) >= 2 |
62 | 58 | ) { |
63 | | - $type = TypeCombinator::addNull($type); |
| 59 | + $throwType = $scope->getType($methodCall->getArgs()[1]->value); |
| 60 | + if ( |
| 61 | + !$throwType instanceof ConstantBooleanType |
| 62 | + || !$throwType->getValue() |
| 63 | + ) { |
| 64 | + $type = TypeCombinator::addNull($type); |
| 65 | + } |
64 | 66 | } |
| 67 | + |
| 68 | + $types[] = $type; |
65 | 69 | } |
66 | 70 |
|
67 | | - return $type; |
| 71 | + return TypeCombinator::union(...$types); |
68 | 72 | } |
69 | 73 |
|
70 | 74 | } |
0 commit comments