1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Type\Generic;
4:
5: use PHPStan\Type\KeyOfType;
6: use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
7: use PHPStan\Type\Type;
8:
9: /** @api */
10: final class TemplateKeyOfType extends KeyOfType implements TemplateType
11: {
12:
13: /** @use TemplateTypeTrait<KeyOfType> */
14: use TemplateTypeTrait;
15: use UndecidedComparisonCompoundTypeTrait;
16:
17: /**
18: * @param non-empty-string $name
19: */
20: public function __construct(
21: TemplateTypeScope $scope,
22: TemplateTypeStrategy $templateTypeStrategy,
23: TemplateTypeVariance $templateTypeVariance,
24: string $name,
25: KeyOfType $bound,
26: )
27: {
28: parent::__construct($bound->getType());
29: $this->scope = $scope;
30: $this->strategy = $templateTypeStrategy;
31: $this->variance = $templateTypeVariance;
32: $this->name = $name;
33: $this->bound = $bound;
34: }
35:
36: protected function getResult(): Type
37: {
38: $result = $this->getBound()->getResult();
39:
40: return TemplateTypeFactory::create(
41: $this->getScope(),
42: $this->getName(),
43: $result,
44: $this->getVariance(),
45: $this->getStrategy(),
46: );
47: }
48:
49: protected function shouldGeneralizeInferredType(): bool
50: {
51: return false;
52: }
53:
54: }
55: