1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\PhpDocParser\Ast\Type;
4:
5: use PHPStan\PhpDocParser\Ast\NodeAttributes;
6: use function array_map;
7: use function implode;
8:
9: class UnionTypeNode implements TypeNode
10: {
11:
12: use NodeAttributes;
13:
14: /** @var TypeNode[] */
15: public array $types;
16:
17: /**
18: * @param TypeNode[] $types
19: */
20: public function __construct(array $types)
21: {
22: $this->types = $types;
23: }
24:
25:
26: public function __toString(): string
27: {
28: return '(' . implode(' | ', array_map(static function (TypeNode $type): string {
29: if ($type instanceof NullableTypeNode) {
30: return '(' . $type . ')';
31: }
32:
33: return (string) $type;
34: }, $this->types)) . ')';
35: }
36:
37: }
38: