1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Type\Generic;
4:
5: use PHPStan\Turbo\ShadowedByTurboExtension;
6: use PHPStan\Type\ArrayType;
7: use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
8: use PHPStan\Type\Type;
9:
10: /** @api */
11: #[ShadowedByTurboExtension(implementation: __DIR__ . '/../../../turbo-ext/src/TemplateArrayType.cpp')]
12: final class TemplateArrayType extends ArrayType implements TemplateType
13: {
14:
15: /** @use TemplateTypeTrait<ArrayType> */
16: use TemplateTypeTrait;
17: use UndecidedComparisonCompoundTypeTrait;
18:
19: /**
20: * @param non-empty-string $name
21: */
22: public function __construct(
23: TemplateTypeScope $scope,
24: TemplateTypeStrategy $templateTypeStrategy,
25: TemplateTypeVariance $templateTypeVariance,
26: string $name,
27: ArrayType $bound,
28: ?Type $default,
29: )
30: {
31: parent::__construct($bound->getKeyType(), $bound->getItemType());
32: $this->scope = $scope;
33: $this->strategy = $templateTypeStrategy;
34: $this->variance = $templateTypeVariance;
35: $this->name = $name;
36: $this->bound = $bound;
37: $this->default = $default;
38: }
39:
40: protected function withTypes(Type $keyType, Type $itemType): ArrayType
41: {
42: return new self(
43: $this->scope,
44: $this->strategy,
45: $this->variance,
46: $this->name,
47: new ArrayType($keyType, $itemType),
48: $this->default,
49: );
50: }
51:
52: }
53: