|
9 | 9 | use PHPStan\Type\Constant\ConstantBooleanType;
|
10 | 10 | use PHPStan\Type\Constant\ConstantStringType;
|
11 | 11 | use PHPStan\Type\DynamicFunctionReturnTypeExtension;
|
| 12 | +use PHPStan\Type\Enum\EnumCaseObjectType; |
12 | 13 | use PHPStan\Type\Generic\GenericClassStringType;
|
| 14 | +use PHPStan\Type\IntersectionType; |
13 | 15 | use PHPStan\Type\ObjectShapeType;
|
| 16 | +use PHPStan\Type\ObjectType; |
14 | 17 | use PHPStan\Type\ObjectWithoutClassType;
|
15 | 18 | use PHPStan\Type\StaticType;
|
16 | 19 | use PHPStan\Type\Type;
|
| 20 | +use PHPStan\Type\TypeCombinator; |
17 | 21 | use PHPStan\Type\TypeTraverser;
|
18 | 22 | use PHPStan\Type\TypeUtils;
|
19 |
| -use PHPStan\Type\TypeCombinator; |
20 | 23 | use PHPStan\Type\UnionType;
|
21 | 24 | use function count;
|
22 | 25 |
|
@@ -50,29 +53,42 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
|
50 | 53 | return new ClassStringType();
|
51 | 54 | }
|
52 | 55 |
|
53 |
| - $isObject = $argType->isObject(); |
54 |
| - if ($isObject->yes() || $isObject->maybe()) { |
55 |
| - if ($argType instanceof ObjectShapeType) { |
56 |
| - return new ClassStringType(); |
57 |
| - } |
58 |
| - |
59 |
| - $objectType = TypeCombinator::intersect($argType, new ObjectWithoutClassType()); |
60 |
| - if ($objectType instanceof StaticType) { |
61 |
| - $objectType = $objectType->getStaticObjectType(); |
62 |
| - } |
63 |
| - $classStringType = new GenericClassStringType($objectType); |
64 |
| - |
65 |
| - if ($isObject->yes()) { |
66 |
| - return $classStringType; |
67 |
| - } |
68 |
| - |
69 |
| - return new UnionType([ |
70 |
| - $classStringType, |
71 |
| - new ConstantBooleanType(false), |
72 |
| - ]); |
73 |
| - } |
74 |
| - |
75 |
| - return new ConstantBooleanType(false); |
| 56 | + return TypeTraverser::map( |
| 57 | + $argType, |
| 58 | + static function (Type $type, callable $traverse): Type { |
| 59 | + if ($type instanceof UnionType || $type instanceof IntersectionType) { |
| 60 | + return $traverse($type); |
| 61 | + } |
| 62 | + |
| 63 | + if ($type instanceof EnumCaseObjectType) { |
| 64 | + return new GenericClassStringType(new ObjectType($type->getClassName())); |
| 65 | + } |
| 66 | + |
| 67 | + $isObject = $type->isObject(); |
| 68 | + if ($isObject->yes() || $isObject->maybe()) { |
| 69 | + if ($type instanceof ObjectShapeType) { |
| 70 | + return new ClassStringType(); |
| 71 | + } |
| 72 | + |
| 73 | + $objectType = TypeCombinator::intersect($type, new ObjectWithoutClassType()); |
| 74 | + if ($objectType instanceof StaticType) { |
| 75 | + $objectType = $objectType->getStaticObjectType(); |
| 76 | + } |
| 77 | + $classStringType = new GenericClassStringType($objectType); |
| 78 | + |
| 79 | + if ($isObject->yes()) { |
| 80 | + return $classStringType; |
| 81 | + } |
| 82 | + |
| 83 | + return new UnionType([ |
| 84 | + $classStringType, |
| 85 | + new ConstantBooleanType(false), |
| 86 | + ]); |
| 87 | + } |
| 88 | + |
| 89 | + return new ConstantBooleanType(false); |
| 90 | + }, |
| 91 | + ); |
76 | 92 | }
|
77 | 93 |
|
78 | 94 | }
|
0 commit comments