|
14 | 14 | use PHPStan\Type\Generic\GenericClassStringType; |
15 | 15 | use PHPStan\Type\Generic\TemplateType; |
16 | 16 | use PHPStan\Type\IntersectionType; |
17 | | -use PHPStan\Type\MixedType; |
| 17 | +use PHPStan\Type\ObjectShapeType; |
18 | 18 | use PHPStan\Type\ObjectType; |
19 | 19 | use PHPStan\Type\ObjectWithoutClassType; |
20 | 20 | use PHPStan\Type\StaticType; |
21 | 21 | use PHPStan\Type\Type; |
| 22 | +use PHPStan\Type\TypeCombinator; |
22 | 23 | use PHPStan\Type\TypeTraverser; |
23 | 24 | use PHPStan\Type\TypeUtils; |
24 | 25 | use PHPStan\Type\UnionType; |
@@ -66,30 +67,35 @@ static function (Type $type, callable $traverse): Type { |
66 | 67 | return new GenericClassStringType(new ObjectType($type->getClassName())); |
67 | 68 | } |
68 | 69 |
|
69 | | - $objectClassNames = $type->getObjectClassNames(); |
70 | | - if ($type instanceof TemplateType && $objectClassNames === []) { |
71 | | - if ($type instanceof ObjectWithoutClassType) { |
72 | | - return new GenericClassStringType($type); |
73 | | - } |
74 | | - |
75 | | - return new UnionType([ |
76 | | - new GenericClassStringType($type), |
77 | | - new ConstantBooleanType(false), |
78 | | - ]); |
79 | | - } elseif ($type instanceof MixedType) { |
80 | | - return new UnionType([ |
81 | | - new ClassStringType(), |
82 | | - new ConstantBooleanType(false), |
83 | | - ]); |
84 | | - } elseif ($type instanceof StaticType) { |
85 | | - return new GenericClassStringType($type->getStaticObjectType()); |
86 | | - } elseif ($objectClassNames !== []) { |
87 | | - return new GenericClassStringType($type); |
88 | | - } elseif ($type instanceof ObjectWithoutClassType) { |
| 70 | + if ($type instanceof ObjectShapeType) { |
89 | 71 | return new ClassStringType(); |
90 | 72 | } |
91 | 73 |
|
92 | | - return new ConstantBooleanType(false); |
| 74 | + $isObject = $type->isObject(); |
| 75 | + if ($isObject->no()) { |
| 76 | + return new ConstantBooleanType(false); |
| 77 | + } |
| 78 | + |
| 79 | + if ($type instanceof StaticType) { |
| 80 | + $objectType = $type->getStaticObjectType(); |
| 81 | + } else { |
| 82 | + $objectType = TypeCombinator::intersect($type, new ObjectWithoutClassType()); |
| 83 | + } |
| 84 | + |
| 85 | + if (!$objectType instanceof TemplateType && $objectType instanceof ObjectWithoutClassType) { |
| 86 | + $classStringType = new ClassStringType(); |
| 87 | + } else { |
| 88 | + $classStringType = new GenericClassStringType($objectType); |
| 89 | + } |
| 90 | + |
| 91 | + if ($isObject->yes()) { |
| 92 | + return $classStringType; |
| 93 | + } |
| 94 | + |
| 95 | + return new UnionType([ |
| 96 | + $classStringType, |
| 97 | + new ConstantBooleanType(false), |
| 98 | + ]); |
93 | 99 | }, |
94 | 100 | ); |
95 | 101 | } |
|
0 commit comments