1 | <?php |
||
14 | class Collection implements CollectionInterface |
||
15 | { |
||
16 | /** |
||
17 | * Collection's identifier. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $id = ''; |
||
22 | |||
23 | /** |
||
24 | * Collection's items. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $items = []; |
||
29 | |||
30 | /** |
||
31 | * Collection constructor. |
||
32 | * |
||
33 | * @param string|null $id |
||
34 | * @param array $items |
||
35 | */ |
||
36 | public function __construct($id = null, $items = []) |
||
47 | |||
48 | /** |
||
49 | * If parameter is empty uses the object's hash. |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | public function setId(string $id = null) |
||
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | */ |
||
65 | public function getId(): string |
||
69 | |||
70 | /** |
||
71 | * {@inheritdoc} |
||
72 | */ |
||
73 | public function has(string $id): bool |
||
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | */ |
||
81 | public function add(ItemInterface $item): ?CollectionInterface |
||
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | public function replace(string $id, ItemInterface $item): ?CollectionInterface |
||
111 | |||
112 | /** |
||
113 | * {@inheritdoc} |
||
114 | */ |
||
115 | public function remove(string $id): ?CollectionInterface |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | public function get(string $id): ?ItemInterface |
||
140 | |||
141 | /** |
||
142 | * {@inheritdoc} |
||
143 | */ |
||
144 | public function keys(): array |
||
148 | |||
149 | /** |
||
150 | * {@inheritdoc} |
||
151 | */ |
||
152 | public function first(): ?ItemInterface |
||
161 | |||
162 | /** |
||
163 | * {@inheritdoc} |
||
164 | */ |
||
165 | public function last(): ?ItemInterface |
||
174 | |||
175 | /** |
||
176 | * {@inheritdoc} |
||
177 | */ |
||
178 | public function count(): int |
||
182 | |||
183 | /** |
||
184 | * {@inheritdoc} |
||
185 | */ |
||
186 | public function toArray(): array |
||
190 | |||
191 | /** |
||
192 | * {@inheritdoc} |
||
193 | */ |
||
194 | public function getIterator(): \ArrayIterator |
||
198 | |||
199 | /** |
||
200 | * {@inheritdoc} |
||
201 | */ |
||
202 | public function usort(\Closure $callback = null): CollectionInterface |
||
214 | |||
215 | /** |
||
216 | * {@inheritdoc} |
||
217 | */ |
||
218 | public function filter(\Closure $callback): CollectionInterface |
||
222 | |||
223 | /** |
||
224 | * {@inheritdoc} |
||
225 | */ |
||
226 | public function map(\Closure $callback): CollectionInterface |
||
230 | |||
231 | /** |
||
232 | * Implement ArrayAccess. |
||
233 | * |
||
234 | * @param string $offset |
||
235 | * |
||
236 | * @return bool |
||
237 | */ |
||
238 | public function offsetExists($offset) |
||
242 | |||
243 | /** |
||
244 | * Implement ArrayAccess. |
||
245 | * |
||
246 | * @param string $offset |
||
247 | * |
||
248 | * @return CollectionInterface|bool |
||
249 | */ |
||
250 | public function offsetGet($offset) |
||
254 | |||
255 | /** |
||
256 | * Implement ArrayAccess. |
||
257 | * |
||
258 | * @param mixed $offset |
||
259 | * @param ItemInterface $value |
||
260 | * |
||
261 | * @return CollectionInterface|null |
||
262 | */ |
||
263 | public function offsetSet($offset, $value) |
||
267 | |||
268 | /** |
||
269 | * Implement ArrayAccess. |
||
270 | * |
||
271 | * @param string $offset |
||
272 | * |
||
273 | * @return CollectionInterface|null |
||
274 | */ |
||
275 | public function offsetUnset($offset) |
||
279 | |||
280 | /** |
||
281 | * Returns a string representation of this object. |
||
282 | * |
||
283 | * @return string |
||
284 | */ |
||
285 | public function __toString() |
||
289 | } |
||
290 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.