22
33namespace PHPStan \Type ;
44
5+ use PHPStan \Broker \Broker ;
56use PHPStan \Reflection \ClassMemberAccessAnswerer ;
67use PHPStan \Reflection \ClassReflection ;
78use PHPStan \Reflection \ConstantReflection ;
89use PHPStan \Reflection \MethodReflection ;
910use PHPStan \Reflection \PropertyReflection ;
1011use PHPStan \TrinaryLogic ;
12+ use PHPStan \Type \Generic \GenericObjectType ;
13+ use PHPStan \Type \Generic \TemplateTypeHelper ;
1114use PHPStan \Type \Traits \NonGenericTypeTrait ;
1215use PHPStan \Type \Traits \UndecidedComparisonTypeTrait ;
1316
@@ -17,13 +20,22 @@ class StaticType implements TypeWithClassName
1720 use NonGenericTypeTrait;
1821 use UndecidedComparisonTypeTrait;
1922
20- private string $ baseClass ;
23+ private ClassReflection $ classReflection ;
2124
2225 private ?\PHPStan \Type \ObjectType $ staticObjectType = null ;
2326
24- public function __construct (string $ baseClass )
27+ private string $ baseClass ;
28+
29+ /**
30+ * @param string|ClassReflection $classReflection
31+ */
32+ public function __construct ($ classReflection )
2533 {
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 ();
2739 }
2840
2941 public function getClassName (): string
@@ -39,7 +51,17 @@ public function getAncestorWithClassName(string $className): ?ObjectType
3951 public function getStaticObjectType (): ObjectType
4052 {
4153 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 );
4365 }
4466
4567 return $ this ->staticObjectType ;
@@ -155,7 +177,7 @@ public function getConstant(string $constantName): ConstantReflection
155177
156178 public function changeBaseClass (ClassReflection $ classReflection ): self
157179 {
158- return new self ($ classReflection-> getName () );
180+ return new self ($ classReflection );
159181 }
160182
161183 public function isIterable (): TrinaryLogic
0 commit comments