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 IntersectionTypeNode implements TypeNode |
10: | { |
11: | |
12: | use NodeAttributes; |
13: | |
14: | |
15: | public array $types; |
16: | |
17: | |
18: | |
19: | |
20: | public function __construct(array $types) |
21: | { |
22: | $this->types = $types; |
23: | } |
24: | |
25: | public function __toString(): string |
26: | { |
27: | return '(' . implode(' & ', array_map(static function (TypeNode $type): string { |
28: | if ($type instanceof NullableTypeNode) { |
29: | return '(' . $type . ')'; |
30: | } |
31: | |
32: | return (string) $type; |
33: | }, $this->types)) . ')'; |
34: | } |
35: | |
36: | } |
37: | |