1: | <?php declare(strict_types = 1); |
2: | |
3: | namespace PHPStan\Type; |
4: | |
5: | use PHPStan\Type\Generic\TemplateTypeHelper; |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | class GenericTypeVariableResolver |
12: | { |
13: | |
14: | |
15: | |
16: | |
17: | public static function getType( |
18: | TypeWithClassName $type, |
19: | string $genericClassName, |
20: | string $typeVariableName, |
21: | ): ?Type |
22: | { |
23: | $classReflection = $type->getClassReflection(); |
24: | if ($classReflection === null) { |
25: | return null; |
26: | } |
27: | $ancestorClassReflection = $classReflection->getAncestorWithClassName($genericClassName); |
28: | if ($ancestorClassReflection === null) { |
29: | return null; |
30: | } |
31: | |
32: | $activeTemplateTypeMap = $ancestorClassReflection->getPossiblyIncompleteActiveTemplateTypeMap(); |
33: | |
34: | $type = $activeTemplateTypeMap->getType($typeVariableName); |
35: | if ($type instanceof ErrorType) { |
36: | $templateTypeMap = $ancestorClassReflection->getTemplateTypeMap(); |
37: | $templateType = $templateTypeMap->getType($typeVariableName); |
38: | if ($templateType === null) { |
39: | return $type; |
40: | } |
41: | |
42: | $bound = TemplateTypeHelper::resolveToBounds($templateType); |
43: | if ($bound instanceof MixedType && $bound->isExplicitMixed()) { |
44: | return new MixedType(false); |
45: | } |
46: | |
47: | return $bound; |
48: | } |
49: | |
50: | return $type; |
51: | } |
52: | |
53: | } |
54: | |