4
4
5
5
namespace GeekCell \Ddd \Domain ;
6
6
7
+ use ArrayAccess ;
8
+ use ArrayIterator ;
7
9
use Assert ;
10
+ use Countable ;
8
11
use InvalidArgumentException ;
12
+ use IteratorAggregate ;
9
13
use Traversable ;
14
+ use function array_filter ;
15
+ use function array_map ;
16
+ use function array_reduce ;
17
+ use function array_values ;
18
+ use function count ;
19
+ use function get_class ;
20
+ use function is_int ;
21
+ use function reset ;
10
22
11
23
/**
12
24
* @template T of object
13
- * @implements \ IteratorAggregate<T>
14
- * @implements \ ArrayAccess<mixed, T>
25
+ * @implements IteratorAggregate<T>
26
+ * @implements ArrayAccess<mixed, T>
15
27
*/
16
- class Collection implements \ ArrayAccess, \ Countable, \ IteratorAggregate
28
+ class Collection implements ArrayAccess, Countable, IteratorAggregate
17
29
{
18
30
/**
19
31
* @param T[] $items
@@ -249,7 +261,7 @@ public function add(mixed $item): static
249
261
public function filter (callable $ callback ): static
250
262
{
251
263
return new static (
252
- \ array_values (\ array_filter ($ this ->items , $ callback )),
264
+ array_values (array_filter ($ this ->items , $ callback )),
253
265
$ this ->itemType ,
254
266
);
255
267
}
@@ -267,15 +279,15 @@ public function filter(callable $callback): static
267
279
*/
268
280
public function map (callable $ callback , bool $ inferTypes = true ): static
269
281
{
270
- $ mapResult = \ array_map ($ callback , $ this ->items );
271
- $ firstItem = \ reset ($ mapResult );
282
+ $ mapResult = array_map ($ callback , $ this ->items );
283
+ $ firstItem = reset ($ mapResult );
272
284
273
285
if ($ firstItem === false || !is_object ($ firstItem )) {
274
286
return new static ($ mapResult );
275
287
}
276
288
277
289
if ($ inferTypes && $ this ->itemType !== null ) {
278
- return new static ($ mapResult , \ get_class ($ firstItem ));
290
+ return new static ($ mapResult , get_class ($ firstItem ));
279
291
}
280
292
281
293
return new static ($ mapResult );
@@ -291,15 +303,15 @@ public function map(callable $callback, bool $inferTypes = true): static
291
303
*/
292
304
public function reduce (callable $ callback , mixed $ initial = null ): mixed
293
305
{
294
- return \ array_reduce ($ this ->items , $ callback , $ initial );
306
+ return array_reduce ($ this ->items , $ callback , $ initial );
295
307
}
296
308
297
309
/**
298
310
* @inheritDoc
299
311
*/
300
312
public function offsetExists (mixed $ offset ): bool
301
313
{
302
- if (!\ is_int ($ offset )) {
314
+ if (!is_int ($ offset )) {
303
315
return false ;
304
316
}
305
317
@@ -345,14 +357,14 @@ public function offsetUnset(mixed $offset): void
345
357
*/
346
358
public function count (): int
347
359
{
348
- return \ count ($ this ->items );
360
+ return count ($ this ->items );
349
361
}
350
362
351
363
/**
352
364
* @inheritDoc
353
365
*/
354
366
public function getIterator (): Traversable
355
367
{
356
- return new \ ArrayIterator ($ this ->items );
368
+ return new ArrayIterator ($ this ->items );
357
369
}
358
370
}
0 commit comments