1 | <?php |
||
20 | final class AddressCollection implements Collection |
||
21 | { |
||
22 | /** |
||
23 | * @var Location[] |
||
24 | */ |
||
25 | private $locations; |
||
26 | |||
27 | /** |
||
28 | * @param Location[] $locations |
||
29 | */ |
||
30 | 5 | public function __construct(array $locations = []) |
|
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | public function getIterator() |
||
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | public function count() |
||
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | 3 | public function first(): Location |
|
55 | { |
||
56 | 3 | if (empty($this->locations)) { |
|
57 | 1 | throw new CollectionIsEmpty(); |
|
58 | } |
||
59 | |||
60 | 2 | return reset($this->locations); |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | public function isEmpty(): bool |
||
70 | |||
71 | /** |
||
72 | * @return Location[] |
||
73 | */ |
||
74 | public function slice(int $offset, int $length = null) |
||
78 | |||
79 | /** |
||
80 | * @return bool |
||
81 | */ |
||
82 | public function has(int $index): bool |
||
86 | |||
87 | /** |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | public function get(int $index): Location |
||
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | public function all(): array |
||
106 | } |
||
107 |