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 |
||
160 | |||
161 | /** |
||
162 | * {@inheritdoc} |
||
163 | */ |
||
164 | public function count(): int |
||
168 | |||
169 | /** |
||
170 | * {@inheritdoc} |
||
171 | */ |
||
172 | public function toArray(): array |
||
176 | |||
177 | /** |
||
178 | * {@inheritdoc} |
||
179 | */ |
||
180 | public function getIterator(): \ArrayIterator |
||
184 | |||
185 | /** |
||
186 | * {@inheritdoc} |
||
187 | */ |
||
188 | public function usort(\Closure $callback = null): CollectionInterface |
||
200 | |||
201 | /** |
||
202 | * {@inheritdoc} |
||
203 | */ |
||
204 | public function filter(\Closure $callback): CollectionInterface |
||
208 | |||
209 | /** |
||
210 | * {@inheritdoc} |
||
211 | */ |
||
212 | public function map(\Closure $callback): CollectionInterface |
||
216 | |||
217 | /** |
||
218 | * Implement ArrayAccess. |
||
219 | * |
||
220 | * @param string $offset |
||
221 | * |
||
222 | * @return bool |
||
223 | */ |
||
224 | public function offsetExists($offset) |
||
228 | |||
229 | /** |
||
230 | * Implement ArrayAccess. |
||
231 | * |
||
232 | * @param string $offset |
||
233 | * |
||
234 | * @return CollectionInterface|bool |
||
|
|||
235 | */ |
||
236 | public function offsetGet($offset) |
||
240 | |||
241 | /** |
||
242 | * Implement ArrayAccess. |
||
243 | * |
||
244 | * @param mixed $offset |
||
245 | * @param ItemInterface $value |
||
246 | * |
||
247 | * @return CollectionInterface|null |
||
248 | */ |
||
249 | public function offsetSet($offset, $value) |
||
253 | |||
254 | /** |
||
255 | * Implement ArrayAccess. |
||
256 | * |
||
257 | * @param string $offset |
||
258 | * |
||
259 | * @return CollectionInterface|null |
||
260 | */ |
||
261 | public function offsetUnset($offset) |
||
265 | |||
266 | /** |
||
267 | * Returns a string representation of this object. |
||
268 | * |
||
269 | * @return string |
||
270 | */ |
||
271 | public function __toString() |
||
275 | } |
||
276 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.