44
55use PHPStan \PhpDoc \Tag \TemplateTag ;
66use PHPStan \Type \BenevolentUnionType ;
7+ use PHPStan \Type \IntegerType ;
78use PHPStan \Type \MixedType ;
89use PHPStan \Type \ObjectType ;
910use PHPStan \Type \ObjectWithoutClassType ;
11+ use PHPStan \Type \StringType ;
1012use PHPStan \Type \Type ;
13+ use PHPStan \Type \TypeWithClassName ;
1114use PHPStan \Type \UnionType ;
1215
1316final class TemplateTypeFactory
1417{
1518
16- public static function create (TemplateTypeScope $ scope , string $ name , ?Type $ bound , TemplateTypeVariance $ variance ): Type
19+ public static function create (TemplateTypeScope $ scope , string $ name , ?Type $ bound , TemplateTypeVariance $ variance ): TemplateType
1720 {
1821 $ strategy = new TemplateTypeParameterStrategy ();
1922
@@ -22,13 +25,21 @@ public static function create(TemplateTypeScope $scope, string $name, ?Type $bou
2225 }
2326
2427 $ boundClass = get_class ($ bound );
25- if ($ boundClass === ObjectType::class) {
28+ if ($ bound instanceof TypeWithClassName && $ boundClass === ObjectType::class) {
2629 return new TemplateObjectType ($ scope , $ strategy , $ variance , $ name , $ bound ->getClassName ());
2730 }
2831 if ($ boundClass === ObjectWithoutClassType::class) {
2932 return new TemplateObjectWithoutClassType ($ scope , $ strategy , $ variance , $ name );
3033 }
3134
35+ if ($ boundClass === StringType::class) {
36+ return new TemplateStringType ($ scope , $ strategy , $ variance , $ name );
37+ }
38+
39+ if ($ boundClass === IntegerType::class) {
40+ return new TemplateIntegerType ($ scope , $ strategy , $ variance , $ name );
41+ }
42+
3243 if ($ boundClass === MixedType::class) {
3344 return new TemplateMixedType ($ scope , $ strategy , $ variance , $ name );
3445 }
@@ -46,7 +57,7 @@ public static function create(TemplateTypeScope $scope, string $name, ?Type $bou
4657 return new TemplateMixedType ($ scope , $ strategy , $ variance , $ name );
4758 }
4859
49- public static function fromTemplateTag (TemplateTypeScope $ scope , TemplateTag $ tag ): Type
60+ public static function fromTemplateTag (TemplateTypeScope $ scope , TemplateTag $ tag ): TemplateType
5061 {
5162 return self ::create ($ scope , $ tag ->getName (), $ tag ->getBound (), $ tag ->getVariance ());
5263 }
0 commit comments