1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Type\Generic;
4:
5: use PHPStan\TrinaryLogic;
6: use PHPStan\Type\Constant\ConstantArrayType;
7: use PHPStan\Type\Constant\ConstantIntegerType;
8: use PHPStan\Type\Constant\ConstantStringType;
9: use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
10: use PHPStan\Type\Type;
11:
12: /** @api */
13: final class TemplateConstantArrayType extends ConstantArrayType implements TemplateType
14: {
15:
16: /** @use TemplateTypeTrait<ConstantArrayType> */
17: use TemplateTypeTrait;
18: use UndecidedComparisonCompoundTypeTrait;
19:
20: /**
21: * @param non-empty-string $name
22: */
23: public function __construct(
24: TemplateTypeScope $scope,
25: TemplateTypeStrategy $templateTypeStrategy,
26: TemplateTypeVariance $templateTypeVariance,
27: string $name,
28: ConstantArrayType $bound,
29: ?Type $default,
30: )
31: {
32: parent::__construct($bound->getKeyTypes(), $bound->getValueTypes(), $bound->getNextAutoIndexes(), $bound->getOptionalKeys(), $bound->isList());
33: $this->scope = $scope;
34: $this->strategy = $templateTypeStrategy;
35: $this->variance = $templateTypeVariance;
36: $this->name = $name;
37: $this->bound = $bound;
38: $this->default = $default;
39: }
40:
41: /**
42: * @param list<ConstantIntegerType|ConstantStringType> $keyTypes
43: * @param array<int, Type> $valueTypes
44: * @param non-empty-list<int> $nextAutoIndexes
45: * @param int[] $optionalKeys
46: */
47: protected function recreate(
48: array $keyTypes,
49: array $valueTypes,
50: array $nextAutoIndexes = [0],
51: array $optionalKeys = [],
52: ?TrinaryLogic $isList = null,
53: ): ConstantArrayType
54: {
55: return new self(
56: $this->scope,
57: $this->strategy,
58: $this->variance,
59: $this->name,
60: new ConstantArrayType($keyTypes, $valueTypes, $nextAutoIndexes, $optionalKeys, $isList),
61: $this->default,
62: );
63: }
64:
65: }
66: