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: ?Type $default,
27: )
28: {
29: parent::__construct($bound->getType());
30: $this->scope = $scope;
31: $this->strategy = $templateTypeStrategy;
32: $this->variance = $templateTypeVariance;
33: $this->name = $name;
34: $this->bound = $bound;
35: $this->default = $default;
36: }
37:
38: protected function getResult(): Type
39: {
40: $result = $this->getBound()->getResult();
41:
42: return TemplateTypeFactory::create(
43: $this->getScope(),
44: $this->getName(),
45: $result,
46: $this->getVariance(),
47: $this->getStrategy(),
48: $this->getDefault(),
49: );
50: }
51:
52: protected function shouldGeneralizeInferredType(): bool
53: {
54: return false;
55: }
56:
57: }
58: