2
2
3
3
namespace PHPStan \Type ;
4
4
5
+ use PHPStan \Broker \Broker ;
5
6
use PHPStan \Reflection \ClassMemberAccessAnswerer ;
6
7
use PHPStan \Reflection \ClassReflection ;
7
8
use PHPStan \Reflection \ConstantReflection ;
8
9
use PHPStan \Reflection \MethodReflection ;
9
10
use PHPStan \Reflection \PropertyReflection ;
10
11
use PHPStan \TrinaryLogic ;
12
+ use PHPStan \Type \Generic \GenericObjectType ;
13
+ use PHPStan \Type \Generic \TemplateTypeHelper ;
11
14
use PHPStan \Type \Traits \NonGenericTypeTrait ;
12
15
use PHPStan \Type \Traits \UndecidedComparisonTypeTrait ;
13
16
@@ -17,13 +20,22 @@ class StaticType implements TypeWithClassName
17
20
use NonGenericTypeTrait;
18
21
use UndecidedComparisonTypeTrait;
19
22
20
- private string $ baseClass ;
23
+ private ClassReflection $ classReflection ;
21
24
22
25
private ?\PHPStan \Type \ObjectType $ staticObjectType = null ;
23
26
24
- public function __construct (string $ baseClass )
27
+ private string $ baseClass ;
28
+
29
+ /**
30
+ * @param string|ClassReflection $classReflection
31
+ */
32
+ public function __construct ($ classReflection )
25
33
{
26
- $ this ->baseClass = $ baseClass ;
34
+ if (is_string ($ classReflection )) {
35
+ $ classReflection = Broker::getInstance ()->getClass ($ classReflection );
36
+ }
37
+ $ this ->classReflection = $ classReflection ;
38
+ $ this ->baseClass = $ classReflection ->getName ();
27
39
}
28
40
29
41
public function getClassName (): string
@@ -39,7 +51,17 @@ public function getAncestorWithClassName(string $className): ?ObjectType
39
51
public function getStaticObjectType (): ObjectType
40
52
{
41
53
if ($ this ->staticObjectType === null ) {
42
- $ this ->staticObjectType = new ObjectType ($ this ->baseClass );
54
+ if ($ this ->classReflection ->isGeneric ()) {
55
+ $ typeMap = $ this ->classReflection ->getTemplateTypeMap ()->map (static function (string $ name , Type $ type ): Type {
56
+ return TemplateTypeHelper::toArgument ($ type );
57
+ });
58
+ return $ this ->staticObjectType = new GenericObjectType (
59
+ $ this ->classReflection ->getName (),
60
+ $ this ->classReflection ->typeMapToList ($ typeMap )
61
+ );
62
+ }
63
+
64
+ return $ this ->staticObjectType = new ObjectType ($ this ->classReflection ->getName (), null , $ this ->classReflection );
43
65
}
44
66
45
67
return $ this ->staticObjectType ;
@@ -155,7 +177,7 @@ public function getConstant(string $constantName): ConstantReflection
155
177
156
178
public function changeBaseClass (ClassReflection $ classReflection ): self
157
179
{
158
- return new self ($ classReflection-> getName () );
180
+ return new self ($ classReflection );
159
181
}
160
182
161
183
public function isIterable (): TrinaryLogic
0 commit comments