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