Skip to content

Commit 52ced3c

Browse files
author
Bl00D4NGEL
committed
refac: import functions in Collection
1 parent 74ce180 commit 52ced3c

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

src/Domain/Collection.php

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,28 @@
44

55
namespace GeekCell\Ddd\Domain;
66

7+
use ArrayAccess;
8+
use ArrayIterator;
79
use Assert;
10+
use Countable;
811
use InvalidArgumentException;
12+
use IteratorAggregate;
913
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;
1022

1123
/**
1224
* @template T of object
13-
* @implements \IteratorAggregate<T>
14-
* @implements \ArrayAccess<mixed, T>
25+
* @implements IteratorAggregate<T>
26+
* @implements ArrayAccess<mixed, T>
1527
*/
16-
class Collection implements \ArrayAccess, \Countable, \IteratorAggregate
28+
class Collection implements ArrayAccess, Countable, IteratorAggregate
1729
{
1830
/**
1931
* @param T[] $items
@@ -249,7 +261,7 @@ public function add(mixed $item): static
249261
public function filter(callable $callback): static
250262
{
251263
return new static(
252-
\array_values(\array_filter($this->items, $callback)),
264+
array_values(array_filter($this->items, $callback)),
253265
$this->itemType,
254266
);
255267
}
@@ -267,15 +279,15 @@ public function filter(callable $callback): static
267279
*/
268280
public function map(callable $callback, bool $inferTypes = true): static
269281
{
270-
$mapResult = \array_map($callback, $this->items);
271-
$firstItem = \reset($mapResult);
282+
$mapResult = array_map($callback, $this->items);
283+
$firstItem = reset($mapResult);
272284

273285
if ($firstItem === false || !is_object($firstItem)) {
274286
return new static($mapResult);
275287
}
276288

277289
if ($inferTypes && $this->itemType !== null) {
278-
return new static($mapResult, \get_class($firstItem));
290+
return new static($mapResult, get_class($firstItem));
279291
}
280292

281293
return new static($mapResult);
@@ -291,15 +303,15 @@ public function map(callable $callback, bool $inferTypes = true): static
291303
*/
292304
public function reduce(callable $callback, mixed $initial = null): mixed
293305
{
294-
return \array_reduce($this->items, $callback, $initial);
306+
return array_reduce($this->items, $callback, $initial);
295307
}
296308

297309
/**
298310
* @inheritDoc
299311
*/
300312
public function offsetExists(mixed $offset): bool
301313
{
302-
if (!\is_int($offset)) {
314+
if (!is_int($offset)) {
303315
return false;
304316
}
305317

@@ -345,14 +357,14 @@ public function offsetUnset(mixed $offset): void
345357
*/
346358
public function count(): int
347359
{
348-
return \count($this->items);
360+
return count($this->items);
349361
}
350362

351363
/**
352364
* @inheritDoc
353365
*/
354366
public function getIterator(): Traversable
355367
{
356-
return new \ArrayIterator($this->items);
368+
return new ArrayIterator($this->items);
357369
}
358370
}

0 commit comments

Comments
 (0)