@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @link http://api.prototypejs.org/language/Enumerable/ |
19 | 19 | */ |
20 | -trait Enumerable{ |
|
20 | +trait Enumerable { |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @var array |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @return $this |
49 | 49 | */ |
50 | - public function __each($callback){ |
|
50 | + public function __each($callback) { |
|
51 | 51 | $this->__map($callback); |
52 | 52 | |
53 | 53 | return $this; |
@@ -64,13 +64,13 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function __map($callback):array { |
66 | 66 | |
67 | - if(!is_callable($callback)){ |
|
67 | + if (!is_callable($callback)) { |
|
68 | 68 | throw new TraitException('invalid callback'); |
69 | 69 | } |
70 | 70 | |
71 | 71 | $return = []; |
72 | 72 | |
73 | - foreach($this->array as $index => $element){ |
|
73 | + foreach ($this->array as $index => $element) { |
|
74 | 74 | $return[$index] = call_user_func_array($callback, [$element, $index]); |
75 | 75 | } |
76 | 76 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @return $this |
84 | 84 | */ |
85 | - public function __reverse(){ |
|
85 | + public function __reverse() { |
|
86 | 86 | $this->array = array_reverse($this->array); |
87 | 87 | $this->offset = 0; |
88 | 88 | |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | /** |
93 | 93 | * @return mixed |
94 | 94 | */ |
95 | - public function __last(){ |
|
95 | + public function __last() { |
|
96 | 96 | return $this->array[count($this->array) - 1]; |
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
100 | 100 | * @return $this |
101 | 101 | */ |
102 | - public function __clear(){ |
|
102 | + public function __clear() { |
|
103 | 103 | $this->array = []; |
104 | 104 | |
105 | 105 | return $this; |
@@ -124,15 +124,15 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function __findAll(Closure $callback):array{ |
126 | 126 | |
127 | - if(!is_callable($callback)){ |
|
127 | + if (!is_callable($callback)) { |
|
128 | 128 | throw new TraitException('invalid callback'); |
129 | 129 | } |
130 | 130 | |
131 | 131 | $return = []; |
132 | 132 | |
133 | - foreach($this->array as $index => $element){ |
|
133 | + foreach ($this->array as $index => $element) { |
|
134 | 134 | |
135 | - if(call_user_func_array($callback, [$element, $index]) === true){ |
|
135 | + if (call_user_func_array($callback, [$element, $index]) === true) { |
|
136 | 136 | $return[] = $element; |
137 | 137 | } |
138 | 138 | |
@@ -151,15 +151,15 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function __reject(Closure $callback):array{ |
153 | 153 | |
154 | - if(!is_callable($callback)){ |
|
154 | + if (!is_callable($callback)) { |
|
155 | 155 | throw new TraitException('invalid callback'); |
156 | 156 | } |
157 | 157 | |
158 | 158 | $return = []; |
159 | 159 | |
160 | - foreach($this->array as $index => $element){ |
|
160 | + foreach ($this->array as $index => $element) { |
|
161 | 161 | |
162 | - if(call_user_func_array($callback, [$element, $index]) !== true){ |
|
162 | + if (call_user_func_array($callback, [$element, $index]) !== true) { |
|
163 | 163 | $return[] = $element; |
164 | 164 | } |
165 | 165 | |
@@ -175,13 +175,13 @@ discard block |
||
175 | 175 | */ |
176 | 176 | public function __equal(array $y):bool{ |
177 | 177 | |
178 | - if(count($this->array) !== count($y)){ |
|
178 | + if (count($this->array) !== count($y)) { |
|
179 | 179 | return false; |
180 | 180 | } |
181 | 181 | |
182 | 182 | $diff = 0; |
183 | 183 | |
184 | - foreach($this->array as $kx => $vx){ |
|
184 | + foreach ($this->array as $kx => $vx) { |
|
185 | 185 | $diff |= $vx ^ $y[$kx]; |
186 | 186 | } |
187 | 187 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @extends \SplFixedArray |
19 | 19 | */ |
20 | -class ByteArray extends SplFixedArray{ |
|
20 | +class ByteArray extends SplFixedArray { |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @return string |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @return string |
31 | 31 | */ |
32 | 32 | public function toHex():string{ |
33 | - return $this->map(function($v){ |
|
33 | + return $this->map(function($v) { |
|
34 | 34 | return str_pad(dechex($v), '2', '0', STR_PAD_LEFT); |
35 | 35 | }); |
36 | 36 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @return string |
54 | 54 | */ |
55 | 55 | public function toBin():string{ |
56 | - return $this->map(function($v){ |
|
56 | + return $this->map(function($v) { |
|
57 | 57 | return str_pad(decbin($v), '8', '0', STR_PAD_LEFT); |
58 | 58 | }); |
59 | 59 | } |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | |
83 | 83 | $diff = $offset + $length; |
84 | 84 | |
85 | - if($diff > $this->count()){ |
|
85 | + if ($diff > $this->count()) { |
|
86 | 86 | $this->setSize($diff); |
87 | 87 | } |
88 | 88 | |
89 | - for($i = 0; $i < $length; $i++){ |
|
89 | + for ($i = 0; $i < $length; $i++) { |
|
90 | 90 | $this[$i + $offset] = $src[$i + $srcOffset]; |
91 | 91 | } |
92 | 92 | |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | |
104 | 104 | // keep an extended class |
105 | 105 | /** @var \chillerlan\Traits\ArrayHelpers\ByteArray $slice */ |
106 | - $slice = (new ReflectionClass($this))->newInstanceArgs([$length ?? ($this->count() - $offset)]); |
|
106 | + $slice = (new ReflectionClass($this))->newInstanceArgs([$length ?? ($this->count() - $offset)]); |
|
107 | 107 | |
108 | - foreach($slice as $i => $_){ |
|
108 | + foreach ($slice as $i => $_) { |
|
109 | 109 | $slice[$i] = $this[$offset + $i]; |
110 | 110 | } |
111 | 111 | |
@@ -119,13 +119,13 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function equal(SplFixedArray $array):bool{ |
121 | 121 | |
122 | - if($this->count() !== $array->count()){ |
|
122 | + if ($this->count() !== $array->count()) { |
|
123 | 123 | return false; |
124 | 124 | } |
125 | 125 | |
126 | 126 | $diff = 0; |
127 | 127 | |
128 | - foreach($this as $k => $v){ |
|
128 | + foreach ($this as $k => $v) { |
|
129 | 129 | $diff |= $v ^ $array[$k]; |
130 | 130 | } |
131 | 131 |