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