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: | public const KIND_NON_EMPTY_ARRAY = 'non-empty-array'; |
14: | public const KIND_NON_EMPTY_LIST = 'non-empty-list'; |
15: | |
16: | use NodeAttributes; |
17: | |
18: | |
19: | public $items; |
20: | |
21: | |
22: | public $sealed; |
23: | |
24: | |
25: | public $kind; |
26: | |
27: | |
28: | public $unsealedType; |
29: | |
30: | |
31: | |
32: | |
33: | |
34: | public function __construct( |
35: | array $items, |
36: | bool $sealed = true, |
37: | string $kind = self::KIND_ARRAY, |
38: | ?ArrayShapeUnsealedTypeNode $unsealedType = null |
39: | ) |
40: | { |
41: | $this->items = $items; |
42: | $this->sealed = $sealed; |
43: | $this->kind = $kind; |
44: | $this->unsealedType = $unsealedType; |
45: | } |
46: | |
47: | |
48: | public function __toString(): string |
49: | { |
50: | $items = $this->items; |
51: | |
52: | if (! $this->sealed) { |
53: | $items[] = '...' . $this->unsealedType; |
54: | } |
55: | |
56: | return $this->kind . '{' . implode(', ', $items) . '}'; |
57: | } |
58: | |
59: | } |
60: | |