1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Type\Generic;
4:
5: use PHPStan\Type\Type;
6: use PHPStan\Type\UnionType;
7:
8: /** @api */
9: final class TemplateUnionType extends UnionType implements TemplateType
10: {
11:
12: /** @use TemplateTypeTrait<UnionType> */
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: UnionType $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: public function filterTypes(callable $filterCb): Type
38: {
39: $result = parent::filterTypes($filterCb);
40: if (!$result instanceof TemplateType) {
41: return TemplateTypeFactory::create(
42: $this->getScope(),
43: $this->getName(),
44: $result,
45: $this->getVariance(),
46: $this->getStrategy(),
47: $this->getDefault(),
48: );
49: }
50:
51: return $result;
52: }
53:
54: }
55: