4
4
5
5
namespace GeekCell \Ddd \Domain ;
6
6
7
- use ArrayAccess ;
8
- use ArrayIterator ;
9
7
use Assert ;
10
- use Countable ;
11
- use IteratorAggregate ;
12
- use Traversable ;
13
8
14
- class Collection implements ArrayAccess, Countable, IteratorAggregate
9
+ class Collection implements \ ArrayAccess, \ Countable, \ IteratorAggregate
15
10
{
16
11
/**
17
12
* @template T of object
18
- * @extends IteratorAggregate<T>
13
+ * @extends \ IteratorAggregate<T>
19
14
*
20
15
* @param T[] $items
21
16
* @param class-string<T> $itemType
@@ -63,7 +58,7 @@ public function add(mixed $item): static
63
58
public function filter (callable $ callback ): static
64
59
{
65
60
return new static (
66
- array_filter ($ this ->items , $ callback ),
61
+ \array_values ( \ array_filter ($ this ->items , $ callback) ),
67
62
$ this ->itemType ,
68
63
);
69
64
}
@@ -81,15 +76,15 @@ public function filter(callable $callback): static
81
76
*/
82
77
public function map (callable $ callback , bool $ inferTypes = true ): static
83
78
{
84
- $ mapResult = array_map ($ callback , $ this ->items );
85
- $ firstItem = reset ($ mapResult );
79
+ $ mapResult = \ array_map ($ callback , $ this ->items );
80
+ $ firstItem = \ reset ($ mapResult );
86
81
87
82
if ($ firstItem === false || !is_object ($ firstItem )) {
88
83
return new static ($ mapResult );
89
84
}
90
85
91
86
if ($ inferTypes && $ this ->itemType !== null ) {
92
- return new static ($ mapResult , get_class ($ firstItem ));
87
+ return new static ($ mapResult , \ get_class ($ firstItem ));
93
88
}
94
89
95
90
return new static ($ mapResult );
@@ -105,15 +100,15 @@ public function map(callable $callback, bool $inferTypes = true): static
105
100
*/
106
101
public function reduce (callable $ callback , mixed $ initial = null ): mixed
107
102
{
108
- return array_reduce ($ this ->items , $ callback , $ initial );
103
+ return \ array_reduce ($ this ->items , $ callback , $ initial );
109
104
}
110
105
111
106
/**
112
107
* @inheritDoc
113
108
*/
114
109
public function offsetExists (mixed $ offset ): bool
115
110
{
116
- if (!is_int ($ offset )) {
111
+ if (!\ is_int ($ offset )) {
117
112
return false ;
118
113
}
119
114
@@ -159,14 +154,14 @@ public function offsetUnset(mixed $offset): void
159
154
*/
160
155
public function count (): int
161
156
{
162
- return count ($ this ->items );
157
+ return \ count ($ this ->items );
163
158
}
164
159
165
160
/**
166
161
* @inheritDoc
167
162
*/
168
- public function getIterator (): Traversable
163
+ public function getIterator (): \ Traversable
169
164
{
170
- return new ArrayIterator ($ this ->items );
165
+ return new \ ArrayIterator ($ this ->items );
171
166
}
172
167
}
0 commit comments