1: | <?php declare(strict_types = 1); |
2: | |
3: | namespace PHPStan\PhpDocParser\Ast\Type; |
4: | |
5: | use PHPStan\PhpDocParser\Ast\NodeAttributes; |
6: | use function implode; |
7: | |
8: | class ArrayShapeNode implements TypeNode |
9: | { |
10: | |
11: | public const KIND_ARRAY = 'array'; |
12: | public const KIND_LIST = 'list'; |
13: | |
14: | use NodeAttributes; |
15: | |
16: | |
17: | public $items; |
18: | |
19: | |
20: | public $sealed; |
21: | |
22: | |
23: | public $kind; |
24: | |
25: | |
26: | public $unsealedType; |
27: | |
28: | |
29: | |
30: | |
31: | |
32: | public function __construct( |
33: | array $items, |
34: | bool $sealed = true, |
35: | string $kind = self::KIND_ARRAY, |
36: | ?ArrayShapeUnsealedTypeNode $unsealedType = null |
37: | ) |
38: | { |
39: | $this->items = $items; |
40: | $this->sealed = $sealed; |
41: | $this->kind = $kind; |
42: | $this->unsealedType = $unsealedType; |
43: | } |
44: | |
45: | |
46: | public function __toString(): string |
47: | { |
48: | $items = $this->items; |
49: | |
50: | if (! $this->sealed) { |
51: | $items[] = '...' . $this->unsealedType; |
52: | } |
53: | |
54: | return $this->kind . '{' . implode(', ', $items) . '}'; |
55: | } |
56: | |
57: | } |
58: | |