1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Type\Generic;
4:
5: use PHPStan\Turbo\ShadowedByTurboExtension;
6: use PHPStan\Type\Type;
7: use PHPStan\Type\UnionType;
8:
9: /** @api */
10: #[ShadowedByTurboExtension(implementation: __DIR__ . '/../../../turbo-ext/src/TemplateUnionType.cpp')]
11: final class TemplateUnionType extends UnionType implements TemplateType
12: {
13:
14: /** @use TemplateTypeTrait<UnionType> */
15: use TemplateTypeTrait;
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: UnionType $bound,
26: ?Type $default,
27: )
28: {
29: parent::__construct($bound->getTypes());
30:
31: $this->scope = $scope;
32: $this->strategy = $templateTypeStrategy;
33: $this->variance = $templateTypeVariance;
34: $this->name = $name;
35: $this->bound = $bound;
36: $this->default = $default;
37: }
38:
39: public function filterTypes(callable $filterCb): Type
40: {
41: $result = parent::filterTypes($filterCb);
42: if (!$result instanceof TemplateType) {
43: return TemplateTypeFactory::create(
44: $this->getScope(),
45: $this->getName(),
46: $result,
47: $this->getVariance(),
48: $this->getStrategy(),
49: $this->getDefault(),
50: );
51: }
52:
53: return $result;
54: }
55:
56: }
57: