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