@@ -25,32 +25,17 @@ class StaticType implements TypeWithClassName
25
25
use NonGenericTypeTrait;
26
26
use UndecidedComparisonTypeTrait;
27
27
28
- private ? ClassReflection $ classReflection ;
28
+ private ClassReflection $ classReflection ;
29
29
30
30
private ?\PHPStan \Type \ObjectType $ staticObjectType = null ;
31
31
32
32
private string $ baseClass ;
33
33
34
34
/**
35
35
* @api
36
- * @param string|ClassReflection $classReflection
37
36
*/
38
- public function __construct ($ classReflection )
39
- {
40
- if (is_string ($ classReflection )) {
41
- $ broker = Broker::getInstance ();
42
- if ($ broker ->hasClass ($ classReflection )) {
43
- $ classReflection = $ broker ->getClass ($ classReflection );
44
- $ this ->classReflection = $ classReflection ;
45
- $ this ->baseClass = $ classReflection ->getName ();
46
- return ;
47
- }
48
-
49
- $ this ->classReflection = null ;
50
- $ this ->baseClass = $ classReflection ;
51
- return ;
52
- }
53
-
37
+ public function __construct (ClassReflection $ classReflection )
38
+ {
54
39
$ this ->classReflection = $ classReflection ;
55
40
$ this ->baseClass = $ classReflection ->getName ();
56
41
}
@@ -72,13 +57,18 @@ public function getAncestorWithClassName(string $className): ?TypeWithClassName
72
57
return null ;
73
58
}
74
59
75
- return $ this ->changeBaseClass ($ ancestor ->getClassReflection () ?? $ ancestor ->getClassName ());
60
+ $ classReflection = $ ancestor ->getClassReflection ();
61
+ if ($ classReflection !== null ) {
62
+ return $ this ->changeBaseClass ($ classReflection );
63
+ }
64
+
65
+ return null ;
76
66
}
77
67
78
68
public function getStaticObjectType (): ObjectType
79
69
{
80
70
if ($ this ->staticObjectType === null ) {
81
- if ($ this ->classReflection !== null && $ this -> classReflection ->isGeneric ()) {
71
+ if ($ this ->classReflection ->isGeneric ()) {
82
72
$ typeMap = $ this ->classReflection ->getActiveTemplateTypeMap ()->map (static function (string $ name , Type $ type ): Type {
83
73
return TemplateTypeHelper::toArgument ($ type );
84
74
});
@@ -88,7 +78,7 @@ public function getStaticObjectType(): ObjectType
88
78
);
89
79
}
90
80
91
- return $ this ->staticObjectType = new ObjectType ($ this ->baseClass , null , $ this ->classReflection );
81
+ return $ this ->staticObjectType = new ObjectType ($ this ->classReflection -> getName () , null , $ this ->classReflection );
92
82
}
93
83
94
84
return $ this ->staticObjectType ;
@@ -102,11 +92,6 @@ public function getReferencedClasses(): array
102
92
return $ this ->getStaticObjectType ()->getReferencedClasses ();
103
93
}
104
94
105
- public function getBaseClass (): string
106
- {
107
- return $ this ->baseClass ;
108
- }
109
-
110
95
public function accepts (Type $ type , bool $ strictTypes ): TrinaryLogic
111
96
{
112
97
if ($ type instanceof CompoundType) {
@@ -247,9 +232,7 @@ private function transformStaticType(Type $type, ClassMemberAccessAnswerer $scop
247
232
if ($ type instanceof StaticType) {
248
233
$ classReflection = $ this ->classReflection ;
249
234
$ isFinal = false ;
250
- if ($ classReflection === null ) {
251
- $ classReflection = $ this ->baseClass ;
252
- } elseif ($ scope ->isInClass ()) {
235
+ if ($ scope ->isInClass ()) {
253
236
$ classReflection = $ scope ->getClassReflection ();
254
237
$ isFinal = $ classReflection ->isFinal ();
255
238
}
@@ -280,11 +263,7 @@ public function getConstant(string $constantName): ConstantReflection
280
263
return $ this ->getStaticObjectType ()->getConstant ($ constantName );
281
264
}
282
265
283
- /**
284
- * @param ClassReflection|string $classReflection
285
- * @return self
286
- */
287
- public function changeBaseClass ($ classReflection ): self
266
+ public function changeBaseClass (ClassReflection $ classReflection ): self
288
267
{
289
268
return new self ($ classReflection );
290
269
}
@@ -409,7 +388,12 @@ public function traverse(callable $cb): Type
409
388
*/
410
389
public static function __set_state (array $ properties ): Type
411
390
{
412
- return new self ($ properties ['baseClass ' ]);
391
+ $ broker = Broker::getInstance ();
392
+ if ($ broker ->hasClass ($ properties ['baseClass ' ])) {
393
+ return new self ($ broker ->getClass ($ properties ['baseClass ' ]));
394
+ }
395
+
396
+ return new ErrorType ();
413
397
}
414
398
415
399
}
0 commit comments