@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | |
24 | 24 | declare(strict_types=1); |
25 | 25 | |
26 | -if (! function_exists('stringContains')) { |
|
26 | +if (!function_exists('stringContains')) { |
|
27 | 27 | /** |
28 | 28 | * Checks if a string contains a sub string |
29 | 29 | * |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
40 | -if (! function_exists('array_flatten')) { |
|
40 | +if (!function_exists('array_flatten')) { |
|
41 | 41 | /** |
42 | 42 | * Flattens an array to desired depth. |
43 | 43 | * doesn't preserve keys |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | { |
51 | 51 | return array_reduce( |
52 | 52 | $array, |
53 | - function (array $carry, $element) use ($n): array { |
|
53 | + function(array $carry, $element) use ($n) : array { |
|
54 | 54 | // Remove empty arrays. |
55 | 55 | if (is_array($element) && empty($element)) { |
56 | 56 | return $carry; |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
72 | -if (! function_exists('toObject')) { |
|
72 | +if (!function_exists('toObject')) { |
|
73 | 73 | /** |
74 | 74 | * Simple mapper for turning arrays into stdClass objects. |
75 | 75 | * |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
90 | -if (! function_exists('invokeCallable')) { |
|
90 | +if (!function_exists('invokeCallable')) { |
|
91 | 91 | /** |
92 | 92 | * Used to invoke a callable. |
93 | 93 | * |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
104 | -if (! function_exists('isArrayAccess')) { |
|
104 | +if (!function_exists('isArrayAccess')) { |
|
105 | 105 | /** |
106 | 106 | * Checks if an array or an object which has array like access. |
107 | 107 | * |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | * @param mixed $b The values to compare with |
46 | 46 | * @return bool |
47 | 47 | */ |
48 | - return function ($b) use ($a): bool { |
|
49 | - if (! sameScalar($b, $a)) { |
|
48 | + return function($b) use ($a): bool { |
|
49 | + if (!sameScalar($b, $a)) { |
|
50 | 50 | return false; |
51 | 51 | } |
52 | 52 | |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | * @param mixed $b The values to compare with |
84 | 84 | * @return bool |
85 | 85 | */ |
86 | - return function ($b) use ($a): bool { |
|
87 | - return ! isEqualTo($a)($b); |
|
86 | + return function($b) use ($a): bool { |
|
87 | + return !isEqualTo($a)($b); |
|
88 | 88 | }; |
89 | 89 | } |
90 | 90 | |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | * @param Number $b |
102 | 102 | * @return bool |
103 | 103 | */ |
104 | - return function ($b) use ($a): bool { |
|
105 | - return isEqualIn(array( 'integer', 'double' ))(gettype($b)) |
|
104 | + return function($b) use ($a): bool { |
|
105 | + return isEqualIn(array('integer', 'double'))(gettype($b)) |
|
106 | 106 | ? $a < $b : false; |
107 | 107 | }; |
108 | 108 | } |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * @param mixed $b |
121 | 121 | * @return bool |
122 | 122 | */ |
123 | - return function ($b) use ($a): bool { |
|
124 | - return isEqualIn(array( 'integer', 'double' ))(gettype($b)) |
|
123 | + return function($b) use ($a): bool { |
|
124 | + return isEqualIn(array('integer', 'double'))(gettype($b)) |
|
125 | 125 | ? $a > $b : false; |
126 | 126 | }; |
127 | 127 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * @param Number $b The base value to compare with must be int or float. |
140 | 140 | * @return bool |
141 | 141 | */ |
142 | - return function ($b) use ($a): bool { |
|
142 | + return function($b) use ($a): bool { |
|
143 | 143 | return any(isEqualTo($a), isLessThan($a))($b); |
144 | 144 | }; |
145 | 145 | } |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @param Number $b |
158 | 158 | * @return bool |
159 | 159 | */ |
160 | - return function ($b) use ($a): bool { |
|
160 | + return function($b) use ($a): bool { |
|
161 | 161 | return any(isEqualTo($a), isGreaterThan($a))($b); |
162 | 162 | }; |
163 | 163 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * @param mixed[] $b The array of values which it could be |
175 | 175 | * @return bool |
176 | 176 | */ |
177 | - return function ($b) use ($a): ?bool { |
|
177 | + return function($b) use ($a): ?bool { |
|
178 | 178 | if ( |
179 | 179 | is_numeric($b) || is_bool($b) || |
180 | 180 | is_string($b) || is_array($b) |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | return in_array( |
185 | 185 | (array) $b, |
186 | 186 | array_map( |
187 | - function ($e): array { |
|
187 | + function($e): array { |
|
188 | 188 | return (array) $e; |
189 | 189 | }, |
190 | 190 | $a |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | */ |
207 | 207 | function notEmpty($value): bool |
208 | 208 | { |
209 | - return ! empty($value); |
|
209 | + return !empty($value); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -221,10 +221,10 @@ discard block |
||
221 | 221 | * @param mixed $value |
222 | 222 | * @return bool |
223 | 223 | */ |
224 | - return function ($value) use ($callables): bool { |
|
224 | + return function($value) use ($callables): bool { |
|
225 | 225 | return (bool) array_reduce( |
226 | 226 | $callables, |
227 | - function ($result, $callable) use ($value) { |
|
227 | + function($result, $callable) use ($value) { |
|
228 | 228 | return (is_bool($result) && $result === false) ? false : $callable($value); |
229 | 229 | }, |
230 | 230 | null |
@@ -244,10 +244,10 @@ discard block |
||
244 | 244 | * @param mixed $value |
245 | 245 | * @return bool |
246 | 246 | */ |
247 | - return function ($value) use ($callables): bool { |
|
247 | + return function($value) use ($callables): bool { |
|
248 | 248 | return (bool) array_reduce( |
249 | 249 | $callables, |
250 | - function ($result, $callable) use ($value) { |
|
250 | + function($result, $callable) use ($value) { |
|
251 | 251 | return (is_bool($result) && $result === true) ? true : $callable($value); |
252 | 252 | }, |
253 | 253 | null |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | * @param mixed $value |
268 | 268 | * @return bool |
269 | 269 | */ |
270 | - return function ($value) use ($source) { |
|
270 | + return function($value) use ($source) { |
|
271 | 271 | return gettype($value) === $source; |
272 | 272 | }; |
273 | 273 | } |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | function allTrue(bool ...$variables): bool |
299 | 299 | { |
300 | 300 | foreach ($variables as $value) { |
301 | - if (! is_bool($value) || $value !== true) { |
|
301 | + if (!is_bool($value) || $value !== true) { |
|
302 | 302 | return false; |
303 | 303 | } |
304 | 304 | } |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | * @param mixed $value |
389 | 389 | * @return bool |
390 | 390 | */ |
391 | - return function ($value) use ($callable): bool { |
|
392 | - return ! (bool) $callable($value); |
|
391 | + return function($value) use ($callable): bool { |
|
392 | + return !(bool) $callable($value); |
|
393 | 393 | }; |
394 | 394 | } |
@@ -264,7 +264,7 @@ |
||
264 | 264 | * Only works for public or dynamic properties. |
265 | 265 | * |
266 | 266 | * @param array<string,mixed>|ArrayObject<string,mixed>|object $store |
267 | - * @param string $property The property key. |
|
267 | + * @param string $property The property key. |
|
268 | 268 | * @return Closure(mixed):(array<string,mixed>|ArrayObject<string,mixed>|object) |
269 | 269 | */ |
270 | 270 | function setProperty($store, string $property): Closure |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @param mixed The value passed into the functions |
50 | 50 | * @return mixed The final result. |
51 | 51 | */ |
52 | - return function ($e) use ($callables) { |
|
52 | + return function($e) use ($callables) { |
|
53 | 53 | foreach ($callables as $callable) { |
54 | 54 | $e = $callable($e); |
55 | 55 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @param mixed The value passed into the functions |
71 | 71 | * @return mixed The final result. |
72 | 72 | */ |
73 | - return function ($e) use ($callables) { |
|
73 | + return function($e) use ($callables) { |
|
74 | 74 | foreach (\array_reverse($callables) as $callable) { |
75 | 75 | $e = $callable($e); |
76 | 76 | } |
@@ -91,9 +91,9 @@ discard block |
||
91 | 91 | * @param mixed The value passed into the functions |
92 | 92 | * @return mixed|null The final result or null. |
93 | 93 | */ |
94 | - return function ($e) use ($callables) { |
|
94 | + return function($e) use ($callables) { |
|
95 | 95 | foreach ($callables as $callable) { |
96 | - if (! is_null($e)) { |
|
96 | + if (!is_null($e)) { |
|
97 | 97 | $e = $callable($e); |
98 | 98 | } |
99 | 99 | } |
@@ -116,17 +116,17 @@ discard block |
||
116 | 116 | * @param mixed $e The value being passed through the functions. |
117 | 117 | * @return mixed The final result. |
118 | 118 | */ |
119 | - return function ($e) use ($validator, $callables) { |
|
119 | + return function($e) use ($validator, $callables) { |
|
120 | 120 | foreach ($callables as $callable) { |
121 | 121 | // If invalid, abort and return null |
122 | - if (! $validator($e)) { |
|
122 | + if (!$validator($e)) { |
|
123 | 123 | return null; |
124 | 124 | } |
125 | 125 | // Run through callable. |
126 | 126 | $e = $callable($e); |
127 | 127 | |
128 | 128 | // Check results and bail if invalid type. |
129 | - if (! $validator($e)) { |
|
129 | + if (!$validator($e)) { |
|
130 | 130 | return null; |
131 | 131 | } |
132 | 132 | } |
@@ -172,9 +172,9 @@ discard block |
||
172 | 172 | * @param mixed $data The array or object to attempt to get param. |
173 | 173 | * @return mixed|null |
174 | 174 | */ |
175 | - return function ($data) use ($property) { |
|
175 | + return function($data) use ($property) { |
|
176 | 176 | if (is_array($data)) { |
177 | - return array_key_exists($property, $data) ? $data[ $property ] : null; |
|
177 | + return array_key_exists($property, $data) ? $data[$property] : null; |
|
178 | 178 | } elseif (is_object($data)) { |
179 | 179 | return property_exists($data, $property) ? $data->{$property} : null; |
180 | 180 | } else { |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | * @param mixed[]|object $data The array or object to attempt to get param. |
198 | 198 | * @return mixed|null |
199 | 199 | */ |
200 | - return function ($data) use ($nodes) { |
|
200 | + return function($data) use ($nodes) { |
|
201 | 201 | foreach ($nodes as $node) { |
202 | 202 | $data = getProperty($node)($data); |
203 | 203 | |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | * @param mixed $data The array or object to attempt to get param. |
223 | 223 | * @return mixed|null |
224 | 224 | */ |
225 | - return function ($data) use ($property): bool { |
|
225 | + return function($data) use ($property): bool { |
|
226 | 226 | if (is_array($data)) { |
227 | 227 | return array_key_exists($property, $data); |
228 | 228 | } elseif (is_object($data)) { |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | * @param mixed $data The array or object to attempt to get param. |
248 | 248 | * @return bool |
249 | 249 | */ |
250 | - return function ($data) use ($property, $value): bool { |
|
250 | + return function($data) use ($property, $value): bool { |
|
251 | 251 | return pipe( |
252 | 252 | $data, |
253 | 253 | getProperty($property), |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | { |
273 | 273 | |
274 | 274 | // If passed store is not an array or object, throw exception. |
275 | - if (! isArrayAccess($store) && ! is_object($store)) { |
|
275 | + if (!isArrayAccess($store) && !is_object($store)) { |
|
276 | 276 | throw new TypeError('Only objects or arrays can be constructed using setProperty.'); |
277 | 277 | } |
278 | 278 | |
@@ -280,10 +280,10 @@ discard block |
||
280 | 280 | * @param mixed $value The value to set to keu. |
281 | 281 | * @return array<string,mixed>|ArrayObject<string,mixed>|object The datastore. |
282 | 282 | */ |
283 | - return function ($value) use ($store, $property) { |
|
283 | + return function($value) use ($store, $property) { |
|
284 | 284 | if (isArrayAccess($store)) { |
285 | 285 | /** @phpstan-ignore-next-line */ |
286 | - $store[ $property ] = $value; |
|
286 | + $store[$property] = $value; |
|
287 | 287 | } else { |
288 | 288 | $store->{$property} = $value; |
289 | 289 | } |
@@ -306,8 +306,8 @@ discard block |
||
306 | 306 | * @param mixed $data The data to pass through the callable |
307 | 307 | * @return array |
308 | 308 | */ |
309 | - return function ($data) use ($key, $value): array { |
|
310 | - return array( $key => $value($data) ); |
|
309 | + return function($data) use ($key, $value): array { |
|
310 | + return array($key => $value($data)); |
|
311 | 311 | }; |
312 | 312 | } |
313 | 313 | |
@@ -324,12 +324,12 @@ discard block |
||
324 | 324 | * @param callable(mixed):mixed ...$encoders encodeProperty() functions. |
325 | 325 | * @return Closure |
326 | 326 | */ |
327 | - return function (...$encoders) use ($dataType): Closure { |
|
327 | + return function(...$encoders) use ($dataType): Closure { |
|
328 | 328 | /** |
329 | 329 | * @param mixed $data The data to pass through the encoders. |
330 | 330 | * @return array<string,mixed>|object The encoded object/array. |
331 | 331 | */ |
332 | - return function ($data) use ($dataType, $encoders) { |
|
332 | + return function($data) use ($dataType, $encoders) { |
|
333 | 333 | foreach ($encoders as $encoder) { |
334 | 334 | $key = array_keys($encoder($data))[0]; |
335 | 335 | // throw exception if key is int |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | * @param mixed ...$args |
357 | 357 | * @return mixed |
358 | 358 | */ |
359 | - return function (...$args) use ($fn) { |
|
359 | + return function(...$args) use ($fn) { |
|
360 | 360 | return $fn(...$args); |
361 | 361 | }; |
362 | 362 | } |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | * @param mixed $ignored Any values can be passed and ignored. |
374 | 374 | * @return mixed |
375 | 375 | */ |
376 | - return function (...$ignored) use ($value) { |
|
376 | + return function(...$ignored) use ($value) { |
|
377 | 377 | return $value; |
378 | 378 | }; |
379 | 379 | } |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | * @param mixed $value |
409 | 409 | * @return mixed |
410 | 410 | */ |
411 | - return function ($value) use ($condition, $then) { |
|
411 | + return function($value) use ($condition, $then) { |
|
412 | 412 | return true === (bool) $condition($value) |
413 | 413 | ? $then($value) |
414 | 414 | : $value; |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | * @param mixed $value |
432 | 432 | * @return mixed |
433 | 433 | */ |
434 | - return function ($value) use ($condition, $then, $else) { |
|
434 | + return function($value) use ($condition, $then, $else) { |
|
435 | 435 | return true === (bool) $condition($value) |
436 | 436 | ? $then($value) |
437 | 437 | : $else($value); |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @param string $string |
49 | 49 | * @return string |
50 | 50 | */ |
51 | - return function (string $string) use ($opening, $closing): string { |
|
51 | + return function(string $string) use ($opening, $closing) : string { |
|
52 | 52 | return \sprintf('%s%s%s', $opening, $string, $closing ?? $opening); |
53 | 53 | }; |
54 | 54 | } |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | * @param string $string |
69 | 69 | * @return string |
70 | 70 | */ |
71 | - return function (string $string) use ($start, $finish): string { |
|
72 | - return ! $finish |
|
71 | + return function(string $string) use ($start, $finish) : string { |
|
72 | + return !$finish |
|
73 | 73 | ? substr($string, $start) |
74 | 74 | : substr($string, $start, $finish); |
75 | 75 | }; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @param string $string |
88 | 88 | * @return string |
89 | 89 | */ |
90 | - return function (string $string) use ($prepend): string { |
|
90 | + return function(string $string) use ($prepend): string { |
|
91 | 91 | return \sprintf('%s%s', $prepend, $string); |
92 | 92 | }; |
93 | 93 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @param string $string |
105 | 105 | * @return string |
106 | 106 | */ |
107 | - return function (string $string) use ($append): string { |
|
107 | + return function(string $string) use ($append): string { |
|
108 | 108 | return \sprintf('%s%s', $string, $append); |
109 | 109 | }; |
110 | 110 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * @param array<string, mixed> $values |
122 | 122 | * @return string Will return original string if false. |
123 | 123 | */ |
124 | - return function (array $values = array()) use ($template): string { |
|
124 | + return function(array $values = array()) use ($template): string { |
|
125 | 125 | return \vsprintf($template, $values); |
126 | 126 | }; |
127 | 127 | } |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | * @param string $replace value to replace with |
139 | 139 | * @return Closure(string):string |
140 | 140 | */ |
141 | - return function (string $replace) use ($find): Closure { |
|
141 | + return function(string $replace) use ($find): Closure { |
|
142 | 142 | /** |
143 | 143 | * @param string $subject String to carry out find and replace. |
144 | 144 | * @return string |
145 | 145 | */ |
146 | - return function ($subject) use ($find, $replace): string { |
|
146 | + return function($subject) use ($find, $replace): string { |
|
147 | 147 | return \str_replace($find, $replace, $subject); |
148 | 148 | }; |
149 | 149 | }; |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @param string $source |
163 | 163 | * @return string |
164 | 164 | */ |
165 | - return function ($source) use ($find, $replace): string { |
|
165 | + return function($source) use ($find, $replace): string { |
|
166 | 166 | return \str_replace($find, $replace, $source); |
167 | 167 | }; |
168 | 168 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * @param string $string |
182 | 182 | * @return string |
183 | 183 | */ |
184 | - return function (string $string) use ($replace, $offset, $length): string { |
|
184 | + return function(string $string) use ($replace, $offset, $length) : string { |
|
185 | 185 | return $length |
186 | 186 | ? \substr_replace($string, $replace, $offset, $length) |
187 | 187 | : \substr_replace($string, $replace, $offset); |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * @param string $source |
201 | 201 | * @return bool |
202 | 202 | */ |
203 | - return function (string $source) use ($find): bool { |
|
203 | + return function(string $source) use ($find): bool { |
|
204 | 204 | return (\substr($source, 0, \strlen($find)) === $find); |
205 | 205 | }; |
206 | 206 | } |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @param string $source |
218 | 218 | * @return bool |
219 | 219 | */ |
220 | - return function (string $source) use ($find): bool { |
|
220 | + return function(string $source) use ($find): bool { |
|
221 | 221 | if (\strlen($find) === 0) { |
222 | 222 | return true; |
223 | 223 | } |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | * @param string $haystack String to look in. |
238 | 238 | * @return bool |
239 | 239 | */ |
240 | - return function (string $haystack) use ($needle): bool { |
|
240 | + return function(string $haystack) use ($needle): bool { |
|
241 | 241 | return \stringContains($haystack, $needle); |
242 | 242 | }; |
243 | 243 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | * @param string $source String to look in. |
255 | 255 | * @return bool |
256 | 256 | */ |
257 | - return function (string $source) use ($pattern): bool { |
|
257 | + return function(string $source) use ($pattern): bool { |
|
258 | 258 | return (bool) \preg_match($pattern, $source); |
259 | 259 | }; |
260 | 260 | } |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | * @param string $name |
272 | 272 | * @return string[] |
273 | 273 | */ |
274 | - return function (string $string) use ($pattern): ?array { |
|
274 | + return function(string $string) use ($pattern): ?array { |
|
275 | 275 | return \preg_split($pattern, $string) ?: null; |
276 | 276 | }; |
277 | 277 | } |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * @param string|int|float $number |
291 | 291 | * @return string |
292 | 292 | */ |
293 | - return function ($number) use ($precision, $point, $thousands): string { |
|
293 | + return function($number) use ($precision, $point, $thousands): string { |
|
294 | 294 | return \is_numeric($number) |
295 | 295 | ? \number_format((float) $number, (int) $precision, $point, $thousands) |
296 | 296 | : ''; |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | * @param string $string The string to have char, slash escaped. |
312 | 312 | * @return string |
313 | 313 | */ |
314 | - return function (string $string) use ($charList): string { |
|
314 | + return function(string $string) use ($charList): string { |
|
315 | 315 | return \addcslashes($string, $charList); |
316 | 316 | }; |
317 | 317 | } |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | * @param string $string The string to be split |
330 | 330 | * @return array<int, string> |
331 | 331 | */ |
332 | - return function (string $string) use ($separator, $limit): array { |
|
332 | + return function(string $string) use ($separator, $limit): array { |
|
333 | 333 | $chunks = explode($separator, $string, $limit); |
334 | 334 | return is_array($chunks) ? $chunks : []; // @phpstan-ignore-line, inconsistent errors with differing php versions. |
335 | 335 | }; |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | * @param string $string The string to be split |
348 | 348 | * @return array<int, string> |
349 | 349 | */ |
350 | - return function (string $string) use ($length): array { |
|
350 | + return function(string $string) use ($length): array { |
|
351 | 351 | return \str_split($string, max(1, $length)) ?: array(); // @phpstan-ignore-line, inconsistent errors with differing php versions. |
352 | 352 | }; |
353 | 353 | } |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | * @param string $string The string to be chunked |
367 | 367 | * @return string |
368 | 368 | */ |
369 | - return function (string $string) use ($length, $end): string { |
|
369 | + return function(string $string) use ($length, $end): string { |
|
370 | 370 | return \chunk_split($string, max(1, $length), $end); |
371 | 371 | }; |
372 | 372 | } |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | * @param string $string The string to be wrapped |
386 | 386 | * @return string |
387 | 387 | */ |
388 | - return function (string $string) use ($width, $break, $cut): string { |
|
388 | + return function(string $string) use ($width, $break, $cut): string { |
|
389 | 389 | return \wordwrap($string, $width, $break, $cut); |
390 | 390 | }; |
391 | 391 | } |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | function countChars(int $mode = 1): Closure |
401 | 401 | { |
402 | 402 | // Throw an exception if the mode is not supported. |
403 | - if (! in_array($mode, array( 0, 1, 2, 3, 4 ), true)) { |
|
403 | + if (!in_array($mode, array(0, 1, 2, 3, 4), true)) { |
|
404 | 404 | throw new \InvalidArgumentException('Invalid mode'); |
405 | 405 | } |
406 | 406 | |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | * @param string $string The string to have its char counted. |
409 | 409 | * @return int[]|string |
410 | 410 | */ |
411 | - return function (string $string) use ($mode) { |
|
411 | + return function(string $string) use ($mode) { |
|
412 | 412 | return \count_chars($string, $mode); |
413 | 413 | }; |
414 | 414 | } |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | * @param string $haystack |
428 | 428 | * @return int |
429 | 429 | */ |
430 | - return function (string $haystack) use ($needle, $offset, $length): int { |
|
430 | + return function(string $haystack) use ($needle, $offset, $length) : int { |
|
431 | 431 | return $length |
432 | 432 | ? \substr_count($haystack, $needle, $offset, $length) |
433 | 433 | : \substr_count($haystack, $needle, $offset); |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | * @param string $string The string to be trimmed |
447 | 447 | * @return string |
448 | 448 | */ |
449 | - return function (string $string) use ($mask): string { |
|
449 | + return function(string $string) use ($mask): string { |
|
450 | 450 | return \trim($string, $mask); |
451 | 451 | }; |
452 | 452 | } |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | * @param string $string The string to be trimmed |
464 | 464 | * @return string |
465 | 465 | */ |
466 | - return function (string $string) use ($mask): string { |
|
466 | + return function(string $string) use ($mask): string { |
|
467 | 467 | return \ltrim($string, $mask); |
468 | 468 | }; |
469 | 469 | } |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | * @param string $string The string to be trimmed |
481 | 481 | * @return string |
482 | 482 | */ |
483 | - return function (string $string) use ($mask): string { |
|
483 | + return function(string $string) use ($mask): string { |
|
484 | 484 | return \rtrim($string, $mask); |
485 | 485 | }; |
486 | 486 | } |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | * @param string $comparisonString The string to compare against base. |
500 | 500 | * @return Number |
501 | 501 | */ |
502 | - return function (string $comparisonString) use ($base, $asPc) { |
|
502 | + return function(string $comparisonString) use ($base, $asPc) { |
|
503 | 503 | $pc = 0.00; |
504 | 504 | $matching = similar_text($base, $comparisonString, $pc); |
505 | 505 | return $asPc ? $pc : $matching; |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | * @param string $comparisonString The string to act as the base. |
521 | 521 | * @return Number |
522 | 522 | */ |
523 | - return function (string $base) use ($comparisonString, $asPc) { |
|
523 | + return function(string $base) use ($comparisonString, $asPc) { |
|
524 | 524 | $pc = 0.00; |
525 | 525 | $matching = similar_text($base, $comparisonString, $pc); |
526 | 526 | return $asPc ? $pc : $matching; |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | * @param string $string The string to pad out. |
542 | 542 | * @return string |
543 | 543 | */ |
544 | - return function (string $string) use ($length, $padContent, $type): string { |
|
544 | + return function(string $string) use ($length, $padContent, $type): string { |
|
545 | 545 | return \str_pad($string, $length, $padContent, $type); |
546 | 546 | }; |
547 | 547 | } |
@@ -558,7 +558,7 @@ discard block |
||
558 | 558 | * @param string $string The string to repeat |
559 | 559 | * @return string |
560 | 560 | */ |
561 | - return function (string $string) use ($count): string { |
|
561 | + return function(string $string) use ($count): string { |
|
562 | 562 | return \str_repeat($string, $count); |
563 | 563 | }; |
564 | 564 | } |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | * @param string $string The string to pad out. |
577 | 577 | * @return int|string[] |
578 | 578 | */ |
579 | - return function (string $string) use ($format, $charList) { |
|
579 | + return function(string $string) use ($format, $charList) { |
|
580 | 580 | return $charList |
581 | 581 | ? (\str_word_count($string, $format, $charList) ?: 0) |
582 | 582 | : (\str_word_count($string, $format) ?: 0); |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | * @param string $string The string to strip tags from. |
596 | 596 | * @return string |
597 | 597 | */ |
598 | - return function (string $string) use ($allowedTags): string { |
|
598 | + return function(string $string) use ($allowedTags) : string { |
|
599 | 599 | return $allowedTags |
600 | 600 | ? \strip_tags($string, $allowedTags) |
601 | 601 | : \strip_tags($string); |
@@ -612,13 +612,13 @@ discard block |
||
612 | 612 | */ |
613 | 613 | function firstPosition(string $needle, int $offset = 0, int $flags = STRINGS_CASE_SENSITIVE): Closure |
614 | 614 | { |
615 | - $caseSensitive = ! (bool) ($flags & STRINGS_CASE_INSENSITIVE); // Assumes true unless INSESNITVE passed |
|
615 | + $caseSensitive = !(bool) ($flags & STRINGS_CASE_INSENSITIVE); // Assumes true unless INSESNITVE passed |
|
616 | 616 | |
617 | 617 | /** |
618 | 618 | * @param string $haystack The haystack to look through. |
619 | 619 | * @return int|null |
620 | 620 | */ |
621 | - return function (string $haystack) use ($needle, $offset, $caseSensitive): ?int { |
|
621 | + return function(string $haystack) use ($needle, $offset, $caseSensitive): ?int { |
|
622 | 622 | $pos = $caseSensitive |
623 | 623 | ? strpos($haystack, $needle, $offset) |
624 | 624 | : stripos($haystack, $needle, $offset); |
@@ -636,13 +636,13 @@ discard block |
||
636 | 636 | */ |
637 | 637 | function lastPosition(string $needle, int $offset = 0, int $flags = STRINGS_CASE_SENSITIVE): Closure |
638 | 638 | { |
639 | - $caseSensitive = ! (bool) ($flags & STRINGS_CASE_INSENSITIVE); // Assumes true unless INSESNITVE passed |
|
639 | + $caseSensitive = !(bool) ($flags & STRINGS_CASE_INSENSITIVE); // Assumes true unless INSESNITVE passed |
|
640 | 640 | |
641 | 641 | /** |
642 | 642 | * @param string $haystack The haystack to look through. |
643 | 643 | * @return int|null |
644 | 644 | */ |
645 | - return function (string $haystack) use ($needle, $offset, $caseSensitive): ?int { |
|
645 | + return function(string $haystack) use ($needle, $offset, $caseSensitive): ?int { |
|
646 | 646 | $pos = $caseSensitive |
647 | 647 | ? strrpos($haystack, $needle, $offset) |
648 | 648 | : strripos($haystack, $needle, $offset); |
@@ -664,13 +664,13 @@ discard block |
||
664 | 664 | |
665 | 665 | // Decode flags, only look for none defaults. |
666 | 666 | $beforeNeedle = (bool) ($flags & STRINGS_BEFORE_NEEDLE); |
667 | - $caseSensitive = ! (bool) ($flags & STRINGS_CASE_INSENSITIVE); // Assumes true unless INSESNITVE passed |
|
667 | + $caseSensitive = !(bool) ($flags & STRINGS_CASE_INSENSITIVE); // Assumes true unless INSESNITVE passed |
|
668 | 668 | |
669 | 669 | /** |
670 | 670 | * @param string $haystack The haystack to look through. |
671 | 671 | * @return string |
672 | 672 | */ |
673 | - return function (string $haystack) use ($needle, $beforeNeedle, $caseSensitive): string { |
|
673 | + return function(string $haystack) use ($needle, $beforeNeedle, $caseSensitive): string { |
|
674 | 674 | $result = $caseSensitive |
675 | 675 | ? strstr($haystack, $needle, $beforeNeedle) |
676 | 676 | : stristr($haystack, $needle, $beforeNeedle); |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | * @param string $haystack |
692 | 692 | * @return string |
693 | 693 | */ |
694 | - return function (string $haystack) use ($chars): string { |
|
694 | + return function(string $haystack) use ($chars): string { |
|
695 | 695 | $result = strpbrk($haystack, $chars); |
696 | 696 | return is_string($result) ? $result : ''; |
697 | 697 | }; |
@@ -710,7 +710,7 @@ discard block |
||
710 | 710 | * @param string $haystack |
711 | 711 | * @return string |
712 | 712 | */ |
713 | - return function (string $haystack) use ($char): string { |
|
713 | + return function(string $haystack) use ($char): string { |
|
714 | 714 | $result = strrchr($haystack, $char); |
715 | 715 | return is_string($result) ? $result : ''; |
716 | 716 | }; |
@@ -729,7 +729,7 @@ discard block |
||
729 | 729 | * @param string $haystack |
730 | 730 | * @return string |
731 | 731 | */ |
732 | - return function (string $haystack) use ($dictionary): string { |
|
732 | + return function(string $haystack) use ($dictionary): string { |
|
733 | 733 | $result = strtr($haystack, $dictionary); |
734 | 734 | return $result; |
735 | 735 | }; |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | * @param string|null $value |
760 | 760 | * @return Closure|string |
761 | 761 | */ |
762 | - return function (?string $value = null) use ($initial) { |
|
762 | + return function(?string $value = null) use ($initial) { |
|
763 | 763 | if ($value) { |
764 | 764 | $initial .= $value; |
765 | 765 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | if (is_object($class)) { |
53 | 53 | $class = get_class($class); |
54 | 54 | } |
55 | - if (! class_exists($class)) { |
|
55 | + if (!class_exists($class)) { |
|
56 | 56 | throw new InvalidArgumentException(__FUNCTION__ . 'only accepts a Class or Class Name'); |
57 | 57 | } |
58 | 58 | |
@@ -60,11 +60,11 @@ discard block |
||
60 | 60 | * @param Class $value |
61 | 61 | * @return bool |
62 | 62 | */ |
63 | - return function ($value) use ($class): bool { |
|
63 | + return function($value) use ($class): bool { |
|
64 | 64 | if (is_object($value)) { |
65 | 65 | $value = get_class($value); |
66 | 66 | } |
67 | - if (! class_exists($value)) { |
|
67 | + if (!class_exists($value)) { |
|
68 | 68 | throw new InvalidArgumentException(__FUNCTION__ . 'only accepts a Class or Class Name'); |
69 | 69 | } |
70 | 70 | return is_a($value, $class, true); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @param Class $class |
85 | 85 | * @return bool |
86 | 86 | */ |
87 | - return function ($class) use ($interface): bool { |
|
87 | + return function($class) use ($interface): bool { |
|
88 | 88 | return in_array( |
89 | 89 | $interface, |
90 | 90 | class_implements($class, false) ?: array(), |
@@ -105,18 +105,18 @@ discard block |
||
105 | 105 | * @param object $object |
106 | 106 | * @return array<string, mixed> |
107 | 107 | */ |
108 | - return function ($object): array { |
|
108 | + return function($object): array { |
|
109 | 109 | |
110 | 110 | // If not object, return empty array. |
111 | - if (! is_object($object)) { |
|
111 | + if (!is_object($object)) { |
|
112 | 112 | return array(); |
113 | 113 | } |
114 | 114 | |
115 | 115 | $objectVars = get_object_vars($object); |
116 | 116 | return array_reduce( |
117 | 117 | array_keys($objectVars), |
118 | - function (array $array, $key) use ($objectVars): array { |
|
119 | - $array[ ltrim((string) $key, '_') ] = $objectVars[ $key ]; |
|
118 | + function(array $array, $key) use ($objectVars): array { |
|
119 | + $array[ltrim((string) $key, '_')] = $objectVars[$key]; |
|
120 | 120 | return $array; |
121 | 121 | }, |
122 | 122 | array() |
@@ -138,9 +138,9 @@ discard block |
||
138 | 138 | * @param object|class-string $object |
139 | 139 | * @return bool |
140 | 140 | */ |
141 | - return function ($object) use ($trait, $autoload): bool { |
|
141 | + return function($object) use ($trait, $autoload): bool { |
|
142 | 142 | // Throw type error if not object or class-string. |
143 | - if (! is_object($object) && ! class_exists($object, false)) { |
|
143 | + if (!is_object($object) && !class_exists($object, false)) { |
|
144 | 144 | throw new InvalidArgumentException(__FUNCTION__ . ' only accepts an object or class-string'); |
145 | 145 | } |
146 | 146 | |
@@ -168,10 +168,10 @@ discard block |
||
168 | 168 | $constructorArgs = $constructor->getConstructor() ? $constructor->getConstructor()->getParameters() : array(); |
169 | 169 | $constructorArgs = array_reduce( |
170 | 170 | $constructorArgs, |
171 | - function (array $args, \ReflectionParameter $param) use ($baseProperties): array { |
|
171 | + function(array $args, \ReflectionParameter $param) use ($baseProperties): array { |
|
172 | 172 | // If the param exists in base properties use that, else use the default value or null. |
173 | - $args[ $param->getName() ] = \array_key_exists($param->getName(), $baseProperties) |
|
174 | - ? $baseProperties[ $param->getName() ] |
|
173 | + $args[$param->getName()] = \array_key_exists($param->getName(), $baseProperties) |
|
174 | + ? $baseProperties[$param->getName()] |
|
175 | 175 | : ($param->isDefaultValueAvailable() |
176 | 176 | ? $param->getDefaultValue() |
177 | 177 | : null); |
@@ -185,14 +185,14 @@ discard block |
||
185 | 185 | * @param array<string, mixed> $properties |
186 | 186 | * @return Class |
187 | 187 | */ |
188 | - return function (array $properties = array()) use ($class, $constructorArgs) { |
|
188 | + return function(array $properties = array()) use ($class, $constructorArgs) { |
|
189 | 189 | // Loop through constructorArgs and replace with any passed properties. |
190 | 190 | $constructorArgs = array_reduce( |
191 | 191 | array_keys($constructorArgs), |
192 | - function (array $args, string $key) use ($constructorArgs, $properties): array { |
|
192 | + function(array $args, string $key) use ($constructorArgs, $properties): array { |
|
193 | 193 | $args[] = \array_key_exists($key, $properties) |
194 | - ? $properties[ $key ] |
|
195 | - : $constructorArgs[ $key ]; |
|
194 | + ? $properties[$key] |
|
195 | + : $constructorArgs[$key]; |
|
196 | 196 | return $args; |
197 | 197 | }, |
198 | 198 | array() |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @param int|null $value |
47 | 47 | * @return Closure(int|null):(Closure|int)|int |
48 | 48 | */ |
49 | - return function (?int $value = null) use ($initial) { |
|
49 | + return function(?int $value = null) use ($initial) { |
|
50 | 50 | if (null !== $value) { |
51 | 51 | $initial += $value; |
52 | 52 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @param float|null $value |
67 | 67 | * @return Closure(float|null):(Closure|float)|float |
68 | 68 | */ |
69 | - return function (?float $value = null) use ($initial) { |
|
69 | + return function(?float $value = null) use ($initial) { |
|
70 | 70 | if (null !== $value) { |
71 | 71 | $initial += $value; |
72 | 72 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | */ |
84 | 84 | function sum($initial = 0): Closure |
85 | 85 | { |
86 | - if (! C\isNumber($initial)) { |
|
86 | + if (!C\isNumber($initial)) { |
|
87 | 87 | throw new InvalidArgumentException(__FUNCTION__ . 'only accepts a Number (Float or Int)'); |
88 | 88 | } |
89 | 89 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @param Number $value |
92 | 92 | * @return int|float |
93 | 93 | */ |
94 | - return function ($value) use ($initial) { |
|
94 | + return function($value) use ($initial) { |
|
95 | 95 | return $initial + $value; |
96 | 96 | }; |
97 | 97 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | */ |
107 | 107 | function subtract($initial = 0): Closure |
108 | 108 | { |
109 | - if (! C\isNumber($initial)) { |
|
109 | + if (!C\isNumber($initial)) { |
|
110 | 110 | throw new InvalidArgumentException(__FUNCTION__ . 'only accepts a Number (Float or Int)'); |
111 | 111 | } |
112 | 112 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * @param Number $value |
115 | 115 | * @return int|float |
116 | 116 | */ |
117 | - return function ($value) use ($initial) { |
|
117 | + return function($value) use ($initial) { |
|
118 | 118 | return $value - $initial; |
119 | 119 | }; |
120 | 120 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | */ |
130 | 130 | function multiply($initial = 1): Closure |
131 | 131 | { |
132 | - if (! C\isNumber($initial)) { |
|
132 | + if (!C\isNumber($initial)) { |
|
133 | 133 | throw new InvalidArgumentException(__FUNCTION__ . 'only accepts a Number (Float or Int)'); |
134 | 134 | } |
135 | 135 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @param Number $value |
138 | 138 | * @return Number |
139 | 139 | */ |
140 | - return function ($value) use ($initial) { |
|
140 | + return function($value) use ($initial) { |
|
141 | 141 | return $value * $initial; |
142 | 142 | }; |
143 | 143 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | */ |
154 | 154 | function divideBy($divisor = 1): Closure |
155 | 155 | { |
156 | - if (! C\isNumber($divisor)) { |
|
156 | + if (!C\isNumber($divisor)) { |
|
157 | 157 | throw new \InvalidArgumentException(__FUNCTION__ . 'only accepts a Number (Float or Int)'); |
158 | 158 | } |
159 | 159 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | * @param float $value |
162 | 162 | * @return float |
163 | 163 | */ |
164 | - return function ($value) use ($divisor): float { |
|
164 | + return function($value) use ($divisor): float { |
|
165 | 165 | return $value / $divisor; |
166 | 166 | }; |
167 | 167 | } |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | */ |
176 | 176 | function divideInto($dividend = 1): Closure |
177 | 177 | { |
178 | - if (! C\isNumber($dividend)) { |
|
178 | + if (!C\isNumber($dividend)) { |
|
179 | 179 | throw new \InvalidArgumentException(__FUNCTION__ . 'only accepts a Number (Float or Int)'); |
180 | 180 | } |
181 | 181 | |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | * @param float $value |
184 | 184 | * @return float |
185 | 185 | */ |
186 | - return function ($value) use ($dividend): float { |
|
186 | + return function($value) use ($dividend): float { |
|
187 | 187 | return $dividend / $value; |
188 | 188 | }; |
189 | 189 | } |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | */ |
198 | 198 | function remainderBy($divisor = 1): Closure |
199 | 199 | { |
200 | - if (! C\isNumber($divisor)) { |
|
200 | + if (!C\isNumber($divisor)) { |
|
201 | 201 | throw new \InvalidArgumentException(__FUNCTION__ . 'only accepts a Number (Float or Int)'); |
202 | 202 | } |
203 | 203 | |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | * @param float $value |
206 | 206 | * @return float |
207 | 207 | */ |
208 | - return function ($value) use ($divisor): float { |
|
208 | + return function($value) use ($divisor): float { |
|
209 | 209 | return $value % $divisor; |
210 | 210 | }; |
211 | 211 | } |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | */ |
220 | 220 | function remainderInto($dividend = 1): Closure |
221 | 221 | { |
222 | - if (! C\isNumber($dividend)) { |
|
222 | + if (!C\isNumber($dividend)) { |
|
223 | 223 | throw new \InvalidArgumentException(__FUNCTION__ . 'only accepts a Number (Float or Int)'); |
224 | 224 | } |
225 | 225 | |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * @param float $value |
228 | 228 | * @return float |
229 | 229 | */ |
230 | - return function ($value) use ($dividend): float { |
|
230 | + return function($value) use ($dividend): float { |
|
231 | 231 | return $dividend % $value; |
232 | 232 | }; |
233 | 233 | } |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | */ |
242 | 242 | function isMultipleOf($multiple): Closure |
243 | 243 | { |
244 | - if (! C\isNumber($multiple)) { |
|
244 | + if (!C\isNumber($multiple)) { |
|
245 | 245 | throw new \InvalidArgumentException(__FUNCTION__ . 'only accepts a Number (Float or Int)'); |
246 | 246 | } |
247 | 247 | |
@@ -250,8 +250,8 @@ discard block |
||
250 | 250 | * @return bool |
251 | 251 | * @throws InvalidArgumentException If neither int or float passed. |
252 | 252 | */ |
253 | - return function ($value) use ($multiple): bool { |
|
254 | - if (! C\isNumber($value)) { |
|
253 | + return function($value) use ($multiple): bool { |
|
254 | + if (!C\isNumber($value)) { |
|
255 | 255 | throw new \InvalidArgumentException(__FUNCTION__ . 'only accepts a Number (Float or Int)'); |
256 | 256 | } |
257 | 257 | |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | * @return bool |
278 | 278 | * @throws InvalidArgumentException If neither int or float passed. |
279 | 279 | */ |
280 | - return function (int $value) use ($factor): bool { |
|
280 | + return function(int $value) use ($factor): bool { |
|
281 | 281 | // Return false if 0 |
282 | 282 | if ($value === 0) { |
283 | 283 | return false; |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | */ |
298 | 298 | function round($precision = 1): Closure |
299 | 299 | { |
300 | - if (! C\isNumber($precision)) { |
|
300 | + if (!C\isNumber($precision)) { |
|
301 | 301 | throw new \InvalidArgumentException(__FUNCTION__ . 'only accepts a Number (Float or Int)'); |
302 | 302 | } |
303 | 303 | |
@@ -306,8 +306,8 @@ discard block |
||
306 | 306 | * @return float |
307 | 307 | * @throws InvalidArgumentException If neither int or float passed. |
308 | 308 | */ |
309 | - return function ($value) use ($precision): float { |
|
310 | - if (! C\isNumber($value)) { |
|
309 | + return function($value) use ($precision): float { |
|
310 | + if (!C\isNumber($value)) { |
|
311 | 311 | throw new \InvalidArgumentException("Num\\round() only accepts a valid Number ( Int|Float -> Float )"); |
312 | 312 | } |
313 | 313 | return \round(\floatval($value), $precision); |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | */ |
324 | 324 | function power($exponent): Closure |
325 | 325 | { |
326 | - if (! C\isNumber($exponent)) { |
|
326 | + if (!C\isNumber($exponent)) { |
|
327 | 327 | throw new \InvalidArgumentException(__FUNCTION__ . 'only accepts a Number (Float or Int) for the exponent'); |
328 | 328 | } |
329 | 329 | |
@@ -332,8 +332,8 @@ discard block |
||
332 | 332 | * @return Number |
333 | 333 | * @throws InvalidArgumentException If neither int or float passed. |
334 | 334 | */ |
335 | - return function ($value) use ($exponent) { |
|
336 | - if (! C\isNumber($value)) { |
|
335 | + return function($value) use ($exponent) { |
|
336 | + if (!C\isNumber($value)) { |
|
337 | 337 | throw new \InvalidArgumentException('Num\\power() only accepts a valid Number ( Int|Float )'); |
338 | 338 | } |
339 | 339 | return \pow($value, $exponent); |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | */ |
350 | 350 | function root($root): Closure |
351 | 351 | { |
352 | - if (! C\isNumber($root)) { |
|
352 | + if (!C\isNumber($root)) { |
|
353 | 353 | throw new \InvalidArgumentException(__FUNCTION__ . 'only accepts a Number (Float or Int) for the root'); |
354 | 354 | } |
355 | 355 | |
@@ -358,8 +358,8 @@ discard block |
||
358 | 358 | * @return Number |
359 | 359 | * @throws InvalidArgumentException If neither int or float passed. |
360 | 360 | */ |
361 | - return function ($value) use ($root) { |
|
362 | - if (! C\isNumber($value)) { |
|
361 | + return function($value) use ($root) { |
|
362 | + if (!C\isNumber($value)) { |
|
363 | 363 | throw new \InvalidArgumentException('Num\\root() only accepts a valid Number ( Int|Float )'); |
364 | 364 | } |
365 | 365 | return pow($value, (1 / $root)); |
@@ -41,14 +41,14 @@ discard block |
||
41 | 41 | * @return Closure(mixed):array<int|string, mixed> |
42 | 42 | */ |
43 | 43 | function pushHead( array $array ): Closure { |
44 | - /** |
|
45 | - * @param mixed $value Adds value start of array. |
|
46 | - * @return array New array with value on head. |
|
47 | - */ |
|
48 | - return function ( $value ) use ( $array ): array { |
|
49 | - array_unshift( $array, $value ); |
|
50 | - return $array; |
|
51 | - }; |
|
44 | + /** |
|
45 | + * @param mixed $value Adds value start of array. |
|
46 | + * @return array New array with value on head. |
|
47 | + */ |
|
48 | + return function ( $value ) use ( $array ): array { |
|
49 | + array_unshift( $array, $value ); |
|
50 | + return $array; |
|
51 | + }; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -58,14 +58,14 @@ discard block |
||
58 | 58 | * @return Closure(mixed):array<int|string, mixed> |
59 | 59 | */ |
60 | 60 | function pushTail( array $array ): Closure { |
61 | - /** |
|
62 | - * @param mixed $value Adds value end of array. |
|
63 | - * @return array<int|string, mixed> New array with value on tail. |
|
64 | - */ |
|
65 | - return function ( $value ) use ( $array ): array { |
|
66 | - $array[] = $value; |
|
67 | - return $array; |
|
68 | - }; |
|
61 | + /** |
|
62 | + * @param mixed $value Adds value end of array. |
|
63 | + * @return array<int|string, mixed> New array with value on tail. |
|
64 | + */ |
|
65 | + return function ( $value ) use ( $array ): array { |
|
66 | + $array[] = $value; |
|
67 | + return $array; |
|
68 | + }; |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * @return mixed Will return the first value is array is not empty, else null. |
76 | 76 | */ |
77 | 77 | function head( array $array ) { |
78 | - return ! empty( $array ) ? array_values( $array )[0] : null; |
|
78 | + return ! empty( $array ) ? array_values( $array )[0] : null; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @return mixed Will return the last value is array is not empty, else null. |
86 | 86 | */ |
87 | 87 | function tail( array $array ) { |
88 | - return ! empty( $array ) ? array_reverse( $array, false )[0] : null; |
|
88 | + return ! empty( $array ) ? array_reverse( $array, false )[0] : null; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | |
@@ -97,13 +97,13 @@ discard block |
||
97 | 97 | * |
98 | 98 | */ |
99 | 99 | function toString( ?string $glue = null ): Closure { |
100 | - /** |
|
101 | - * @param array<int|string, mixed> $array Array join |
|
102 | - * @return string. |
|
103 | - */ |
|
104 | - return function ( array $array ) use ( $glue ): string { |
|
105 | - return $glue ? \join( $glue, $array ) : \join( $array ); |
|
106 | - }; |
|
100 | + /** |
|
101 | + * @param array<int|string, mixed> $array Array join |
|
102 | + * @return string. |
|
103 | + */ |
|
104 | + return function ( array $array ) use ( $glue ): string { |
|
105 | + return $glue ? \join( $glue, $array ) : \join( $array ); |
|
106 | + }; |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -115,21 +115,21 @@ discard block |
||
115 | 115 | * |
116 | 116 | */ |
117 | 117 | function zip( array $additional, $default = null ): Closure { |
118 | - $additional = array_values( $additional ); |
|
119 | - return function ( array $array ) use ( $additional, $default ) { |
|
120 | - $array = array_values( $array ); |
|
121 | - return array_reduce( |
|
122 | - array_keys( $array ), |
|
123 | - function ( $carry, $key ) use ( $array, $additional, $default ): array { |
|
124 | - $carry[] = array( |
|
125 | - $array[ $key ], |
|
126 | - array_key_exists( $key, $additional ) ? $additional[ $key ] : $default, |
|
127 | - ); |
|
128 | - return $carry; |
|
129 | - }, |
|
130 | - array() |
|
131 | - ); |
|
132 | - }; |
|
118 | + $additional = array_values( $additional ); |
|
119 | + return function ( array $array ) use ( $additional, $default ) { |
|
120 | + $array = array_values( $array ); |
|
121 | + return array_reduce( |
|
122 | + array_keys( $array ), |
|
123 | + function ( $carry, $key ) use ( $array, $additional, $default ): array { |
|
124 | + $carry[] = array( |
|
125 | + $array[ $key ], |
|
126 | + array_key_exists( $key, $additional ) ? $additional[ $key ] : $default, |
|
127 | + ); |
|
128 | + return $carry; |
|
129 | + }, |
|
130 | + array() |
|
131 | + ); |
|
132 | + }; |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | |
@@ -148,16 +148,16 @@ discard block |
||
148 | 148 | * @return Closure |
149 | 149 | */ |
150 | 150 | function arrayCompiler( array $inital = array() ): Closure { |
151 | - /** |
|
152 | - * @param mixed $value Adds value to inner array if value set, else returns. |
|
153 | - * @return mixed[]|Closure |
|
154 | - */ |
|
155 | - return function ( $value = null ) use ( $inital ) { |
|
156 | - if ( $value ) { |
|
157 | - $inital[] = $value; |
|
158 | - } |
|
159 | - return ! is_null( $value ) ? arrayCompiler( $inital ) : $inital; |
|
160 | - }; |
|
151 | + /** |
|
152 | + * @param mixed $value Adds value to inner array if value set, else returns. |
|
153 | + * @return mixed[]|Closure |
|
154 | + */ |
|
155 | + return function ( $value = null ) use ( $inital ) { |
|
156 | + if ( $value ) { |
|
157 | + $inital[] = $value; |
|
158 | + } |
|
159 | + return ! is_null( $value ) ? arrayCompiler( $inital ) : $inital; |
|
160 | + }; |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -169,19 +169,19 @@ discard block |
||
169 | 169 | * @return Closure |
170 | 170 | */ |
171 | 171 | function arrayCompilerTyped( callable $validator, array $inital = array() ): Closure { |
172 | - // Ensure all is validated from initial. |
|
173 | - $inital = array_filter( $inital, $validator ); |
|
174 | - |
|
175 | - /** |
|
176 | - * @param mixed $value |
|
177 | - * @return mixed[]|Closure |
|
178 | - */ |
|
179 | - return function ( $value = null ) use ( $validator, $inital ) { |
|
180 | - if ( ! is_null( $value ) && $validator( $value ) ) { |
|
181 | - $inital[] = $value; |
|
182 | - } |
|
183 | - return ! is_null( $value ) ? arrayCompilerTyped( $validator, $inital ) : $inital; |
|
184 | - }; |
|
172 | + // Ensure all is validated from initial. |
|
173 | + $inital = array_filter( $inital, $validator ); |
|
174 | + |
|
175 | + /** |
|
176 | + * @param mixed $value |
|
177 | + * @return mixed[]|Closure |
|
178 | + */ |
|
179 | + return function ( $value = null ) use ( $validator, $inital ) { |
|
180 | + if ( ! is_null( $value ) && $validator( $value ) ) { |
|
181 | + $inital[] = $value; |
|
182 | + } |
|
183 | + return ! is_null( $value ) ? arrayCompilerTyped( $validator, $inital ) : $inital; |
|
184 | + }; |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | |
@@ -200,13 +200,13 @@ discard block |
||
200 | 200 | * @return Closure(array<int|string, mixed>):array<int|string, mixed> |
201 | 201 | */ |
202 | 202 | function filter( callable $callable ): Closure { |
203 | - /** |
|
204 | - * @param array<int|string, mixed> $source Array to filter |
|
205 | - * @return array<int|string, mixed> Filtered array. |
|
206 | - */ |
|
207 | - return function ( array $source ) use ( $callable ): array { |
|
208 | - return array_filter( $source, $callable ); |
|
209 | - }; |
|
203 | + /** |
|
204 | + * @param array<int|string, mixed> $source Array to filter |
|
205 | + * @return array<int|string, mixed> Filtered array. |
|
206 | + */ |
|
207 | + return function ( array $source ) use ( $callable ): array { |
|
208 | + return array_filter( $source, $callable ); |
|
209 | + }; |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -216,13 +216,13 @@ discard block |
||
216 | 216 | * @return Closure(array<int|string, mixed>):array<int|string, mixed> |
217 | 217 | */ |
218 | 218 | function filterKey( callable $callable ): Closure { |
219 | - /** |
|
220 | - * @param array<int|string, mixed> $source Array to filter |
|
221 | - * @return array<int|string, mixed> Filtered array. |
|
222 | - */ |
|
223 | - return function ( array $source ) use ( $callable ): array { |
|
224 | - return array_filter( $source, $callable, \ARRAY_FILTER_USE_KEY ); |
|
225 | - }; |
|
219 | + /** |
|
220 | + * @param array<int|string, mixed> $source Array to filter |
|
221 | + * @return array<int|string, mixed> Filtered array. |
|
222 | + */ |
|
223 | + return function ( array $source ) use ( $callable ): array { |
|
224 | + return array_filter( $source, $callable, \ARRAY_FILTER_USE_KEY ); |
|
225 | + }; |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
@@ -233,13 +233,13 @@ discard block |
||
233 | 233 | * @return Closure(array<int|string, mixed>):array<int|string, mixed> |
234 | 234 | */ |
235 | 235 | function filterAnd( callable ...$callables ): Closure { |
236 | - /** |
|
237 | - * @param array<int|string, mixed> $source Array to filter |
|
238 | - * @return array<int|string, mixed> Filtered array. |
|
239 | - */ |
|
240 | - return function ( array $source ) use ( $callables ): array { |
|
241 | - return array_filter( $source, Comp\groupAnd( ...$callables ) ); |
|
242 | - }; |
|
236 | + /** |
|
237 | + * @param array<int|string, mixed> $source Array to filter |
|
238 | + * @return array<int|string, mixed> Filtered array. |
|
239 | + */ |
|
240 | + return function ( array $source ) use ( $callables ): array { |
|
241 | + return array_filter( $source, Comp\groupAnd( ...$callables ) ); |
|
242 | + }; |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -250,13 +250,13 @@ discard block |
||
250 | 250 | * @return Closure(array<int|string, mixed>):array<int|string, mixed> |
251 | 251 | */ |
252 | 252 | function filterOr( callable ...$callables ): Closure { |
253 | - /** |
|
254 | - * @param array<int|string, mixed> $source Array to filter |
|
255 | - * @return array<int|string, mixed> Filtered array. |
|
256 | - */ |
|
257 | - return function ( array $source ) use ( $callables ): array { |
|
258 | - return array_filter( $source, Comp\groupOr( ...$callables ) ); |
|
259 | - }; |
|
253 | + /** |
|
254 | + * @param array<int|string, mixed> $source Array to filter |
|
255 | + * @return array<int|string, mixed> Filtered array. |
|
256 | + */ |
|
257 | + return function ( array $source ) use ( $callables ): array { |
|
258 | + return array_filter( $source, Comp\groupOr( ...$callables ) ); |
|
259 | + }; |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -266,13 +266,13 @@ discard block |
||
266 | 266 | * @return Closure(array<int|string, mixed>):?mixed |
267 | 267 | */ |
268 | 268 | function filterFirst( callable $func ): Closure { |
269 | - /** |
|
270 | - * @param array<int|string, mixed> $array The array to filter |
|
271 | - * @return mixed|null The first element from the filtered array or null if filter returns empty |
|
272 | - */ |
|
273 | - return function ( array $array ) use ( $func ) { |
|
274 | - return head( array_filter( $array, $func ) ); |
|
275 | - }; |
|
269 | + /** |
|
270 | + * @param array<int|string, mixed> $array The array to filter |
|
271 | + * @return mixed|null The first element from the filtered array or null if filter returns empty |
|
272 | + */ |
|
273 | + return function ( array $array ) use ( $func ) { |
|
274 | + return head( array_filter( $array, $func ) ); |
|
275 | + }; |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -282,13 +282,13 @@ discard block |
||
282 | 282 | * @return Closure(array<int|string, mixed>):?mixed |
283 | 283 | */ |
284 | 284 | function filterLast( callable $func ): Closure { |
285 | - /** |
|
286 | - * @param array<int|string, mixed> $array The array to filter |
|
287 | - * @return mixed|null The last element from the filtered array. |
|
288 | - */ |
|
289 | - return function ( array $array ) use ( $func ) { |
|
290 | - return tail( array_filter( $array, $func ) ); |
|
291 | - }; |
|
285 | + /** |
|
286 | + * @param array<int|string, mixed> $array The array to filter |
|
287 | + * @return mixed|null The last element from the filtered array. |
|
288 | + */ |
|
289 | + return function ( array $array ) use ( $func ) { |
|
290 | + return tail( array_filter( $array, $func ) ); |
|
291 | + }; |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | /** |
@@ -301,13 +301,13 @@ discard block |
||
301 | 301 | * @return Closure(array<int|string, mixed>):array<int|string, mixed> |
302 | 302 | */ |
303 | 303 | function filterMap( callable $filter, callable $map ): Closure { |
304 | - /** |
|
305 | - * @param array<int|string, mixed> $array The array to filter then map. |
|
306 | - * @return array<int|string, mixed> |
|
307 | - */ |
|
308 | - return function ( array $array ) use ( $filter, $map ): array { |
|
309 | - return array_map( $map, array_filter( $array, $filter ) ); |
|
310 | - }; |
|
304 | + /** |
|
305 | + * @param array<int|string, mixed> $array The array to filter then map. |
|
306 | + * @return array<int|string, mixed> |
|
307 | + */ |
|
308 | + return function ( array $array ) use ( $filter, $map ): array { |
|
309 | + return array_map( $map, array_filter( $array, $filter ) ); |
|
310 | + }; |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
@@ -317,13 +317,13 @@ discard block |
||
317 | 317 | * @return Closure(array<int|string, mixed>):int |
318 | 318 | */ |
319 | 319 | function filterCount( callable $function ): Closure { |
320 | - /** |
|
321 | - * @param array<int|string, mixed> $array |
|
322 | - * @return int Count |
|
323 | - */ |
|
324 | - return function ( array $array ) use ( $function ) { |
|
325 | - return count( array_filter( $array, $function ) ); |
|
326 | - }; |
|
320 | + /** |
|
321 | + * @param array<int|string, mixed> $array |
|
322 | + * @return int Count |
|
323 | + */ |
|
324 | + return function ( array $array ) use ( $function ) { |
|
325 | + return count( array_filter( $array, $function ) ); |
|
326 | + }; |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
@@ -335,26 +335,26 @@ discard block |
||
335 | 335 | * @return Closure(mixed[]):array{0:mixed[], 1:mixed[]} |
336 | 336 | */ |
337 | 337 | function partition( callable $function ): Closure { |
338 | - /** |
|
339 | - * @param mixed[] $array |
|
340 | - * @return array{0:mixed[], 1:mixed[]} |
|
341 | - */ |
|
342 | - return function ( array $array ) use ( $function ): array { |
|
343 | - return array_reduce( |
|
344 | - $array, |
|
345 | - /** |
|
346 | - * @param array{0:mixed[], 1:mixed[]} $carry |
|
347 | - * @param mixed $element |
|
348 | - * @return array{0:mixed[], 1:mixed[]} |
|
349 | - */ |
|
350 | - function ( $carry, $element ) use ( $function ): array { |
|
351 | - $key = (bool) $function( $element ) ? 1 : 0; |
|
352 | - $carry[ $key ][] = $element; |
|
353 | - return $carry; |
|
354 | - }, |
|
355 | - array( array(), array() ) |
|
356 | - ); |
|
357 | - }; |
|
338 | + /** |
|
339 | + * @param mixed[] $array |
|
340 | + * @return array{0:mixed[], 1:mixed[]} |
|
341 | + */ |
|
342 | + return function ( array $array ) use ( $function ): array { |
|
343 | + return array_reduce( |
|
344 | + $array, |
|
345 | + /** |
|
346 | + * @param array{0:mixed[], 1:mixed[]} $carry |
|
347 | + * @param mixed $element |
|
348 | + * @return array{0:mixed[], 1:mixed[]} |
|
349 | + */ |
|
350 | + function ( $carry, $element ) use ( $function ): array { |
|
351 | + $key = (bool) $function( $element ) ? 1 : 0; |
|
352 | + $carry[ $key ][] = $element; |
|
353 | + return $carry; |
|
354 | + }, |
|
355 | + array( array(), array() ) |
|
356 | + ); |
|
357 | + }; |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | /** |
@@ -364,18 +364,18 @@ discard block |
||
364 | 364 | * @return Closure(mixed[]):bool |
365 | 365 | */ |
366 | 366 | function filterAll( callable $function ): Closure { |
367 | - /** |
|
368 | - * @param mixed[] $array |
|
369 | - * @return bool |
|
370 | - */ |
|
371 | - return function ( array $array ) use ( $function ): bool { |
|
372 | - foreach ( $array as $value ) { |
|
373 | - if ( false === $function( $value ) ) { |
|
374 | - return false; |
|
375 | - } |
|
376 | - } |
|
377 | - return true; |
|
378 | - }; |
|
367 | + /** |
|
368 | + * @param mixed[] $array |
|
369 | + * @return bool |
|
370 | + */ |
|
371 | + return function ( array $array ) use ( $function ): bool { |
|
372 | + foreach ( $array as $value ) { |
|
373 | + if ( false === $function( $value ) ) { |
|
374 | + return false; |
|
375 | + } |
|
376 | + } |
|
377 | + return true; |
|
378 | + }; |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | |
@@ -386,18 +386,18 @@ discard block |
||
386 | 386 | * @return Closure(mixed[]):bool |
387 | 387 | */ |
388 | 388 | function filterAny( callable $function ): Closure { |
389 | - /** |
|
390 | - * @param mixed[] $array |
|
391 | - * @return bool |
|
392 | - */ |
|
393 | - return function ( array $array ) use ( $function ): bool { |
|
394 | - foreach ( $array as $value ) { |
|
395 | - if ( true === $function( $value ) ) { |
|
396 | - return true; |
|
397 | - } |
|
398 | - } |
|
399 | - return false; |
|
400 | - }; |
|
389 | + /** |
|
390 | + * @param mixed[] $array |
|
391 | + * @return bool |
|
392 | + */ |
|
393 | + return function ( array $array ) use ( $function ): bool { |
|
394 | + foreach ( $array as $value ) { |
|
395 | + if ( true === $function( $value ) ) { |
|
396 | + return true; |
|
397 | + } |
|
398 | + } |
|
399 | + return false; |
|
400 | + }; |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | |
@@ -416,13 +416,13 @@ discard block |
||
416 | 416 | * @return Closure(mixed[]):mixed[] |
417 | 417 | */ |
418 | 418 | function map( callable $func ): Closure { |
419 | - /** |
|
420 | - * @param mixed[] $array The array to map |
|
421 | - * @return mixed[] |
|
422 | - */ |
|
423 | - return function ( array $array ) use ( $func ): array { |
|
424 | - return array_map( $func, $array ); |
|
425 | - }; |
|
419 | + /** |
|
420 | + * @param mixed[] $array The array to map |
|
421 | + * @return mixed[] |
|
422 | + */ |
|
423 | + return function ( array $array ) use ( $func ): array { |
|
424 | + return array_map( $func, $array ); |
|
425 | + }; |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | /** |
@@ -433,20 +433,20 @@ discard block |
||
433 | 433 | * @return Closure(mixed[]):mixed[] |
434 | 434 | */ |
435 | 435 | function mapKey( callable $func ): Closure { |
436 | - /** |
|
437 | - * @param mixed[] $array The array to map |
|
438 | - * @return mixed[] |
|
439 | - */ |
|
440 | - return function ( array $array ) use ( $func ): array { |
|
441 | - return array_reduce( |
|
442 | - array_keys( $array ), |
|
443 | - function ( $carry, $key ) use ( $func, $array ) { |
|
444 | - $carry[ $func( $key ) ] = $array[ $key ]; |
|
445 | - return $carry; |
|
446 | - }, |
|
447 | - array() |
|
448 | - ); |
|
449 | - }; |
|
436 | + /** |
|
437 | + * @param mixed[] $array The array to map |
|
438 | + * @return mixed[] |
|
439 | + */ |
|
440 | + return function ( array $array ) use ( $func ): array { |
|
441 | + return array_reduce( |
|
442 | + array_keys( $array ), |
|
443 | + function ( $carry, $key ) use ( $func, $array ) { |
|
444 | + $carry[ $func( $key ) ] = $array[ $key ]; |
|
445 | + return $carry; |
|
446 | + }, |
|
447 | + array() |
|
448 | + ); |
|
449 | + }; |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | /** |
@@ -457,18 +457,18 @@ discard block |
||
457 | 457 | * @return Closure(mixed[]):mixed[] |
458 | 458 | */ |
459 | 459 | function mapWith( callable $func, ...$data ): Closure { |
460 | - /** |
|
461 | - * @param mixed[] $array The array to map |
|
462 | - * @return mixed[] |
|
463 | - */ |
|
464 | - return function ( array $array ) use ( $func, $data ): array { |
|
465 | - return array_map( |
|
466 | - function ( $e ) use ( $data, $func ) { |
|
467 | - return $func( $e, ...$data ); |
|
468 | - }, |
|
469 | - $array |
|
470 | - ); |
|
471 | - }; |
|
460 | + /** |
|
461 | + * @param mixed[] $array The array to map |
|
462 | + * @return mixed[] |
|
463 | + */ |
|
464 | + return function ( array $array ) use ( $func, $data ): array { |
|
465 | + return array_map( |
|
466 | + function ( $e ) use ( $data, $func ) { |
|
467 | + return $func( $e, ...$data ); |
|
468 | + }, |
|
469 | + $array |
|
470 | + ); |
|
471 | + }; |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | /** |
@@ -478,19 +478,19 @@ discard block |
||
478 | 478 | * @return Closure(mixed[]):mixed[] |
479 | 479 | */ |
480 | 480 | function mapWithKey( callable $func ): Closure { |
481 | - /** |
|
482 | - * @param mixed[] $array The array to map |
|
483 | - * @return mixed[] |
|
484 | - */ |
|
485 | - return function ( array $array ) use ( $func ): array { |
|
486 | - return array_map( |
|
487 | - function ( $key, $value ) use ( $func ) { |
|
488 | - return $func( $value, $key ); |
|
489 | - }, |
|
490 | - $array, |
|
491 | - array_keys( $array ) |
|
492 | - ); |
|
493 | - }; |
|
481 | + /** |
|
482 | + * @param mixed[] $array The array to map |
|
483 | + * @return mixed[] |
|
484 | + */ |
|
485 | + return function ( array $array ) use ( $func ): array { |
|
486 | + return array_map( |
|
487 | + function ( $key, $value ) use ( $func ) { |
|
488 | + return $func( $value, $key ); |
|
489 | + }, |
|
490 | + $array, |
|
491 | + array_keys( $array ) |
|
492 | + ); |
|
493 | + }; |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | /** |
@@ -500,19 +500,19 @@ discard block |
||
500 | 500 | * @return Closure(mixed[]):void |
501 | 501 | */ |
502 | 502 | function each( callable $func ): Closure { |
503 | - /** |
|
504 | - * @param mixed[] $array The array to map |
|
505 | - * @return void |
|
506 | - */ |
|
507 | - return function ( array $array ) use ( $func ): void { |
|
508 | - array_map( |
|
509 | - function ( $key, $value ) use ( $func ) { |
|
510 | - $func( $key, $value ); |
|
511 | - }, |
|
512 | - array_keys( $array ), |
|
513 | - $array |
|
514 | - ); |
|
515 | - }; |
|
503 | + /** |
|
504 | + * @param mixed[] $array The array to map |
|
505 | + * @return void |
|
506 | + */ |
|
507 | + return function ( array $array ) use ( $func ): void { |
|
508 | + array_map( |
|
509 | + function ( $key, $value ) use ( $func ) { |
|
510 | + $func( $key, $value ); |
|
511 | + }, |
|
512 | + array_keys( $array ), |
|
513 | + $array |
|
514 | + ); |
|
515 | + }; |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | /** |
@@ -523,29 +523,29 @@ discard block |
||
523 | 523 | * @return Closure(mixed[]):mixed[] |
524 | 524 | */ |
525 | 525 | function flatMap( callable $function, ?int $n = null ): Closure { |
526 | - /** |
|
527 | - * @param mixed[] $array |
|
528 | - * @return mixed[] |
|
529 | - */ |
|
530 | - return function ( array $array ) use ( $n, $function ): array { |
|
531 | - return array_reduce( |
|
532 | - $array, |
|
533 | - /** |
|
534 | - * @param mixed[] $carry |
|
535 | - * @param mixed $element |
|
536 | - * @return mixed[] |
|
537 | - */ |
|
538 | - function ( array $carry, $element ) use ( $n, $function ): array { |
|
539 | - if ( is_array( $element ) && ( is_null( $n ) || $n > 0 ) ) { |
|
540 | - $carry = array_merge( $carry, flatMap( $function, $n ? $n - 1 : null )( $element ) ); |
|
541 | - } else { |
|
542 | - $carry[] = is_array( $element ) ? $element : $function( $element ); |
|
543 | - } |
|
544 | - return $carry; |
|
545 | - }, |
|
546 | - array() |
|
547 | - ); |
|
548 | - }; |
|
526 | + /** |
|
527 | + * @param mixed[] $array |
|
528 | + * @return mixed[] |
|
529 | + */ |
|
530 | + return function ( array $array ) use ( $n, $function ): array { |
|
531 | + return array_reduce( |
|
532 | + $array, |
|
533 | + /** |
|
534 | + * @param mixed[] $carry |
|
535 | + * @param mixed $element |
|
536 | + * @return mixed[] |
|
537 | + */ |
|
538 | + function ( array $carry, $element ) use ( $n, $function ): array { |
|
539 | + if ( is_array( $element ) && ( is_null( $n ) || $n > 0 ) ) { |
|
540 | + $carry = array_merge( $carry, flatMap( $function, $n ? $n - 1 : null )( $element ) ); |
|
541 | + } else { |
|
542 | + $carry[] = is_array( $element ) ? $element : $function( $element ); |
|
543 | + } |
|
544 | + return $carry; |
|
545 | + }, |
|
546 | + array() |
|
547 | + ); |
|
548 | + }; |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | /* |
@@ -562,25 +562,25 @@ discard block |
||
562 | 562 | * @return Closure(mixed):mixed[] |
563 | 563 | */ |
564 | 564 | function groupBy( callable $function ): Closure { |
565 | - /** |
|
566 | - * @param mixed[] $array The array to be grouped |
|
567 | - * @return mixed[] Grouped array. |
|
568 | - */ |
|
569 | - return function ( array $array ) use ( $function ): array { |
|
570 | - return array_reduce( |
|
571 | - $array, |
|
572 | - /** |
|
573 | - * @param mixed[] $carry |
|
574 | - * @param mixed $element |
|
575 | - * @return mixed[] |
|
576 | - */ |
|
577 | - function ( $carry, $item ) use ( $function ): array { |
|
578 | - $carry[ call_user_func( $function, $item ) ][] = $item; |
|
579 | - return $carry; |
|
580 | - }, |
|
581 | - array() |
|
582 | - ); |
|
583 | - }; |
|
565 | + /** |
|
566 | + * @param mixed[] $array The array to be grouped |
|
567 | + * @return mixed[] Grouped array. |
|
568 | + */ |
|
569 | + return function ( array $array ) use ( $function ): array { |
|
570 | + return array_reduce( |
|
571 | + $array, |
|
572 | + /** |
|
573 | + * @param mixed[] $carry |
|
574 | + * @param mixed $element |
|
575 | + * @return mixed[] |
|
576 | + */ |
|
577 | + function ( $carry, $item ) use ( $function ): array { |
|
578 | + $carry[ call_user_func( $function, $item ) ][] = $item; |
|
579 | + return $carry; |
|
580 | + }, |
|
581 | + array() |
|
582 | + ); |
|
583 | + }; |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | /** |
@@ -591,13 +591,13 @@ discard block |
||
591 | 591 | * @return Closure(mixed[]):mixed[] |
592 | 592 | */ |
593 | 593 | function chunk( int $count, bool $preserveKeys = false ): Closure { |
594 | - /** |
|
595 | - * @param mixed[] $array Array to chunk |
|
596 | - * @return mixed[] |
|
597 | - */ |
|
598 | - return function ( array $array ) use ( $count, $preserveKeys ): array { |
|
599 | - return array_chunk( $array, max( 1, $count ), $preserveKeys ); |
|
600 | - }; |
|
594 | + /** |
|
595 | + * @param mixed[] $array Array to chunk |
|
596 | + * @return mixed[] |
|
597 | + */ |
|
598 | + return function ( array $array ) use ( $count, $preserveKeys ): array { |
|
599 | + return array_chunk( $array, max( 1, $count ), $preserveKeys ); |
|
600 | + }; |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | /** |
@@ -608,13 +608,13 @@ discard block |
||
608 | 608 | * @return Closure(mixed[]):mixed[] |
609 | 609 | */ |
610 | 610 | function column( string $column, ?string $key = null ): Closure { |
611 | - /** |
|
612 | - * @param mixed[] $array |
|
613 | - * @return mixed[] |
|
614 | - */ |
|
615 | - return function ( array $array ) use ( $column, $key ): array { |
|
616 | - return array_column( $array, $column, $key ); |
|
617 | - }; |
|
611 | + /** |
|
612 | + * @param mixed[] $array |
|
613 | + * @return mixed[] |
|
614 | + */ |
|
615 | + return function ( array $array ) use ( $column, $key ): array { |
|
616 | + return array_column( $array, $column, $key ); |
|
617 | + }; |
|
618 | 618 | } |
619 | 619 | |
620 | 620 | /** |
@@ -624,35 +624,35 @@ discard block |
||
624 | 624 | * @return Closure(mixed[] $var): mixed[] |
625 | 625 | */ |
626 | 626 | function flattenByN( ?int $n = null ): Closure { |
627 | - /** |
|
628 | - * @param mixed[] $array Array to flatten |
|
629 | - * @return mixed[] |
|
630 | - */ |
|
631 | - return function ( array $array ) use ( $n ): array { |
|
632 | - return array_reduce( |
|
633 | - $array, |
|
634 | - /** |
|
635 | - * @param array<int|string, mixed> $carry |
|
636 | - * @param mixed|mixed[] $element |
|
637 | - * @return array<int|string, mixed> |
|
638 | - */ |
|
639 | - function ( array $carry, $element ) use ( $n ): array { |
|
640 | - // Remove empty arrays. |
|
641 | - if ( is_array( $element ) && empty( $element ) ) { |
|
642 | - return $carry; |
|
643 | - } |
|
644 | - // If the element is an array and we are still flattening, call again |
|
645 | - if ( is_array( $element ) && ( is_null( $n ) || $n > 0 ) ) { // @phpstan-ignore-line |
|
646 | - $carry = array_merge( $carry, flattenByN( $n ? $n - 1 : null )( $element ) ); |
|
647 | - } else { |
|
648 | - // Else just add the element. |
|
649 | - $carry[] = $element; |
|
650 | - } |
|
651 | - return $carry; |
|
652 | - }, |
|
653 | - array() |
|
654 | - ); |
|
655 | - }; |
|
627 | + /** |
|
628 | + * @param mixed[] $array Array to flatten |
|
629 | + * @return mixed[] |
|
630 | + */ |
|
631 | + return function ( array $array ) use ( $n ): array { |
|
632 | + return array_reduce( |
|
633 | + $array, |
|
634 | + /** |
|
635 | + * @param array<int|string, mixed> $carry |
|
636 | + * @param mixed|mixed[] $element |
|
637 | + * @return array<int|string, mixed> |
|
638 | + */ |
|
639 | + function ( array $carry, $element ) use ( $n ): array { |
|
640 | + // Remove empty arrays. |
|
641 | + if ( is_array( $element ) && empty( $element ) ) { |
|
642 | + return $carry; |
|
643 | + } |
|
644 | + // If the element is an array and we are still flattening, call again |
|
645 | + if ( is_array( $element ) && ( is_null( $n ) || $n > 0 ) ) { // @phpstan-ignore-line |
|
646 | + $carry = array_merge( $carry, flattenByN( $n ? $n - 1 : null )( $element ) ); |
|
647 | + } else { |
|
648 | + // Else just add the element. |
|
649 | + $carry[] = $element; |
|
650 | + } |
|
651 | + return $carry; |
|
652 | + }, |
|
653 | + array() |
|
654 | + ); |
|
655 | + }; |
|
656 | 656 | } |
657 | 657 | |
658 | 658 | /** |
@@ -662,13 +662,13 @@ discard block |
||
662 | 662 | * @return Closure(mixed[]):mixed[] |
663 | 663 | */ |
664 | 664 | function replaceRecursive( array ...$with ): Closure { |
665 | - /** |
|
666 | - * @param mixed[] $array The array to have elements replaced from. |
|
667 | - * @return mixed[] Array with replacements. |
|
668 | - */ |
|
669 | - return function ( array $array ) use ( $with ): array { |
|
670 | - return array_replace_recursive( $array, ...$with ); |
|
671 | - }; |
|
665 | + /** |
|
666 | + * @param mixed[] $array The array to have elements replaced from. |
|
667 | + * @return mixed[] Array with replacements. |
|
668 | + */ |
|
669 | + return function ( array $array ) use ( $with ): array { |
|
670 | + return array_replace_recursive( $array, ...$with ); |
|
671 | + }; |
|
672 | 672 | } |
673 | 673 | |
674 | 674 | /** |
@@ -678,13 +678,13 @@ discard block |
||
678 | 678 | * @return Closure(mixed[]):mixed[] |
679 | 679 | */ |
680 | 680 | function replace( array ...$with ): Closure { |
681 | - /** |
|
682 | - * @param mixed[] $array The array to have elements replaced from. |
|
683 | - * @return mixed[] Array with replacements. |
|
684 | - */ |
|
685 | - return function ( array $array ) use ( $with ): array { |
|
686 | - return array_replace( $array, ...$with ); |
|
687 | - }; |
|
681 | + /** |
|
682 | + * @param mixed[] $array The array to have elements replaced from. |
|
683 | + * @return mixed[] Array with replacements. |
|
684 | + */ |
|
685 | + return function ( array $array ) use ( $with ): array { |
|
686 | + return array_replace( $array, ...$with ); |
|
687 | + }; |
|
688 | 688 | } |
689 | 689 | |
690 | 690 | /** |
@@ -694,13 +694,13 @@ discard block |
||
694 | 694 | * @return Closure(mixed[]):Number |
695 | 695 | */ |
696 | 696 | function sumWhere( callable $function ): Closure { |
697 | - /** |
|
698 | - * @param mixed[] $array Array to do sum() on. |
|
699 | - * @return Number The total. |
|
700 | - */ |
|
701 | - return function ( array $array ) use ( $function ) { |
|
702 | - return array_sum( array_map( $function, $array ) ); |
|
703 | - }; |
|
697 | + /** |
|
698 | + * @param mixed[] $array Array to do sum() on. |
|
699 | + * @return Number The total. |
|
700 | + */ |
|
701 | + return function ( array $array ) use ( $function ) { |
|
702 | + return array_sum( array_map( $function, $array ) ); |
|
703 | + }; |
|
704 | 704 | } |
705 | 705 | |
706 | 706 | /** |
@@ -713,27 +713,27 @@ discard block |
||
713 | 713 | * @throws InvalidArgumentException If property does not exist or is not public. |
714 | 714 | */ |
715 | 715 | function toObject( ?object $object = null ): Closure { |
716 | - $object = $object ?? new stdClass(); |
|
717 | - |
|
718 | - /** |
|
719 | - * @param mixed[] $array |
|
720 | - * @return object |
|
721 | - */ |
|
722 | - return function ( array $array ) use ( $object ): object { |
|
723 | - foreach ( $array as $key => $value ) { |
|
724 | - // If key is not a string or numerical, skip it. |
|
725 | - if ( ! is_string( $key ) || is_numeric( $key ) ) { |
|
726 | - continue; |
|
727 | - } |
|
728 | - |
|
729 | - try { |
|
730 | - $object->{$key} = $value; |
|
731 | - } catch ( \Throwable $th ) { |
|
732 | - throw new \InvalidArgumentException( "Property {$key} does not exist or is not public." ); |
|
733 | - } |
|
734 | - } |
|
735 | - return $object; |
|
736 | - }; |
|
716 | + $object = $object ?? new stdClass(); |
|
717 | + |
|
718 | + /** |
|
719 | + * @param mixed[] $array |
|
720 | + * @return object |
|
721 | + */ |
|
722 | + return function ( array $array ) use ( $object ): object { |
|
723 | + foreach ( $array as $key => $value ) { |
|
724 | + // If key is not a string or numerical, skip it. |
|
725 | + if ( ! is_string( $key ) || is_numeric( $key ) ) { |
|
726 | + continue; |
|
727 | + } |
|
728 | + |
|
729 | + try { |
|
730 | + $object->{$key} = $value; |
|
731 | + } catch ( \Throwable $th ) { |
|
732 | + throw new \InvalidArgumentException( "Property {$key} does not exist or is not public." ); |
|
733 | + } |
|
734 | + } |
|
735 | + return $object; |
|
736 | + }; |
|
737 | 737 | } |
738 | 738 | |
739 | 739 | /** |
@@ -750,13 +750,13 @@ discard block |
||
750 | 750 | * JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE, JSON_THROW_ON_ERROR |
751 | 751 | */ |
752 | 752 | function toJson( int $flags = 0, int $depth = 512 ): Closure { |
753 | - /** |
|
754 | - * @param mixed $data |
|
755 | - * @return string|null |
|
756 | - */ |
|
757 | - return function ( $data ) use ( $flags, $depth ): ?string { |
|
758 | - return \json_encode( $data, $flags, max( 1, $depth ) ) ?: null; |
|
759 | - }; |
|
753 | + /** |
|
754 | + * @param mixed $data |
|
755 | + * @return string|null |
|
756 | + */ |
|
757 | + return function ( $data ) use ( $flags, $depth ): ?string { |
|
758 | + return \json_encode( $data, $flags, max( 1, $depth ) ) ?: null; |
|
759 | + }; |
|
760 | 760 | } |
761 | 761 | |
762 | 762 | |
@@ -775,14 +775,14 @@ discard block |
||
775 | 775 | * @return Closure(mixed[]):mixed[] |
776 | 776 | */ |
777 | 777 | function sort( int $flag = SORT_REGULAR ): Closure { |
778 | - /** |
|
779 | - * @param mixed[]$array The array to sort |
|
780 | - * @return mixed[] The sorted array (new array) |
|
781 | - */ |
|
782 | - return function ( array $array ) use ( $flag ) { |
|
783 | - \sort( $array, $flag ); |
|
784 | - return $array; |
|
785 | - }; |
|
778 | + /** |
|
779 | + * @param mixed[]$array The array to sort |
|
780 | + * @return mixed[] The sorted array (new array) |
|
781 | + */ |
|
782 | + return function ( array $array ) use ( $flag ) { |
|
783 | + \sort( $array, $flag ); |
|
784 | + return $array; |
|
785 | + }; |
|
786 | 786 | } |
787 | 787 | |
788 | 788 | /** |
@@ -793,14 +793,14 @@ discard block |
||
793 | 793 | * @return Closure(mixed[]):mixed[] |
794 | 794 | */ |
795 | 795 | function rsort( int $flag = SORT_REGULAR ): Closure { |
796 | - /** |
|
797 | - * @param mixed[]$array The array to sort |
|
798 | - * @return mixed[] The sorted array (new array) |
|
799 | - */ |
|
800 | - return function ( array $array ) use ( $flag ) { |
|
801 | - \rsort( $array, $flag ); |
|
802 | - return $array; |
|
803 | - }; |
|
796 | + /** |
|
797 | + * @param mixed[]$array The array to sort |
|
798 | + * @return mixed[] The sorted array (new array) |
|
799 | + */ |
|
800 | + return function ( array $array ) use ( $flag ) { |
|
801 | + \rsort( $array, $flag ); |
|
802 | + return $array; |
|
803 | + }; |
|
804 | 804 | } |
805 | 805 | |
806 | 806 | |
@@ -811,14 +811,14 @@ discard block |
||
811 | 811 | * @return Closure(mixed[]):mixed[] |
812 | 812 | */ |
813 | 813 | function ksort( int $flag = SORT_REGULAR ): Closure { |
814 | - /** |
|
815 | - * @param mixed[]$array The array to sort |
|
816 | - * @return mixed[] The sorted array (new array) |
|
817 | - */ |
|
818 | - return function ( array $array ) use ( $flag ) { |
|
819 | - \ksort( $array, $flag ); |
|
820 | - return $array; |
|
821 | - }; |
|
814 | + /** |
|
815 | + * @param mixed[]$array The array to sort |
|
816 | + * @return mixed[] The sorted array (new array) |
|
817 | + */ |
|
818 | + return function ( array $array ) use ( $flag ) { |
|
819 | + \ksort( $array, $flag ); |
|
820 | + return $array; |
|
821 | + }; |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | /** |
@@ -828,14 +828,14 @@ discard block |
||
828 | 828 | * @return Closure(mixed[]):mixed[] |
829 | 829 | */ |
830 | 830 | function krsort( int $flag = SORT_REGULAR ): Closure { |
831 | - /** |
|
832 | - * @param mixed[]$array The array to sort |
|
833 | - * @return mixed[] The sorted array (new array) |
|
834 | - */ |
|
835 | - return function ( array $array ) use ( $flag ) { |
|
836 | - \krsort( $array, $flag ); |
|
837 | - return $array; |
|
838 | - }; |
|
831 | + /** |
|
832 | + * @param mixed[]$array The array to sort |
|
833 | + * @return mixed[] The sorted array (new array) |
|
834 | + */ |
|
835 | + return function ( array $array ) use ( $flag ) { |
|
836 | + \krsort( $array, $flag ); |
|
837 | + return $array; |
|
838 | + }; |
|
839 | 839 | } |
840 | 840 | |
841 | 841 | /** |
@@ -846,14 +846,14 @@ discard block |
||
846 | 846 | * @return Closure(mixed[]):mixed[] |
847 | 847 | */ |
848 | 848 | function asort( int $flag = SORT_REGULAR ): Closure { |
849 | - /** |
|
850 | - * @param mixed[]$array The array to sort |
|
851 | - * @return mixed[] The sorted array (new array) |
|
852 | - */ |
|
853 | - return function ( array $array ) use ( $flag ) { |
|
854 | - \asort( $array, $flag ); |
|
855 | - return $array; |
|
856 | - }; |
|
849 | + /** |
|
850 | + * @param mixed[]$array The array to sort |
|
851 | + * @return mixed[] The sorted array (new array) |
|
852 | + */ |
|
853 | + return function ( array $array ) use ( $flag ) { |
|
854 | + \asort( $array, $flag ); |
|
855 | + return $array; |
|
856 | + }; |
|
857 | 857 | } |
858 | 858 | |
859 | 859 | /** |
@@ -864,14 +864,14 @@ discard block |
||
864 | 864 | * @return Closure(mixed[]):mixed[] |
865 | 865 | */ |
866 | 866 | function arsort( int $flag = SORT_REGULAR ): Closure { |
867 | - /** |
|
868 | - * @param mixed[]$array The array to sort |
|
869 | - * @return mixed[] The sorted array (new array) |
|
870 | - */ |
|
871 | - return function ( array $array ) use ( $flag ) { |
|
872 | - \arsort( $array, $flag ); |
|
873 | - return $array; |
|
874 | - }; |
|
867 | + /** |
|
868 | + * @param mixed[]$array The array to sort |
|
869 | + * @return mixed[] The sorted array (new array) |
|
870 | + */ |
|
871 | + return function ( array $array ) use ( $flag ) { |
|
872 | + \arsort( $array, $flag ); |
|
873 | + return $array; |
|
874 | + }; |
|
875 | 875 | } |
876 | 876 | |
877 | 877 | /** |
@@ -880,14 +880,14 @@ discard block |
||
880 | 880 | * @return Closure(mixed[]):mixed[] |
881 | 881 | */ |
882 | 882 | function natsort(): Closure { |
883 | - /** |
|
884 | - * @param mixed[]$array The array to sort |
|
885 | - * @return mixed[] The sorted array (new array) |
|
886 | - */ |
|
887 | - return function ( array $array ) { |
|
888 | - \natsort( $array ); |
|
889 | - return $array; |
|
890 | - }; |
|
883 | + /** |
|
884 | + * @param mixed[]$array The array to sort |
|
885 | + * @return mixed[] The sorted array (new array) |
|
886 | + */ |
|
887 | + return function ( array $array ) { |
|
888 | + \natsort( $array ); |
|
889 | + return $array; |
|
890 | + }; |
|
891 | 891 | } |
892 | 892 | |
893 | 893 | /** |
@@ -896,14 +896,14 @@ discard block |
||
896 | 896 | * @return Closure(mixed[]):mixed[] |
897 | 897 | */ |
898 | 898 | function natcasesort(): Closure { |
899 | - /** |
|
900 | - * @param mixed[]$array The array to sort |
|
901 | - * @return mixed[] The sorted array (new array) |
|
902 | - */ |
|
903 | - return function ( array $array ) { |
|
904 | - \natcasesort( $array ); |
|
905 | - return $array; |
|
906 | - }; |
|
899 | + /** |
|
900 | + * @param mixed[]$array The array to sort |
|
901 | + * @return mixed[] The sorted array (new array) |
|
902 | + */ |
|
903 | + return function ( array $array ) { |
|
904 | + \natcasesort( $array ); |
|
905 | + return $array; |
|
906 | + }; |
|
907 | 907 | } |
908 | 908 | |
909 | 909 | /** |
@@ -913,14 +913,14 @@ discard block |
||
913 | 913 | * @return Closure(mixed[]):mixed[] |
914 | 914 | */ |
915 | 915 | function uksort( callable $function ): Closure { |
916 | - /** |
|
917 | - * @param mixed[] $array The array to sort |
|
918 | - * @return mixed[] The sorted array (new array) |
|
919 | - */ |
|
920 | - return function ( array $array ) use ( $function ) { |
|
921 | - \uksort( $array, $function ); |
|
922 | - return $array; |
|
923 | - }; |
|
916 | + /** |
|
917 | + * @param mixed[] $array The array to sort |
|
918 | + * @return mixed[] The sorted array (new array) |
|
919 | + */ |
|
920 | + return function ( array $array ) use ( $function ) { |
|
921 | + \uksort( $array, $function ); |
|
922 | + return $array; |
|
923 | + }; |
|
924 | 924 | } |
925 | 925 | |
926 | 926 | /** |
@@ -931,14 +931,14 @@ discard block |
||
931 | 931 | * @return Closure(mixed[]):mixed[] |
932 | 932 | */ |
933 | 933 | function uasort( callable $function ): Closure { |
934 | - /** |
|
935 | - * @param mixed[]$array The array to sort |
|
936 | - * @return mixed[] The sorted array (new array) |
|
937 | - */ |
|
938 | - return function ( array $array ) use ( $function ) { |
|
939 | - \uasort( $array, $function ); |
|
940 | - return $array; |
|
941 | - }; |
|
934 | + /** |
|
935 | + * @param mixed[]$array The array to sort |
|
936 | + * @return mixed[] The sorted array (new array) |
|
937 | + */ |
|
938 | + return function ( array $array ) use ( $function ) { |
|
939 | + \uasort( $array, $function ); |
|
940 | + return $array; |
|
941 | + }; |
|
942 | 942 | } |
943 | 943 | |
944 | 944 | |
@@ -950,14 +950,14 @@ discard block |
||
950 | 950 | * @return Closure(mixed[]):mixed[] |
951 | 951 | */ |
952 | 952 | function usort( callable $function ): Closure { |
953 | - /** |
|
954 | - * @param mixed[]$array The array to sort |
|
955 | - * @return mixed[] The sorted array (new array) |
|
956 | - */ |
|
957 | - return function ( array $array ) use ( $function ) { |
|
958 | - \usort( $array, $function ); |
|
959 | - return $array; |
|
960 | - }; |
|
953 | + /** |
|
954 | + * @param mixed[]$array The array to sort |
|
955 | + * @return mixed[] The sorted array (new array) |
|
956 | + */ |
|
957 | + return function ( array $array ) use ( $function ) { |
|
958 | + \usort( $array, $function ); |
|
959 | + return $array; |
|
960 | + }; |
|
961 | 961 | } |
962 | 962 | |
963 | 963 | /** |
@@ -968,14 +968,14 @@ discard block |
||
968 | 968 | * @return Closure(mixed[]):mixed[] |
969 | 969 | */ |
970 | 970 | function scan( callable $function, $initialValue ): Closure { |
971 | - return function ( array $array ) use ( $function, $initialValue ) { |
|
972 | - $carry[] = $initialValue; |
|
973 | - foreach ( $array as $key => $value ) { |
|
974 | - $initialValue = $function( $initialValue, $value ); |
|
975 | - $carry[] = $initialValue; |
|
976 | - } |
|
977 | - return $carry; |
|
978 | - }; |
|
971 | + return function ( array $array ) use ( $function, $initialValue ) { |
|
972 | + $carry[] = $initialValue; |
|
973 | + foreach ( $array as $key => $value ) { |
|
974 | + $initialValue = $function( $initialValue, $value ); |
|
975 | + $carry[] = $initialValue; |
|
976 | + } |
|
977 | + return $carry; |
|
978 | + }; |
|
979 | 979 | } |
980 | 980 | |
981 | 981 | /** |
@@ -986,14 +986,14 @@ discard block |
||
986 | 986 | * @return Closure(mixed[]):mixed[] |
987 | 987 | */ |
988 | 988 | function scanR( callable $function, $initialValue ): Closure { |
989 | - return function ( array $array ) use ( $function, $initialValue ) { |
|
990 | - $carry[] = $initialValue; |
|
991 | - foreach ( array_reverse( $array ) as $key => $value ) { |
|
992 | - $initialValue = $function( $initialValue, $value ); |
|
993 | - $carry[] = $initialValue; |
|
994 | - } |
|
995 | - return \array_reverse( $carry ); |
|
996 | - }; |
|
989 | + return function ( array $array ) use ( $function, $initialValue ) { |
|
990 | + $carry[] = $initialValue; |
|
991 | + foreach ( array_reverse( $array ) as $key => $value ) { |
|
992 | + $initialValue = $function( $initialValue, $value ); |
|
993 | + $carry[] = $initialValue; |
|
994 | + } |
|
995 | + return \array_reverse( $carry ); |
|
996 | + }; |
|
997 | 997 | } |
998 | 998 | |
999 | 999 | /** |
@@ -1004,13 +1004,13 @@ discard block |
||
1004 | 1004 | * @return Closure(mixed[]):mixed |
1005 | 1005 | */ |
1006 | 1006 | function fold( callable $callable, $initial = array() ): Closure { |
1007 | - /** |
|
1008 | - * @param mixed[] $array |
|
1009 | - * @return mixed |
|
1010 | - */ |
|
1011 | - return function ( array $array ) use ( $callable, $initial ) { |
|
1012 | - return array_reduce( $array, $callable, $initial ); |
|
1013 | - }; |
|
1007 | + /** |
|
1008 | + * @param mixed[] $array |
|
1009 | + * @return mixed |
|
1010 | + */ |
|
1011 | + return function ( array $array ) use ( $callable, $initial ) { |
|
1012 | + return array_reduce( $array, $callable, $initial ); |
|
1013 | + }; |
|
1014 | 1014 | } |
1015 | 1015 | |
1016 | 1016 | /** |
@@ -1021,13 +1021,13 @@ discard block |
||
1021 | 1021 | * @return Closure(mixed[]):mixed |
1022 | 1022 | */ |
1023 | 1023 | function foldR( callable $callable, $initial = array() ): Closure { |
1024 | - /** |
|
1025 | - * @param mixed[] $array |
|
1026 | - * @return mixed |
|
1027 | - */ |
|
1028 | - return function ( array $array ) use ( $callable, $initial ) { |
|
1029 | - return array_reduce( \array_reverse( $array ), $callable, $initial ); |
|
1030 | - }; |
|
1024 | + /** |
|
1025 | + * @param mixed[] $array |
|
1026 | + * @return mixed |
|
1027 | + */ |
|
1028 | + return function ( array $array ) use ( $callable, $initial ) { |
|
1029 | + return array_reduce( \array_reverse( $array ), $callable, $initial ); |
|
1030 | + }; |
|
1031 | 1031 | } |
1032 | 1032 | |
1033 | 1033 | /** |
@@ -1039,16 +1039,16 @@ discard block |
||
1039 | 1039 | * @return Closure(mixed[]):mixed |
1040 | 1040 | */ |
1041 | 1041 | function foldKeys( callable $callable, $initial = array() ): Closure { |
1042 | - /** |
|
1043 | - * @param mixed[] $array |
|
1044 | - * @return mixed |
|
1045 | - */ |
|
1046 | - return function ( array $array ) use ( $callable, $initial ) { |
|
1047 | - foreach ( $array as $key => $value ) { |
|
1048 | - $initial = $callable( $initial, $key, $value ); |
|
1049 | - } |
|
1050 | - return $initial; |
|
1051 | - }; |
|
1042 | + /** |
|
1043 | + * @param mixed[] $array |
|
1044 | + * @return mixed |
|
1045 | + */ |
|
1046 | + return function ( array $array ) use ( $callable, $initial ) { |
|
1047 | + foreach ( $array as $key => $value ) { |
|
1048 | + $initial = $callable( $initial, $key, $value ); |
|
1049 | + } |
|
1050 | + return $initial; |
|
1051 | + }; |
|
1052 | 1052 | } |
1053 | 1053 | |
1054 | 1054 | /** |
@@ -1059,18 +1059,18 @@ discard block |
||
1059 | 1059 | * @throws \InvalidArgumentException if count is negative |
1060 | 1060 | */ |
1061 | 1061 | function take( int $count = 1 ): Closure { |
1062 | - // throw InvalidArgumentException if count is negative |
|
1063 | - if ( $count < 0 ) { |
|
1064 | - throw new \InvalidArgumentException( __FUNCTION__ . ' count must be greater than or equal to 0' ); |
|
1065 | - } |
|
1066 | - |
|
1067 | - /** |
|
1068 | - * @param mixed[] $array |
|
1069 | - * @return mixed[] |
|
1070 | - */ |
|
1071 | - return function ( array $array ) use ( $count ) { |
|
1072 | - return \array_slice( $array, 0, $count ); |
|
1073 | - }; |
|
1062 | + // throw InvalidArgumentException if count is negative |
|
1063 | + if ( $count < 0 ) { |
|
1064 | + throw new \InvalidArgumentException( __FUNCTION__ . ' count must be greater than or equal to 0' ); |
|
1065 | + } |
|
1066 | + |
|
1067 | + /** |
|
1068 | + * @param mixed[] $array |
|
1069 | + * @return mixed[] |
|
1070 | + */ |
|
1071 | + return function ( array $array ) use ( $count ) { |
|
1072 | + return \array_slice( $array, 0, $count ); |
|
1073 | + }; |
|
1074 | 1074 | } |
1075 | 1075 | |
1076 | 1076 | /** |
@@ -1081,25 +1081,25 @@ discard block |
||
1081 | 1081 | * @throws \InvalidArgumentException if count is negative |
1082 | 1082 | */ |
1083 | 1083 | function takeLast( int $count = 1 ): Closure { |
1084 | - // throw InvalidArgumentException if count is negative |
|
1085 | - if ( $count < 0 ) { |
|
1086 | - throw new \InvalidArgumentException( __FUNCTION__ . ' count must be greater than or equal to 0' ); |
|
1087 | - } |
|
1088 | - |
|
1089 | - // If count is 0, return an empty array |
|
1090 | - if ( $count === 0 ) { |
|
1091 | - return function ( array $array ) { |
|
1092 | - return array(); |
|
1093 | - }; |
|
1094 | - } |
|
1095 | - |
|
1096 | - /** |
|
1097 | - * @param mixed[] $array |
|
1098 | - * @return mixed[] |
|
1099 | - */ |
|
1100 | - return function ( array $array ) use ( $count ) { |
|
1101 | - return \array_slice( $array, - $count ); |
|
1102 | - }; |
|
1084 | + // throw InvalidArgumentException if count is negative |
|
1085 | + if ( $count < 0 ) { |
|
1086 | + throw new \InvalidArgumentException( __FUNCTION__ . ' count must be greater than or equal to 0' ); |
|
1087 | + } |
|
1088 | + |
|
1089 | + // If count is 0, return an empty array |
|
1090 | + if ( $count === 0 ) { |
|
1091 | + return function ( array $array ) { |
|
1092 | + return array(); |
|
1093 | + }; |
|
1094 | + } |
|
1095 | + |
|
1096 | + /** |
|
1097 | + * @param mixed[] $array |
|
1098 | + * @return mixed[] |
|
1099 | + */ |
|
1100 | + return function ( array $array ) use ( $count ) { |
|
1101 | + return \array_slice( $array, - $count ); |
|
1102 | + }; |
|
1103 | 1103 | } |
1104 | 1104 | |
1105 | 1105 | /** |
@@ -1110,20 +1110,20 @@ discard block |
||
1110 | 1110 | * @return Closure(mixed[]):mixed[] |
1111 | 1111 | */ |
1112 | 1112 | function takeUntil( callable $conditional ): Closure { |
1113 | - /** |
|
1114 | - * @param mixed[] $array |
|
1115 | - * @return mixed[] |
|
1116 | - */ |
|
1117 | - return function ( array $array ) use ( $conditional ) { |
|
1118 | - $carry = array(); |
|
1119 | - foreach ( $array as $key => $value ) { |
|
1120 | - if ( true === $conditional( $value ) ) { |
|
1121 | - break; |
|
1122 | - } |
|
1123 | - $carry[ $key ] = $value; |
|
1124 | - } |
|
1125 | - return $carry; |
|
1126 | - }; |
|
1113 | + /** |
|
1114 | + * @param mixed[] $array |
|
1115 | + * @return mixed[] |
|
1116 | + */ |
|
1117 | + return function ( array $array ) use ( $conditional ) { |
|
1118 | + $carry = array(); |
|
1119 | + foreach ( $array as $key => $value ) { |
|
1120 | + if ( true === $conditional( $value ) ) { |
|
1121 | + break; |
|
1122 | + } |
|
1123 | + $carry[ $key ] = $value; |
|
1124 | + } |
|
1125 | + return $carry; |
|
1126 | + }; |
|
1127 | 1127 | } |
1128 | 1128 | |
1129 | 1129 | /** |
@@ -1134,18 +1134,18 @@ discard block |
||
1134 | 1134 | * @return Closure(mixed[]):mixed[] |
1135 | 1135 | */ |
1136 | 1136 | function takeWhile( callable $conditional ): Closure { |
1137 | - /** |
|
1138 | - * @param mixed[] $array |
|
1139 | - * @return mixed[] |
|
1140 | - */ |
|
1141 | - return function ( array $array ) use ( $conditional ) { |
|
1142 | - $carry = array(); |
|
1143 | - foreach ( $array as $key => $value ) { |
|
1144 | - if ( false === $conditional( $value ) ) { |
|
1145 | - break; |
|
1146 | - } |
|
1147 | - $carry[ $key ] = $value; |
|
1148 | - } |
|
1149 | - return $carry; |
|
1150 | - }; |
|
1137 | + /** |
|
1138 | + * @param mixed[] $array |
|
1139 | + * @return mixed[] |
|
1140 | + */ |
|
1141 | + return function ( array $array ) use ( $conditional ) { |
|
1142 | + $carry = array(); |
|
1143 | + foreach ( $array as $key => $value ) { |
|
1144 | + if ( false === $conditional( $value ) ) { |
|
1145 | + break; |
|
1146 | + } |
|
1147 | + $carry[ $key ] = $value; |
|
1148 | + } |
|
1149 | + return $carry; |
|
1150 | + }; |
|
1151 | 1151 | } |
@@ -40,13 +40,13 @@ discard block |
||
40 | 40 | * @param array<int|string, mixed> $array |
41 | 41 | * @return Closure(mixed):array<int|string, mixed> |
42 | 42 | */ |
43 | -function pushHead( array $array ): Closure { |
|
43 | +function pushHead(array $array): Closure { |
|
44 | 44 | /** |
45 | 45 | * @param mixed $value Adds value start of array. |
46 | 46 | * @return array New array with value on head. |
47 | 47 | */ |
48 | - return function ( $value ) use ( $array ): array { |
|
49 | - array_unshift( $array, $value ); |
|
48 | + return function($value) use ($array): array { |
|
49 | + array_unshift($array, $value); |
|
50 | 50 | return $array; |
51 | 51 | }; |
52 | 52 | } |
@@ -57,12 +57,12 @@ discard block |
||
57 | 57 | * @param array<int|string, mixed> $array |
58 | 58 | * @return Closure(mixed):array<int|string, mixed> |
59 | 59 | */ |
60 | -function pushTail( array $array ): Closure { |
|
60 | +function pushTail(array $array): Closure { |
|
61 | 61 | /** |
62 | 62 | * @param mixed $value Adds value end of array. |
63 | 63 | * @return array<int|string, mixed> New array with value on tail. |
64 | 64 | */ |
65 | - return function ( $value ) use ( $array ): array { |
|
65 | + return function($value) use ($array): array { |
|
66 | 66 | $array[] = $value; |
67 | 67 | return $array; |
68 | 68 | }; |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | * @param array<int|string, mixed> $array The array. |
75 | 75 | * @return mixed Will return the first value is array is not empty, else null. |
76 | 76 | */ |
77 | -function head( array $array ) { |
|
78 | - return ! empty( $array ) ? array_values( $array )[0] : null; |
|
77 | +function head(array $array) { |
|
78 | + return !empty($array) ? array_values($array)[0] : null; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | * @param array<int|string, mixed> $array |
85 | 85 | * @return mixed Will return the last value is array is not empty, else null. |
86 | 86 | */ |
87 | -function tail( array $array ) { |
|
88 | - return ! empty( $array ) ? array_reverse( $array, false )[0] : null; |
|
87 | +function tail(array $array) { |
|
88 | + return !empty($array) ? array_reverse($array, false)[0] : null; |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | * @return Closure(array<int|string, mixed>):string |
97 | 97 | * |
98 | 98 | */ |
99 | -function toString( ?string $glue = null ): Closure { |
|
99 | +function toString(?string $glue = null): Closure { |
|
100 | 100 | /** |
101 | 101 | * @param array<int|string, mixed> $array Array join |
102 | 102 | * @return string. |
103 | 103 | */ |
104 | - return function ( array $array ) use ( $glue ): string { |
|
105 | - return $glue ? \join( $glue, $array ) : \join( $array ); |
|
104 | + return function(array $array) use ($glue) : string { |
|
105 | + return $glue ? \join($glue, $array) : \join($array); |
|
106 | 106 | }; |
107 | 107 | } |
108 | 108 | |
@@ -114,16 +114,16 @@ discard block |
||
114 | 114 | * @return Closure(array<mixed>):array<array{mixed, mixed}> |
115 | 115 | * |
116 | 116 | */ |
117 | -function zip( array $additional, $default = null ): Closure { |
|
118 | - $additional = array_values( $additional ); |
|
119 | - return function ( array $array ) use ( $additional, $default ) { |
|
120 | - $array = array_values( $array ); |
|
117 | +function zip(array $additional, $default = null): Closure { |
|
118 | + $additional = array_values($additional); |
|
119 | + return function(array $array) use ($additional, $default) { |
|
120 | + $array = array_values($array); |
|
121 | 121 | return array_reduce( |
122 | - array_keys( $array ), |
|
123 | - function ( $carry, $key ) use ( $array, $additional, $default ): array { |
|
122 | + array_keys($array), |
|
123 | + function($carry, $key) use ($array, $additional, $default): array { |
|
124 | 124 | $carry[] = array( |
125 | - $array[ $key ], |
|
126 | - array_key_exists( $key, $additional ) ? $additional[ $key ] : $default, |
|
125 | + $array[$key], |
|
126 | + array_key_exists($key, $additional) ? $additional[$key] : $default, |
|
127 | 127 | ); |
128 | 128 | return $carry; |
129 | 129 | }, |
@@ -147,16 +147,16 @@ discard block |
||
147 | 147 | * @param mixed[] $inital Sets up the inner value. |
148 | 148 | * @return Closure |
149 | 149 | */ |
150 | -function arrayCompiler( array $inital = array() ): Closure { |
|
150 | +function arrayCompiler(array $inital = array()): Closure { |
|
151 | 151 | /** |
152 | 152 | * @param mixed $value Adds value to inner array if value set, else returns. |
153 | 153 | * @return mixed[]|Closure |
154 | 154 | */ |
155 | - return function ( $value = null ) use ( $inital ) { |
|
156 | - if ( $value ) { |
|
155 | + return function($value = null) use ($inital) { |
|
156 | + if ($value) { |
|
157 | 157 | $inital[] = $value; |
158 | 158 | } |
159 | - return ! is_null( $value ) ? arrayCompiler( $inital ) : $inital; |
|
159 | + return !is_null($value) ? arrayCompiler($inital) : $inital; |
|
160 | 160 | }; |
161 | 161 | } |
162 | 162 | |
@@ -168,19 +168,19 @@ discard block |
||
168 | 168 | * @param mixed[] $inital The inital data to start with |
169 | 169 | * @return Closure |
170 | 170 | */ |
171 | -function arrayCompilerTyped( callable $validator, array $inital = array() ): Closure { |
|
171 | +function arrayCompilerTyped(callable $validator, array $inital = array()): Closure { |
|
172 | 172 | // Ensure all is validated from initial. |
173 | - $inital = array_filter( $inital, $validator ); |
|
173 | + $inital = array_filter($inital, $validator); |
|
174 | 174 | |
175 | 175 | /** |
176 | 176 | * @param mixed $value |
177 | 177 | * @return mixed[]|Closure |
178 | 178 | */ |
179 | - return function ( $value = null ) use ( $validator, $inital ) { |
|
180 | - if ( ! is_null( $value ) && $validator( $value ) ) { |
|
179 | + return function($value = null) use ($validator, $inital) { |
|
180 | + if (!is_null($value) && $validator($value)) { |
|
181 | 181 | $inital[] = $value; |
182 | 182 | } |
183 | - return ! is_null( $value ) ? arrayCompilerTyped( $validator, $inital ) : $inital; |
|
183 | + return !is_null($value) ? arrayCompilerTyped($validator, $inital) : $inital; |
|
184 | 184 | }; |
185 | 185 | } |
186 | 186 | |
@@ -199,13 +199,13 @@ discard block |
||
199 | 199 | * @param callable $callable The function to apply to the array. |
200 | 200 | * @return Closure(array<int|string, mixed>):array<int|string, mixed> |
201 | 201 | */ |
202 | -function filter( callable $callable ): Closure { |
|
202 | +function filter(callable $callable): Closure { |
|
203 | 203 | /** |
204 | 204 | * @param array<int|string, mixed> $source Array to filter |
205 | 205 | * @return array<int|string, mixed> Filtered array. |
206 | 206 | */ |
207 | - return function ( array $source ) use ( $callable ): array { |
|
208 | - return array_filter( $source, $callable ); |
|
207 | + return function(array $source) use ($callable): array { |
|
208 | + return array_filter($source, $callable); |
|
209 | 209 | }; |
210 | 210 | } |
211 | 211 | |
@@ -215,13 +215,13 @@ discard block |
||
215 | 215 | * @param callable $callable The function to apply to the array. |
216 | 216 | * @return Closure(array<int|string, mixed>):array<int|string, mixed> |
217 | 217 | */ |
218 | -function filterKey( callable $callable ): Closure { |
|
218 | +function filterKey(callable $callable): Closure { |
|
219 | 219 | /** |
220 | 220 | * @param array<int|string, mixed> $source Array to filter |
221 | 221 | * @return array<int|string, mixed> Filtered array. |
222 | 222 | */ |
223 | - return function ( array $source ) use ( $callable ): array { |
|
224 | - return array_filter( $source, $callable, \ARRAY_FILTER_USE_KEY ); |
|
223 | + return function(array $source) use ($callable): array { |
|
224 | + return array_filter($source, $callable, \ARRAY_FILTER_USE_KEY); |
|
225 | 225 | }; |
226 | 226 | } |
227 | 227 | |
@@ -232,13 +232,13 @@ discard block |
||
232 | 232 | * @param callable ...$callables |
233 | 233 | * @return Closure(array<int|string, mixed>):array<int|string, mixed> |
234 | 234 | */ |
235 | -function filterAnd( callable ...$callables ): Closure { |
|
235 | +function filterAnd(callable ...$callables): Closure { |
|
236 | 236 | /** |
237 | 237 | * @param array<int|string, mixed> $source Array to filter |
238 | 238 | * @return array<int|string, mixed> Filtered array. |
239 | 239 | */ |
240 | - return function ( array $source ) use ( $callables ): array { |
|
241 | - return array_filter( $source, Comp\groupAnd( ...$callables ) ); |
|
240 | + return function(array $source) use ($callables): array { |
|
241 | + return array_filter($source, Comp\groupAnd(...$callables)); |
|
242 | 242 | }; |
243 | 243 | } |
244 | 244 | |
@@ -249,13 +249,13 @@ discard block |
||
249 | 249 | * @param callable ...$callables |
250 | 250 | * @return Closure(array<int|string, mixed>):array<int|string, mixed> |
251 | 251 | */ |
252 | -function filterOr( callable ...$callables ): Closure { |
|
252 | +function filterOr(callable ...$callables): Closure { |
|
253 | 253 | /** |
254 | 254 | * @param array<int|string, mixed> $source Array to filter |
255 | 255 | * @return array<int|string, mixed> Filtered array. |
256 | 256 | */ |
257 | - return function ( array $source ) use ( $callables ): array { |
|
258 | - return array_filter( $source, Comp\groupOr( ...$callables ) ); |
|
257 | + return function(array $source) use ($callables): array { |
|
258 | + return array_filter($source, Comp\groupOr(...$callables)); |
|
259 | 259 | }; |
260 | 260 | } |
261 | 261 | |
@@ -265,13 +265,13 @@ discard block |
||
265 | 265 | * @param callable $func |
266 | 266 | * @return Closure(array<int|string, mixed>):?mixed |
267 | 267 | */ |
268 | -function filterFirst( callable $func ): Closure { |
|
268 | +function filterFirst(callable $func): Closure { |
|
269 | 269 | /** |
270 | 270 | * @param array<int|string, mixed> $array The array to filter |
271 | 271 | * @return mixed|null The first element from the filtered array or null if filter returns empty |
272 | 272 | */ |
273 | - return function ( array $array ) use ( $func ) { |
|
274 | - return head( array_filter( $array, $func ) ); |
|
273 | + return function(array $array) use ($func) { |
|
274 | + return head(array_filter($array, $func)); |
|
275 | 275 | }; |
276 | 276 | } |
277 | 277 | |
@@ -281,13 +281,13 @@ discard block |
||
281 | 281 | * @param callable $func |
282 | 282 | * @return Closure(array<int|string, mixed>):?mixed |
283 | 283 | */ |
284 | -function filterLast( callable $func ): Closure { |
|
284 | +function filterLast(callable $func): Closure { |
|
285 | 285 | /** |
286 | 286 | * @param array<int|string, mixed> $array The array to filter |
287 | 287 | * @return mixed|null The last element from the filtered array. |
288 | 288 | */ |
289 | - return function ( array $array ) use ( $func ) { |
|
290 | - return tail( array_filter( $array, $func ) ); |
|
289 | + return function(array $array) use ($func) { |
|
290 | + return tail(array_filter($array, $func)); |
|
291 | 291 | }; |
292 | 292 | } |
293 | 293 | |
@@ -300,13 +300,13 @@ discard block |
||
300 | 300 | * @param callable(mixed):mixed $map Function to map results of filter function. |
301 | 301 | * @return Closure(array<int|string, mixed>):array<int|string, mixed> |
302 | 302 | */ |
303 | -function filterMap( callable $filter, callable $map ): Closure { |
|
303 | +function filterMap(callable $filter, callable $map): Closure { |
|
304 | 304 | /** |
305 | 305 | * @param array<int|string, mixed> $array The array to filter then map. |
306 | 306 | * @return array<int|string, mixed> |
307 | 307 | */ |
308 | - return function ( array $array ) use ( $filter, $map ): array { |
|
309 | - return array_map( $map, array_filter( $array, $filter ) ); |
|
308 | + return function(array $array) use ($filter, $map): array { |
|
309 | + return array_map($map, array_filter($array, $filter)); |
|
310 | 310 | }; |
311 | 311 | } |
312 | 312 | |
@@ -316,13 +316,13 @@ discard block |
||
316 | 316 | * @param callable $function |
317 | 317 | * @return Closure(array<int|string, mixed>):int |
318 | 318 | */ |
319 | -function filterCount( callable $function ): Closure { |
|
319 | +function filterCount(callable $function): Closure { |
|
320 | 320 | /** |
321 | 321 | * @param array<int|string, mixed> $array |
322 | 322 | * @return int Count |
323 | 323 | */ |
324 | - return function ( array $array ) use ( $function ) { |
|
325 | - return count( array_filter( $array, $function ) ); |
|
324 | + return function(array $array) use ($function) { |
|
325 | + return count(array_filter($array, $function)); |
|
326 | 326 | }; |
327 | 327 | } |
328 | 328 | |
@@ -334,12 +334,12 @@ discard block |
||
334 | 334 | * @param callable(mixed):(bool|int) $function |
335 | 335 | * @return Closure(mixed[]):array{0:mixed[], 1:mixed[]} |
336 | 336 | */ |
337 | -function partition( callable $function ): Closure { |
|
337 | +function partition(callable $function): Closure { |
|
338 | 338 | /** |
339 | 339 | * @param mixed[] $array |
340 | 340 | * @return array{0:mixed[], 1:mixed[]} |
341 | 341 | */ |
342 | - return function ( array $array ) use ( $function ): array { |
|
342 | + return function(array $array) use ($function): array { |
|
343 | 343 | return array_reduce( |
344 | 344 | $array, |
345 | 345 | /** |
@@ -347,12 +347,12 @@ discard block |
||
347 | 347 | * @param mixed $element |
348 | 348 | * @return array{0:mixed[], 1:mixed[]} |
349 | 349 | */ |
350 | - function ( $carry, $element ) use ( $function ): array { |
|
351 | - $key = (bool) $function( $element ) ? 1 : 0; |
|
352 | - $carry[ $key ][] = $element; |
|
350 | + function($carry, $element) use ($function): array { |
|
351 | + $key = (bool) $function($element) ? 1 : 0; |
|
352 | + $carry[$key][] = $element; |
|
353 | 353 | return $carry; |
354 | 354 | }, |
355 | - array( array(), array() ) |
|
355 | + array(array(), array()) |
|
356 | 356 | ); |
357 | 357 | }; |
358 | 358 | } |
@@ -363,14 +363,14 @@ discard block |
||
363 | 363 | * @param callable(mixed):bool $function |
364 | 364 | * @return Closure(mixed[]):bool |
365 | 365 | */ |
366 | -function filterAll( callable $function ): Closure { |
|
366 | +function filterAll(callable $function): Closure { |
|
367 | 367 | /** |
368 | 368 | * @param mixed[] $array |
369 | 369 | * @return bool |
370 | 370 | */ |
371 | - return function ( array $array ) use ( $function ): bool { |
|
372 | - foreach ( $array as $value ) { |
|
373 | - if ( false === $function( $value ) ) { |
|
371 | + return function(array $array) use ($function): bool { |
|
372 | + foreach ($array as $value) { |
|
373 | + if (false === $function($value)) { |
|
374 | 374 | return false; |
375 | 375 | } |
376 | 376 | } |
@@ -385,14 +385,14 @@ discard block |
||
385 | 385 | * @param callable(mixed):bool $function |
386 | 386 | * @return Closure(mixed[]):bool |
387 | 387 | */ |
388 | -function filterAny( callable $function ): Closure { |
|
388 | +function filterAny(callable $function): Closure { |
|
389 | 389 | /** |
390 | 390 | * @param mixed[] $array |
391 | 391 | * @return bool |
392 | 392 | */ |
393 | - return function ( array $array ) use ( $function ): bool { |
|
394 | - foreach ( $array as $value ) { |
|
395 | - if ( true === $function( $value ) ) { |
|
393 | + return function(array $array) use ($function): bool { |
|
394 | + foreach ($array as $value) { |
|
395 | + if (true === $function($value)) { |
|
396 | 396 | return true; |
397 | 397 | } |
398 | 398 | } |
@@ -415,13 +415,13 @@ discard block |
||
415 | 415 | * @param callable(mixed):mixed $func Callback to apply to each element in array. |
416 | 416 | * @return Closure(mixed[]):mixed[] |
417 | 417 | */ |
418 | -function map( callable $func ): Closure { |
|
418 | +function map(callable $func): Closure { |
|
419 | 419 | /** |
420 | 420 | * @param mixed[] $array The array to map |
421 | 421 | * @return mixed[] |
422 | 422 | */ |
423 | - return function ( array $array ) use ( $func ): array { |
|
424 | - return array_map( $func, $array ); |
|
423 | + return function(array $array) use ($func): array { |
|
424 | + return array_map($func, $array); |
|
425 | 425 | }; |
426 | 426 | } |
427 | 427 | |
@@ -432,16 +432,16 @@ discard block |
||
432 | 432 | * @param callable $func |
433 | 433 | * @return Closure(mixed[]):mixed[] |
434 | 434 | */ |
435 | -function mapKey( callable $func ): Closure { |
|
435 | +function mapKey(callable $func): Closure { |
|
436 | 436 | /** |
437 | 437 | * @param mixed[] $array The array to map |
438 | 438 | * @return mixed[] |
439 | 439 | */ |
440 | - return function ( array $array ) use ( $func ): array { |
|
440 | + return function(array $array) use ($func): array { |
|
441 | 441 | return array_reduce( |
442 | - array_keys( $array ), |
|
443 | - function ( $carry, $key ) use ( $func, $array ) { |
|
444 | - $carry[ $func( $key ) ] = $array[ $key ]; |
|
442 | + array_keys($array), |
|
443 | + function($carry, $key) use ($func, $array) { |
|
444 | + $carry[$func($key)] = $array[$key]; |
|
445 | 445 | return $carry; |
446 | 446 | }, |
447 | 447 | array() |
@@ -456,15 +456,15 @@ discard block |
||
456 | 456 | * @param mixed ...$data |
457 | 457 | * @return Closure(mixed[]):mixed[] |
458 | 458 | */ |
459 | -function mapWith( callable $func, ...$data ): Closure { |
|
459 | +function mapWith(callable $func, ...$data): Closure { |
|
460 | 460 | /** |
461 | 461 | * @param mixed[] $array The array to map |
462 | 462 | * @return mixed[] |
463 | 463 | */ |
464 | - return function ( array $array ) use ( $func, $data ): array { |
|
464 | + return function(array $array) use ($func, $data): array { |
|
465 | 465 | return array_map( |
466 | - function ( $e ) use ( $data, $func ) { |
|
467 | - return $func( $e, ...$data ); |
|
466 | + function($e) use ($data, $func) { |
|
467 | + return $func($e, ...$data); |
|
468 | 468 | }, |
469 | 469 | $array |
470 | 470 | ); |
@@ -477,18 +477,18 @@ discard block |
||
477 | 477 | * @param callable(int|string $key, mixed $value):mixed $func |
478 | 478 | * @return Closure(mixed[]):mixed[] |
479 | 479 | */ |
480 | -function mapWithKey( callable $func ): Closure { |
|
480 | +function mapWithKey(callable $func): Closure { |
|
481 | 481 | /** |
482 | 482 | * @param mixed[] $array The array to map |
483 | 483 | * @return mixed[] |
484 | 484 | */ |
485 | - return function ( array $array ) use ( $func ): array { |
|
485 | + return function(array $array) use ($func): array { |
|
486 | 486 | return array_map( |
487 | - function ( $key, $value ) use ( $func ) { |
|
488 | - return $func( $value, $key ); |
|
487 | + function($key, $value) use ($func) { |
|
488 | + return $func($value, $key); |
|
489 | 489 | }, |
490 | 490 | $array, |
491 | - array_keys( $array ) |
|
491 | + array_keys($array) |
|
492 | 492 | ); |
493 | 493 | }; |
494 | 494 | } |
@@ -499,17 +499,17 @@ discard block |
||
499 | 499 | * @param callable(int|string $key, mixed $value):void $func |
500 | 500 | * @return Closure(mixed[]):void |
501 | 501 | */ |
502 | -function each( callable $func ): Closure { |
|
502 | +function each(callable $func): Closure { |
|
503 | 503 | /** |
504 | 504 | * @param mixed[] $array The array to map |
505 | 505 | * @return void |
506 | 506 | */ |
507 | - return function ( array $array ) use ( $func ): void { |
|
507 | + return function(array $array) use ($func): void { |
|
508 | 508 | array_map( |
509 | - function ( $key, $value ) use ( $func ) { |
|
510 | - $func( $key, $value ); |
|
509 | + function($key, $value) use ($func) { |
|
510 | + $func($key, $value); |
|
511 | 511 | }, |
512 | - array_keys( $array ), |
|
512 | + array_keys($array), |
|
513 | 513 | $array |
514 | 514 | ); |
515 | 515 | }; |
@@ -522,12 +522,12 @@ discard block |
||
522 | 522 | * @param int|null $n Depth of nodes to flatten. If null will flatten to n |
523 | 523 | * @return Closure(mixed[]):mixed[] |
524 | 524 | */ |
525 | -function flatMap( callable $function, ?int $n = null ): Closure { |
|
525 | +function flatMap(callable $function, ?int $n = null): Closure { |
|
526 | 526 | /** |
527 | 527 | * @param mixed[] $array |
528 | 528 | * @return mixed[] |
529 | 529 | */ |
530 | - return function ( array $array ) use ( $n, $function ): array { |
|
530 | + return function(array $array) use ($n, $function) : array { |
|
531 | 531 | return array_reduce( |
532 | 532 | $array, |
533 | 533 | /** |
@@ -535,11 +535,11 @@ discard block |
||
535 | 535 | * @param mixed $element |
536 | 536 | * @return mixed[] |
537 | 537 | */ |
538 | - function ( array $carry, $element ) use ( $n, $function ): array { |
|
539 | - if ( is_array( $element ) && ( is_null( $n ) || $n > 0 ) ) { |
|
540 | - $carry = array_merge( $carry, flatMap( $function, $n ? $n - 1 : null )( $element ) ); |
|
538 | + function(array $carry, $element) use ($n, $function) : array { |
|
539 | + if (is_array($element) && (is_null($n) || $n > 0)) { |
|
540 | + $carry = array_merge($carry, flatMap($function, $n ? $n - 1 : null)($element)); |
|
541 | 541 | } else { |
542 | - $carry[] = is_array( $element ) ? $element : $function( $element ); |
|
542 | + $carry[] = is_array($element) ? $element : $function($element); |
|
543 | 543 | } |
544 | 544 | return $carry; |
545 | 545 | }, |
@@ -561,12 +561,12 @@ discard block |
||
561 | 561 | * @param callable(mixed):(string|int) $function The function to group by. |
562 | 562 | * @return Closure(mixed):mixed[] |
563 | 563 | */ |
564 | -function groupBy( callable $function ): Closure { |
|
564 | +function groupBy(callable $function): Closure { |
|
565 | 565 | /** |
566 | 566 | * @param mixed[] $array The array to be grouped |
567 | 567 | * @return mixed[] Grouped array. |
568 | 568 | */ |
569 | - return function ( array $array ) use ( $function ): array { |
|
569 | + return function(array $array) use ($function): array { |
|
570 | 570 | return array_reduce( |
571 | 571 | $array, |
572 | 572 | /** |
@@ -574,8 +574,8 @@ discard block |
||
574 | 574 | * @param mixed $element |
575 | 575 | * @return mixed[] |
576 | 576 | */ |
577 | - function ( $carry, $item ) use ( $function ): array { |
|
578 | - $carry[ call_user_func( $function, $item ) ][] = $item; |
|
577 | + function($carry, $item) use ($function): array { |
|
578 | + $carry[call_user_func($function, $item)][] = $item; |
|
579 | 579 | return $carry; |
580 | 580 | }, |
581 | 581 | array() |
@@ -590,13 +590,13 @@ discard block |
||
590 | 590 | * @param bool $preserveKeys Should inital keys be kept. Default false. |
591 | 591 | * @return Closure(mixed[]):mixed[] |
592 | 592 | */ |
593 | -function chunk( int $count, bool $preserveKeys = false ): Closure { |
|
593 | +function chunk(int $count, bool $preserveKeys = false): Closure { |
|
594 | 594 | /** |
595 | 595 | * @param mixed[] $array Array to chunk |
596 | 596 | * @return mixed[] |
597 | 597 | */ |
598 | - return function ( array $array ) use ( $count, $preserveKeys ): array { |
|
599 | - return array_chunk( $array, max( 1, $count ), $preserveKeys ); |
|
598 | + return function(array $array) use ($count, $preserveKeys): array { |
|
599 | + return array_chunk($array, max(1, $count), $preserveKeys); |
|
600 | 600 | }; |
601 | 601 | } |
602 | 602 | |
@@ -607,13 +607,13 @@ discard block |
||
607 | 607 | * @param string $key Use column for assigning as the index. defaults to numeric keys if null. |
608 | 608 | * @return Closure(mixed[]):mixed[] |
609 | 609 | */ |
610 | -function column( string $column, ?string $key = null ): Closure { |
|
610 | +function column(string $column, ?string $key = null): Closure { |
|
611 | 611 | /** |
612 | 612 | * @param mixed[] $array |
613 | 613 | * @return mixed[] |
614 | 614 | */ |
615 | - return function ( array $array ) use ( $column, $key ): array { |
|
616 | - return array_column( $array, $column, $key ); |
|
615 | + return function(array $array) use ($column, $key) : array { |
|
616 | + return array_column($array, $column, $key); |
|
617 | 617 | }; |
618 | 618 | } |
619 | 619 | |
@@ -623,12 +623,12 @@ discard block |
||
623 | 623 | * @param int|null $n Depth of nodes to flatten. If null will flatten to n |
624 | 624 | * @return Closure(mixed[] $var): mixed[] |
625 | 625 | */ |
626 | -function flattenByN( ?int $n = null ): Closure { |
|
626 | +function flattenByN(?int $n = null): Closure { |
|
627 | 627 | /** |
628 | 628 | * @param mixed[] $array Array to flatten |
629 | 629 | * @return mixed[] |
630 | 630 | */ |
631 | - return function ( array $array ) use ( $n ): array { |
|
631 | + return function(array $array) use ($n) : array { |
|
632 | 632 | return array_reduce( |
633 | 633 | $array, |
634 | 634 | /** |
@@ -636,14 +636,14 @@ discard block |
||
636 | 636 | * @param mixed|mixed[] $element |
637 | 637 | * @return array<int|string, mixed> |
638 | 638 | */ |
639 | - function ( array $carry, $element ) use ( $n ): array { |
|
639 | + function(array $carry, $element) use ($n) : array { |
|
640 | 640 | // Remove empty arrays. |
641 | - if ( is_array( $element ) && empty( $element ) ) { |
|
641 | + if (is_array($element) && empty($element)) { |
|
642 | 642 | return $carry; |
643 | 643 | } |
644 | 644 | // If the element is an array and we are still flattening, call again |
645 | - if ( is_array( $element ) && ( is_null( $n ) || $n > 0 ) ) { // @phpstan-ignore-line |
|
646 | - $carry = array_merge( $carry, flattenByN( $n ? $n - 1 : null )( $element ) ); |
|
645 | + if (is_array($element) && (is_null($n) || $n > 0)) { // @phpstan-ignore-line |
|
646 | + $carry = array_merge($carry, flattenByN($n ? $n - 1 : null)($element)); |
|
647 | 647 | } else { |
648 | 648 | // Else just add the element. |
649 | 649 | $carry[] = $element; |
@@ -661,13 +661,13 @@ discard block |
||
661 | 661 | * @param mixed[] ...$with The array values to replace with |
662 | 662 | * @return Closure(mixed[]):mixed[] |
663 | 663 | */ |
664 | -function replaceRecursive( array ...$with ): Closure { |
|
664 | +function replaceRecursive(array ...$with): Closure { |
|
665 | 665 | /** |
666 | 666 | * @param mixed[] $array The array to have elements replaced from. |
667 | 667 | * @return mixed[] Array with replacements. |
668 | 668 | */ |
669 | - return function ( array $array ) use ( $with ): array { |
|
670 | - return array_replace_recursive( $array, ...$with ); |
|
669 | + return function(array $array) use ($with): array { |
|
670 | + return array_replace_recursive($array, ...$with); |
|
671 | 671 | }; |
672 | 672 | } |
673 | 673 | |
@@ -677,13 +677,13 @@ discard block |
||
677 | 677 | * @param mixed[] ...$with Array with values to replace with, must have matching key with base array. |
678 | 678 | * @return Closure(mixed[]):mixed[] |
679 | 679 | */ |
680 | -function replace( array ...$with ): Closure { |
|
680 | +function replace(array ...$with): Closure { |
|
681 | 681 | /** |
682 | 682 | * @param mixed[] $array The array to have elements replaced from. |
683 | 683 | * @return mixed[] Array with replacements. |
684 | 684 | */ |
685 | - return function ( array $array ) use ( $with ): array { |
|
686 | - return array_replace( $array, ...$with ); |
|
685 | + return function(array $array) use ($with): array { |
|
686 | + return array_replace($array, ...$with); |
|
687 | 687 | }; |
688 | 688 | } |
689 | 689 | |
@@ -693,13 +693,13 @@ discard block |
||
693 | 693 | * @param callable(mixed):Number $function The function to return the value for array sum |
694 | 694 | * @return Closure(mixed[]):Number |
695 | 695 | */ |
696 | -function sumWhere( callable $function ): Closure { |
|
696 | +function sumWhere(callable $function): Closure { |
|
697 | 697 | /** |
698 | 698 | * @param mixed[] $array Array to do sum() on. |
699 | 699 | * @return Number The total. |
700 | 700 | */ |
701 | - return function ( array $array ) use ( $function ) { |
|
702 | - return array_sum( array_map( $function, $array ) ); |
|
701 | + return function(array $array) use ($function) { |
|
702 | + return array_sum(array_map($function, $array)); |
|
703 | 703 | }; |
704 | 704 | } |
705 | 705 | |
@@ -712,24 +712,24 @@ discard block |
||
712 | 712 | * @return Closure(mixed[]):object |
713 | 713 | * @throws InvalidArgumentException If property does not exist or is not public. |
714 | 714 | */ |
715 | -function toObject( ?object $object = null ): Closure { |
|
715 | +function toObject(?object $object = null): Closure { |
|
716 | 716 | $object = $object ?? new stdClass(); |
717 | 717 | |
718 | 718 | /** |
719 | 719 | * @param mixed[] $array |
720 | 720 | * @return object |
721 | 721 | */ |
722 | - return function ( array $array ) use ( $object ): object { |
|
723 | - foreach ( $array as $key => $value ) { |
|
722 | + return function(array $array) use ($object): object { |
|
723 | + foreach ($array as $key => $value) { |
|
724 | 724 | // If key is not a string or numerical, skip it. |
725 | - if ( ! is_string( $key ) || is_numeric( $key ) ) { |
|
725 | + if (!is_string($key) || is_numeric($key)) { |
|
726 | 726 | continue; |
727 | 727 | } |
728 | 728 | |
729 | 729 | try { |
730 | 730 | $object->{$key} = $value; |
731 | - } catch ( \Throwable $th ) { |
|
732 | - throw new \InvalidArgumentException( "Property {$key} does not exist or is not public." ); |
|
731 | + } catch (\Throwable $th) { |
|
732 | + throw new \InvalidArgumentException("Property {$key} does not exist or is not public."); |
|
733 | 733 | } |
734 | 734 | } |
735 | 735 | return $object; |
@@ -749,13 +749,13 @@ discard block |
||
749 | 749 | * JSON_PRETTY_PRINT, JSON_UNESCAPED_LINE_TERMINATORS, |
750 | 750 | * JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE, JSON_THROW_ON_ERROR |
751 | 751 | */ |
752 | -function toJson( int $flags = 0, int $depth = 512 ): Closure { |
|
752 | +function toJson(int $flags = 0, int $depth = 512): Closure { |
|
753 | 753 | /** |
754 | 754 | * @param mixed $data |
755 | 755 | * @return string|null |
756 | 756 | */ |
757 | - return function ( $data ) use ( $flags, $depth ): ?string { |
|
758 | - return \json_encode( $data, $flags, max( 1, $depth ) ) ?: null; |
|
757 | + return function($data) use ($flags, $depth): ?string { |
|
758 | + return \json_encode($data, $flags, max(1, $depth)) ?: null; |
|
759 | 759 | }; |
760 | 760 | } |
761 | 761 | |
@@ -774,13 +774,13 @@ discard block |
||
774 | 774 | * @param int $flag Uses php stock sort constants or numerical values. |
775 | 775 | * @return Closure(mixed[]):mixed[] |
776 | 776 | */ |
777 | -function sort( int $flag = SORT_REGULAR ): Closure { |
|
777 | +function sort(int $flag = SORT_REGULAR): Closure { |
|
778 | 778 | /** |
779 | 779 | * @param mixed[]$array The array to sort |
780 | 780 | * @return mixed[] The sorted array (new array) |
781 | 781 | */ |
782 | - return function ( array $array ) use ( $flag ) { |
|
783 | - \sort( $array, $flag ); |
|
782 | + return function(array $array) use ($flag) { |
|
783 | + \sort($array, $flag); |
|
784 | 784 | return $array; |
785 | 785 | }; |
786 | 786 | } |
@@ -792,13 +792,13 @@ discard block |
||
792 | 792 | * @param int $flag Uses php stock sort constants or numerical values. |
793 | 793 | * @return Closure(mixed[]):mixed[] |
794 | 794 | */ |
795 | -function rsort( int $flag = SORT_REGULAR ): Closure { |
|
795 | +function rsort(int $flag = SORT_REGULAR): Closure { |
|
796 | 796 | /** |
797 | 797 | * @param mixed[]$array The array to sort |
798 | 798 | * @return mixed[] The sorted array (new array) |
799 | 799 | */ |
800 | - return function ( array $array ) use ( $flag ) { |
|
801 | - \rsort( $array, $flag ); |
|
800 | + return function(array $array) use ($flag) { |
|
801 | + \rsort($array, $flag); |
|
802 | 802 | return $array; |
803 | 803 | }; |
804 | 804 | } |
@@ -810,13 +810,13 @@ discard block |
||
810 | 810 | * @param int $flag Uses php stock sort constants or numerical values. |
811 | 811 | * @return Closure(mixed[]):mixed[] |
812 | 812 | */ |
813 | -function ksort( int $flag = SORT_REGULAR ): Closure { |
|
813 | +function ksort(int $flag = SORT_REGULAR): Closure { |
|
814 | 814 | /** |
815 | 815 | * @param mixed[]$array The array to sort |
816 | 816 | * @return mixed[] The sorted array (new array) |
817 | 817 | */ |
818 | - return function ( array $array ) use ( $flag ) { |
|
819 | - \ksort( $array, $flag ); |
|
818 | + return function(array $array) use ($flag) { |
|
819 | + \ksort($array, $flag); |
|
820 | 820 | return $array; |
821 | 821 | }; |
822 | 822 | } |
@@ -827,13 +827,13 @@ discard block |
||
827 | 827 | * @param int $flag Uses php stock sort constants or numerical values. |
828 | 828 | * @return Closure(mixed[]):mixed[] |
829 | 829 | */ |
830 | -function krsort( int $flag = SORT_REGULAR ): Closure { |
|
830 | +function krsort(int $flag = SORT_REGULAR): Closure { |
|
831 | 831 | /** |
832 | 832 | * @param mixed[]$array The array to sort |
833 | 833 | * @return mixed[] The sorted array (new array) |
834 | 834 | */ |
835 | - return function ( array $array ) use ( $flag ) { |
|
836 | - \krsort( $array, $flag ); |
|
835 | + return function(array $array) use ($flag) { |
|
836 | + \krsort($array, $flag); |
|
837 | 837 | return $array; |
838 | 838 | }; |
839 | 839 | } |
@@ -845,13 +845,13 @@ discard block |
||
845 | 845 | * @param int $flag Uses php stock sort constants or numerical values. |
846 | 846 | * @return Closure(mixed[]):mixed[] |
847 | 847 | */ |
848 | -function asort( int $flag = SORT_REGULAR ): Closure { |
|
848 | +function asort(int $flag = SORT_REGULAR): Closure { |
|
849 | 849 | /** |
850 | 850 | * @param mixed[]$array The array to sort |
851 | 851 | * @return mixed[] The sorted array (new array) |
852 | 852 | */ |
853 | - return function ( array $array ) use ( $flag ) { |
|
854 | - \asort( $array, $flag ); |
|
853 | + return function(array $array) use ($flag) { |
|
854 | + \asort($array, $flag); |
|
855 | 855 | return $array; |
856 | 856 | }; |
857 | 857 | } |
@@ -863,13 +863,13 @@ discard block |
||
863 | 863 | * @param int $flag Uses php stock sort constants or numerical values. |
864 | 864 | * @return Closure(mixed[]):mixed[] |
865 | 865 | */ |
866 | -function arsort( int $flag = SORT_REGULAR ): Closure { |
|
866 | +function arsort(int $flag = SORT_REGULAR): Closure { |
|
867 | 867 | /** |
868 | 868 | * @param mixed[]$array The array to sort |
869 | 869 | * @return mixed[] The sorted array (new array) |
870 | 870 | */ |
871 | - return function ( array $array ) use ( $flag ) { |
|
872 | - \arsort( $array, $flag ); |
|
871 | + return function(array $array) use ($flag) { |
|
872 | + \arsort($array, $flag); |
|
873 | 873 | return $array; |
874 | 874 | }; |
875 | 875 | } |
@@ -884,8 +884,8 @@ discard block |
||
884 | 884 | * @param mixed[]$array The array to sort |
885 | 885 | * @return mixed[] The sorted array (new array) |
886 | 886 | */ |
887 | - return function ( array $array ) { |
|
888 | - \natsort( $array ); |
|
887 | + return function(array $array) { |
|
888 | + \natsort($array); |
|
889 | 889 | return $array; |
890 | 890 | }; |
891 | 891 | } |
@@ -900,8 +900,8 @@ discard block |
||
900 | 900 | * @param mixed[]$array The array to sort |
901 | 901 | * @return mixed[] The sorted array (new array) |
902 | 902 | */ |
903 | - return function ( array $array ) { |
|
904 | - \natcasesort( $array ); |
|
903 | + return function(array $array) { |
|
904 | + \natcasesort($array); |
|
905 | 905 | return $array; |
906 | 906 | }; |
907 | 907 | } |
@@ -912,13 +912,13 @@ discard block |
||
912 | 912 | * @param callable(mixed $a, mixed $b): int $function |
913 | 913 | * @return Closure(mixed[]):mixed[] |
914 | 914 | */ |
915 | -function uksort( callable $function ): Closure { |
|
915 | +function uksort(callable $function): Closure { |
|
916 | 916 | /** |
917 | 917 | * @param mixed[] $array The array to sort |
918 | 918 | * @return mixed[] The sorted array (new array) |
919 | 919 | */ |
920 | - return function ( array $array ) use ( $function ) { |
|
921 | - \uksort( $array, $function ); |
|
920 | + return function(array $array) use ($function) { |
|
921 | + \uksort($array, $function); |
|
922 | 922 | return $array; |
923 | 923 | }; |
924 | 924 | } |
@@ -930,13 +930,13 @@ discard block |
||
930 | 930 | * @param callable(mixed $a, mixed $b): int $function |
931 | 931 | * @return Closure(mixed[]):mixed[] |
932 | 932 | */ |
933 | -function uasort( callable $function ): Closure { |
|
933 | +function uasort(callable $function): Closure { |
|
934 | 934 | /** |
935 | 935 | * @param mixed[]$array The array to sort |
936 | 936 | * @return mixed[] The sorted array (new array) |
937 | 937 | */ |
938 | - return function ( array $array ) use ( $function ) { |
|
939 | - \uasort( $array, $function ); |
|
938 | + return function(array $array) use ($function) { |
|
939 | + \uasort($array, $function); |
|
940 | 940 | return $array; |
941 | 941 | }; |
942 | 942 | } |
@@ -949,13 +949,13 @@ discard block |
||
949 | 949 | * @param callable(mixed $a, mixed $b): int $function |
950 | 950 | * @return Closure(mixed[]):mixed[] |
951 | 951 | */ |
952 | -function usort( callable $function ): Closure { |
|
952 | +function usort(callable $function): Closure { |
|
953 | 953 | /** |
954 | 954 | * @param mixed[]$array The array to sort |
955 | 955 | * @return mixed[] The sorted array (new array) |
956 | 956 | */ |
957 | - return function ( array $array ) use ( $function ) { |
|
958 | - \usort( $array, $function ); |
|
957 | + return function(array $array) use ($function) { |
|
958 | + \usort($array, $function); |
|
959 | 959 | return $array; |
960 | 960 | }; |
961 | 961 | } |
@@ -967,11 +967,11 @@ discard block |
||
967 | 967 | * @param mixed $initialValue |
968 | 968 | * @return Closure(mixed[]):mixed[] |
969 | 969 | */ |
970 | -function scan( callable $function, $initialValue ): Closure { |
|
971 | - return function ( array $array ) use ( $function, $initialValue ) { |
|
970 | +function scan(callable $function, $initialValue): Closure { |
|
971 | + return function(array $array) use ($function, $initialValue) { |
|
972 | 972 | $carry[] = $initialValue; |
973 | - foreach ( $array as $key => $value ) { |
|
974 | - $initialValue = $function( $initialValue, $value ); |
|
973 | + foreach ($array as $key => $value) { |
|
974 | + $initialValue = $function($initialValue, $value); |
|
975 | 975 | $carry[] = $initialValue; |
976 | 976 | } |
977 | 977 | return $carry; |
@@ -985,14 +985,14 @@ discard block |
||
985 | 985 | * @param mixed $initialValue |
986 | 986 | * @return Closure(mixed[]):mixed[] |
987 | 987 | */ |
988 | -function scanR( callable $function, $initialValue ): Closure { |
|
989 | - return function ( array $array ) use ( $function, $initialValue ) { |
|
988 | +function scanR(callable $function, $initialValue): Closure { |
|
989 | + return function(array $array) use ($function, $initialValue) { |
|
990 | 990 | $carry[] = $initialValue; |
991 | - foreach ( array_reverse( $array ) as $key => $value ) { |
|
992 | - $initialValue = $function( $initialValue, $value ); |
|
991 | + foreach (array_reverse($array) as $key => $value) { |
|
992 | + $initialValue = $function($initialValue, $value); |
|
993 | 993 | $carry[] = $initialValue; |
994 | 994 | } |
995 | - return \array_reverse( $carry ); |
|
995 | + return \array_reverse($carry); |
|
996 | 996 | }; |
997 | 997 | } |
998 | 998 | |
@@ -1003,13 +1003,13 @@ discard block |
||
1003 | 1003 | * @param mixed $initial |
1004 | 1004 | * @return Closure(mixed[]):mixed |
1005 | 1005 | */ |
1006 | -function fold( callable $callable, $initial = array() ): Closure { |
|
1006 | +function fold(callable $callable, $initial = array()): Closure { |
|
1007 | 1007 | /** |
1008 | 1008 | * @param mixed[] $array |
1009 | 1009 | * @return mixed |
1010 | 1010 | */ |
1011 | - return function ( array $array ) use ( $callable, $initial ) { |
|
1012 | - return array_reduce( $array, $callable, $initial ); |
|
1011 | + return function(array $array) use ($callable, $initial) { |
|
1012 | + return array_reduce($array, $callable, $initial); |
|
1013 | 1013 | }; |
1014 | 1014 | } |
1015 | 1015 | |
@@ -1020,13 +1020,13 @@ discard block |
||
1020 | 1020 | * @param mixed $initial |
1021 | 1021 | * @return Closure(mixed[]):mixed |
1022 | 1022 | */ |
1023 | -function foldR( callable $callable, $initial = array() ): Closure { |
|
1023 | +function foldR(callable $callable, $initial = array()): Closure { |
|
1024 | 1024 | /** |
1025 | 1025 | * @param mixed[] $array |
1026 | 1026 | * @return mixed |
1027 | 1027 | */ |
1028 | - return function ( array $array ) use ( $callable, $initial ) { |
|
1029 | - return array_reduce( \array_reverse( $array ), $callable, $initial ); |
|
1028 | + return function(array $array) use ($callable, $initial) { |
|
1029 | + return array_reduce(\array_reverse($array), $callable, $initial); |
|
1030 | 1030 | }; |
1031 | 1031 | } |
1032 | 1032 | |
@@ -1038,14 +1038,14 @@ discard block |
||
1038 | 1038 | * @param mixed $initial |
1039 | 1039 | * @return Closure(mixed[]):mixed |
1040 | 1040 | */ |
1041 | -function foldKeys( callable $callable, $initial = array() ): Closure { |
|
1041 | +function foldKeys(callable $callable, $initial = array()): Closure { |
|
1042 | 1042 | /** |
1043 | 1043 | * @param mixed[] $array |
1044 | 1044 | * @return mixed |
1045 | 1045 | */ |
1046 | - return function ( array $array ) use ( $callable, $initial ) { |
|
1047 | - foreach ( $array as $key => $value ) { |
|
1048 | - $initial = $callable( $initial, $key, $value ); |
|
1046 | + return function(array $array) use ($callable, $initial) { |
|
1047 | + foreach ($array as $key => $value) { |
|
1048 | + $initial = $callable($initial, $key, $value); |
|
1049 | 1049 | } |
1050 | 1050 | return $initial; |
1051 | 1051 | }; |
@@ -1058,18 +1058,18 @@ discard block |
||
1058 | 1058 | * @return Closure(mixed[]):mixed[] |
1059 | 1059 | * @throws \InvalidArgumentException if count is negative |
1060 | 1060 | */ |
1061 | -function take( int $count = 1 ): Closure { |
|
1061 | +function take(int $count = 1): Closure { |
|
1062 | 1062 | // throw InvalidArgumentException if count is negative |
1063 | - if ( $count < 0 ) { |
|
1064 | - throw new \InvalidArgumentException( __FUNCTION__ . ' count must be greater than or equal to 0' ); |
|
1063 | + if ($count < 0) { |
|
1064 | + throw new \InvalidArgumentException(__FUNCTION__ . ' count must be greater than or equal to 0'); |
|
1065 | 1065 | } |
1066 | 1066 | |
1067 | 1067 | /** |
1068 | 1068 | * @param mixed[] $array |
1069 | 1069 | * @return mixed[] |
1070 | 1070 | */ |
1071 | - return function ( array $array ) use ( $count ) { |
|
1072 | - return \array_slice( $array, 0, $count ); |
|
1071 | + return function(array $array) use ($count) { |
|
1072 | + return \array_slice($array, 0, $count); |
|
1073 | 1073 | }; |
1074 | 1074 | } |
1075 | 1075 | |
@@ -1080,15 +1080,15 @@ discard block |
||
1080 | 1080 | * @return Closure(mixed[]):mixed[] |
1081 | 1081 | * @throws \InvalidArgumentException if count is negative |
1082 | 1082 | */ |
1083 | -function takeLast( int $count = 1 ): Closure { |
|
1083 | +function takeLast(int $count = 1): Closure { |
|
1084 | 1084 | // throw InvalidArgumentException if count is negative |
1085 | - if ( $count < 0 ) { |
|
1086 | - throw new \InvalidArgumentException( __FUNCTION__ . ' count must be greater than or equal to 0' ); |
|
1085 | + if ($count < 0) { |
|
1086 | + throw new \InvalidArgumentException(__FUNCTION__ . ' count must be greater than or equal to 0'); |
|
1087 | 1087 | } |
1088 | 1088 | |
1089 | 1089 | // If count is 0, return an empty array |
1090 | - if ( $count === 0 ) { |
|
1091 | - return function ( array $array ) { |
|
1090 | + if ($count === 0) { |
|
1091 | + return function(array $array) { |
|
1092 | 1092 | return array(); |
1093 | 1093 | }; |
1094 | 1094 | } |
@@ -1097,8 +1097,8 @@ discard block |
||
1097 | 1097 | * @param mixed[] $array |
1098 | 1098 | * @return mixed[] |
1099 | 1099 | */ |
1100 | - return function ( array $array ) use ( $count ) { |
|
1101 | - return \array_slice( $array, - $count ); |
|
1100 | + return function(array $array) use ($count) { |
|
1101 | + return \array_slice($array, - $count); |
|
1102 | 1102 | }; |
1103 | 1103 | } |
1104 | 1104 | |
@@ -1109,18 +1109,18 @@ discard block |
||
1109 | 1109 | * @param callable(mixed): bool $conditional |
1110 | 1110 | * @return Closure(mixed[]):mixed[] |
1111 | 1111 | */ |
1112 | -function takeUntil( callable $conditional ): Closure { |
|
1112 | +function takeUntil(callable $conditional): Closure { |
|
1113 | 1113 | /** |
1114 | 1114 | * @param mixed[] $array |
1115 | 1115 | * @return mixed[] |
1116 | 1116 | */ |
1117 | - return function ( array $array ) use ( $conditional ) { |
|
1117 | + return function(array $array) use ($conditional) { |
|
1118 | 1118 | $carry = array(); |
1119 | - foreach ( $array as $key => $value ) { |
|
1120 | - if ( true === $conditional( $value ) ) { |
|
1119 | + foreach ($array as $key => $value) { |
|
1120 | + if (true === $conditional($value)) { |
|
1121 | 1121 | break; |
1122 | 1122 | } |
1123 | - $carry[ $key ] = $value; |
|
1123 | + $carry[$key] = $value; |
|
1124 | 1124 | } |
1125 | 1125 | return $carry; |
1126 | 1126 | }; |
@@ -1133,18 +1133,18 @@ discard block |
||
1133 | 1133 | * @param callable(mixed): bool $conditional |
1134 | 1134 | * @return Closure(mixed[]):mixed[] |
1135 | 1135 | */ |
1136 | -function takeWhile( callable $conditional ): Closure { |
|
1136 | +function takeWhile(callable $conditional): Closure { |
|
1137 | 1137 | /** |
1138 | 1138 | * @param mixed[] $array |
1139 | 1139 | * @return mixed[] |
1140 | 1140 | */ |
1141 | - return function ( array $array ) use ( $conditional ) { |
|
1141 | + return function(array $array) use ($conditional) { |
|
1142 | 1142 | $carry = array(); |
1143 | - foreach ( $array as $key => $value ) { |
|
1144 | - if ( false === $conditional( $value ) ) { |
|
1143 | + foreach ($array as $key => $value) { |
|
1144 | + if (false === $conditional($value)) { |
|
1145 | 1145 | break; |
1146 | 1146 | } |
1147 | - $carry[ $key ] = $value; |
|
1147 | + $carry[$key] = $value; |
|
1148 | 1148 | } |
1149 | 1149 | return $carry; |
1150 | 1150 | }; |