@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\Traits; |
14 | 14 | |
15 | -interface EnumerableInterface{ |
|
15 | +interface EnumerableInterface { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * @return array |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * @link http://api.prototypejs.org/language/Enumerable/ |
17 | 17 | */ |
18 | -trait Enumerable{ |
|
18 | +trait Enumerable { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var array |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @return $this |
47 | 47 | */ |
48 | - public function __each(callable $callback){ |
|
48 | + public function __each(callable $callback) { |
|
49 | 49 | $this->__map($callback); |
50 | 50 | |
51 | 51 | return $this; |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function __map($callback):array { |
64 | 64 | |
65 | - if(!is_callable($callback)){ |
|
65 | + if (!is_callable($callback)) { |
|
66 | 66 | throw new TraitException('invalid callback'); |
67 | 67 | } |
68 | 68 | |
69 | 69 | $return = []; |
70 | 70 | |
71 | - foreach($this->array as $index => $element){ |
|
71 | + foreach ($this->array as $index => $element) { |
|
72 | 72 | $return[$index] = call_user_func_array($callback, [$element, $index]); |
73 | 73 | } |
74 | 74 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return $this |
82 | 82 | */ |
83 | - public function __reverse(){ |
|
83 | + public function __reverse() { |
|
84 | 84 | $this->array = array_reverse($this->array); |
85 | 85 | $this->offset = 0; |
86 | 86 | |
@@ -90,14 +90,14 @@ discard block |
||
90 | 90 | /** |
91 | 91 | * @return mixed |
92 | 92 | */ |
93 | - public function __last(){ |
|
93 | + public function __last() { |
|
94 | 94 | return $this->array[count($this->array) - 1]; |
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
98 | 98 | * @return $this |
99 | 99 | */ |
100 | - public function __clear(){ |
|
100 | + public function __clear() { |
|
101 | 101 | $this->array = []; |
102 | 102 | |
103 | 103 | return $this; |
@@ -122,15 +122,15 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function __findAll(callable $callback):array{ |
124 | 124 | |
125 | - if(!is_callable($callback)){ |
|
125 | + if (!is_callable($callback)) { |
|
126 | 126 | throw new TraitException('invalid callback'); |
127 | 127 | } |
128 | 128 | |
129 | 129 | $return = []; |
130 | 130 | |
131 | - foreach($this->array as $index => $element){ |
|
131 | + foreach ($this->array as $index => $element) { |
|
132 | 132 | |
133 | - if(call_user_func_array($callback, [$element, $index]) === true){ |
|
133 | + if (call_user_func_array($callback, [$element, $index]) === true) { |
|
134 | 134 | $return[] = $element; |
135 | 135 | } |
136 | 136 | |
@@ -149,15 +149,15 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function __reject(callable $callback):array{ |
151 | 151 | |
152 | - if(!is_callable($callback)){ |
|
152 | + if (!is_callable($callback)) { |
|
153 | 153 | throw new TraitException('invalid callback'); |
154 | 154 | } |
155 | 155 | |
156 | 156 | $return = []; |
157 | 157 | |
158 | - foreach($this->array as $index => $element){ |
|
158 | + foreach ($this->array as $index => $element) { |
|
159 | 159 | |
160 | - if(call_user_func_array($callback, [$element, $index]) !== true){ |
|
160 | + if (call_user_func_array($callback, [$element, $index]) !== true) { |
|
161 | 161 | $return[] = $element; |
162 | 162 | } |
163 | 163 | |
@@ -173,13 +173,13 @@ discard block |
||
173 | 173 | */ |
174 | 174 | public function __equal(array $y):bool{ |
175 | 175 | |
176 | - if(count($this->array) !== count($y)){ |
|
176 | + if (count($this->array) !== count($y)) { |
|
177 | 177 | return false; |
178 | 178 | } |
179 | 179 | |
180 | 180 | $diff = 0; |
181 | 181 | |
182 | - foreach($this->array as $kx => $vx){ |
|
182 | + foreach ($this->array as $kx => $vx) { |
|
183 | 183 | $diff |= $vx ^ $y[$kx]; |
184 | 184 | } |
185 | 185 |