@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | |
114 | 114 | // Convert objects to arrays |
115 | 115 | if (\is_object($data)) { |
116 | - $data = (array) $data; |
|
116 | + $data = (array)$data; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | // Don't convert if it's not an array |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | |
138 | 138 | // Else add values |
139 | 139 | foreach ($row as $key => $value) { |
140 | - $row[$key] = '"'.stripslashes((string) $value).'"'; |
|
140 | + $row[$key] = '"'.stripslashes((string)$value).'"'; |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | $csv[] = implode($delimiter, $row); |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | $data = $data->toArray(); |
162 | 162 | } |
163 | 163 | |
164 | - return (array) $data; |
|
164 | + return (array)$data; |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | return static::toJSON($data); |
178 | 178 | } |
179 | 179 | |
180 | - return (string) $data; |
|
180 | + return (string)$data; |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | return \strlen($data); |
198 | 198 | } |
199 | 199 | |
200 | - return (int) $data; |
|
200 | + return (int)$data; |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | */ |
208 | 208 | public static function toBoolean(mixed $data) : bool |
209 | 209 | { |
210 | - return (bool) $data; |
|
210 | + return (bool)$data; |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | */ |
218 | 218 | public static function toObject(mixed $data) : object |
219 | 219 | { |
220 | - return (object) $data; |
|
220 | + return (object)$data; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | //////////////////////////////////////////////////////////////////// |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @param string $value |
67 | 67 | * |
68 | 68 | */ |
69 | - public static function search(array $array, mixed $value) : int|string|bool |
|
69 | + public static function search(array $array, mixed $value) : int | string | bool |
|
70 | 70 | { |
71 | 71 | return array_search($value, $array, true); |
72 | 72 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | */ |
200 | 200 | public static function clean(array $array) : mixed |
201 | 201 | { |
202 | - return static::filter($array, fn($value) : bool => (bool) $value); |
|
202 | + return static::filter($array, fn($value) : bool => (bool)$value); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | */ |
225 | 225 | public static function without(...$arguments): mixed |
226 | 226 | { |
227 | - $array = array_shift($arguments); |
|
227 | + $array = array_shift($arguments); |
|
228 | 228 | // if singular argument and is an array treat this AS the array to run without agains |
229 | 229 | if (\is_array($arguments[0]) && \count($arguments) === 1) { |
230 | 230 | $arguments = $arguments[0]; |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | */ |
333 | 333 | public static function replaceValue(array $array, string $replace, string $with) : array |
334 | 334 | { |
335 | - return static::each($array, fn($value) : string|array => str_replace($replace, $with, (string) $value)); |
|
335 | + return static::each($array, fn($value) : string | array => str_replace($replace, $with, (string)$value)); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | /** |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | * @param array $arguments |
459 | 459 | * |
460 | 460 | */ |
461 | - public static function invoke(array $array, Closure|string $callable, mixed $arguments = []) : array |
|
461 | + public static function invoke(array $array, Closure | string $callable, mixed $arguments = []) : array |
|
462 | 462 | { |
463 | 463 | // If one argument given for each iteration, create an array for it |
464 | 464 | if ( ! \is_array($arguments)) { |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | */ |
565 | 565 | public static function unique(array $array) : array |
566 | 566 | { |
567 | - return array_reduce($array, function (array $resultArray, $value) : array { |
|
567 | + return array_reduce($array, function(array $resultArray, $value) : array { |
|
568 | 568 | if ( ! static::contains($resultArray, $value)) { |
569 | 569 | $resultArray[] = $value; |
570 | 570 | } |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | $unique = random_int(0, mt_getrandmax()); |
67 | 67 | |
68 | 68 | // Create a closure that check if the function was already called |
69 | - return function (...$arguments) use ($function, $canBeCalledTimes, $unique) { |
|
69 | + return function(...$arguments) use ($function, $canBeCalledTimes, $unique) { |
|
70 | 70 | |
71 | - $signature = FunctionsMethods::getSignature((string) $unique, $function, $arguments); |
|
71 | + $signature = FunctionsMethods::getSignature((string)$unique, $function, $arguments); |
|
72 | 72 | |
73 | 73 | // Get counter |
74 | 74 | $numberOfTimesCalled = FunctionsMethods::hasBeenCalledTimes($signature); |
@@ -77,9 +77,7 @@ discard block |
||
77 | 77 | // Else, increment the count |
78 | 78 | if ($numberOfTimesCalled >= $canBeCalledTimes) { |
79 | 79 | return false; |
80 | - } |
|
81 | - |
|
82 | - ++FunctionsMethods::$canBeCalledTimes[$signature]; |
|
80 | + }++FunctionsMethods::$canBeCalledTimes[$signature]; |
|
83 | 81 | |
84 | 82 | return \call_user_func_array($function, $arguments); |
85 | 83 | }; |
@@ -97,16 +95,15 @@ discard block |
||
97 | 95 | $unique = random_int(0, mt_getrandmax()); |
98 | 96 | |
99 | 97 | // Create a closure that check if the function was already called |
100 | - return function (...$arguments) use ($function, $times, $unique) { |
|
98 | + return function(...$arguments) use ($function, $times, $unique) { |
|
101 | 99 | |
102 | - $signature = FunctionsMethods::getSignature((string) $unique, $function, $arguments); |
|
100 | + $signature = FunctionsMethods::getSignature((string)$unique, $function, $arguments); |
|
103 | 101 | |
104 | 102 | // Get counter |
105 | 103 | $called = FunctionsMethods::hasBeenCalledTimes($signature); |
106 | 104 | |
107 | 105 | // Prevent calling before a certain number |
108 | - if ($called < $times) { |
|
109 | - ++FunctionsMethods::$canBeCalledTimes[$signature]; |
|
106 | + if ($called < $times) {++FunctionsMethods::$canBeCalledTimes[$signature]; |
|
110 | 107 | |
111 | 108 | return false; |
112 | 109 | } |
@@ -126,9 +123,9 @@ discard block |
||
126 | 123 | { |
127 | 124 | $unique = random_int(0, mt_getrandmax()); |
128 | 125 | |
129 | - return function (...$arguments) use ($function, $unique) { |
|
126 | + return function(...$arguments) use ($function, $unique) { |
|
130 | 127 | |
131 | - $signature = FunctionsMethods::getSignature((string) $unique, $function, $arguments); |
|
128 | + $signature = FunctionsMethods::getSignature((string)$unique, $function, $arguments); |
|
132 | 129 | |
133 | 130 | if (isset(FunctionsMethods::$cached[$signature])) { |
134 | 131 | return FunctionsMethods::$cached[$signature]; |
@@ -152,9 +149,9 @@ discard block |
||
152 | 149 | { |
153 | 150 | $unique = random_int(0, mt_getrandmax()); |
154 | 151 | |
155 | - return function (...$arguments) use ($function, $ms, $unique) { |
|
152 | + return function(...$arguments) use ($function, $ms, $unique) { |
|
156 | 153 | |
157 | - $signature = FunctionsMethods::getSignature((string) $unique, $function, $arguments); |
|
154 | + $signature = FunctionsMethods::getSignature((string)$unique, $function, $arguments); |
|
158 | 155 | |
159 | 156 | // Check last called time and update it if necessary |
160 | 157 | $last = FunctionsMethods::getLastCalledTime($signature); |
@@ -227,7 +224,7 @@ discard block |
||
227 | 224 | */ |
228 | 225 | public static function getSignature(string $unique, Closure $function, array $arguments) : string |
229 | 226 | { |
230 | - $function = var_export($function, true); |
|
227 | + $function = var_export($function, true); |
|
231 | 228 | $argumentsStr = var_export($arguments, true); |
232 | 229 | |
233 | 230 | return md5($unique.'_'.$function.'_'.$argumentsStr); |
@@ -170,10 +170,10 @@ discard block |
||
170 | 170 | * |
171 | 171 | * |
172 | 172 | */ |
173 | - public static function endsWith(string $haystack, array|string $needles) : bool |
|
173 | + public static function endsWith(string $haystack, array | string $needles) : bool |
|
174 | 174 | { |
175 | - foreach ((array) $needles as $needle) { |
|
176 | - if (str_ends_with($haystack, (string) $needle)) { |
|
175 | + foreach ((array)$needles as $needle) { |
|
176 | + if (str_ends_with($haystack, (string)$needle)) { |
|
177 | 177 | return true; |
178 | 178 | } |
179 | 179 | } |
@@ -218,10 +218,10 @@ discard block |
||
218 | 218 | * |
219 | 219 | * |
220 | 220 | */ |
221 | - public static function startsWith(string $haystack, array|string $needles) : bool |
|
221 | + public static function startsWith(string $haystack, array | string $needles) : bool |
|
222 | 222 | { |
223 | - foreach ((array) $needles as $needle) { |
|
224 | - if ($needle !== '' && str_starts_with($haystack, (string) $needle)) { |
|
223 | + foreach ((array)$needles as $needle) { |
|
224 | + if ($needle !== '' && str_starts_with($haystack, (string)$needle)) { |
|
225 | 225 | return true; |
226 | 226 | } |
227 | 227 | } |
@@ -244,8 +244,8 @@ discard block |
||
244 | 244 | * @return bool Found or not |
245 | 245 | */ |
246 | 246 | public static function find( |
247 | - array|string $string, |
|
248 | - array|string $needle, |
|
247 | + array | string $string, |
|
248 | + array | string $needle, |
|
249 | 249 | bool $caseSensitive = false, |
250 | 250 | bool $absolute = false |
251 | 251 | ) : bool |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | } |
272 | 272 | |
273 | 273 | // If not case sensitive |
274 | - if (!$caseSensitive) { |
|
274 | + if ( ! $caseSensitive) { |
|
275 | 275 | $string = strtolower($string); |
276 | 276 | $needle = strtolower($needle); |
277 | 277 | } |
@@ -304,11 +304,11 @@ discard block |
||
304 | 304 | * |
305 | 305 | * @return false|string |
306 | 306 | */ |
307 | - public static function sliceFrom($string, $slice) : bool|string |
|
307 | + public static function sliceFrom($string, $slice) : bool | string |
|
308 | 308 | { |
309 | - $slice = strpos((string) $string, (string) $slice); |
|
309 | + $slice = strpos((string)$string, (string)$slice); |
|
310 | 310 | |
311 | - return substr((string) $string, $slice); |
|
311 | + return substr((string)$string, $slice); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | /** |
@@ -319,11 +319,11 @@ discard block |
||
319 | 319 | * |
320 | 320 | * @return false|string |
321 | 321 | */ |
322 | - public static function sliceTo($string, $slice) : bool|string |
|
322 | + public static function sliceTo($string, $slice) : bool | string |
|
323 | 323 | { |
324 | - $slice = strpos((string) $string, (string) $slice); |
|
324 | + $slice = strpos((string)$string, (string)$slice); |
|
325 | 325 | |
326 | - return substr((string) $string, 0, $slice); |
|
326 | + return substr((string)$string, 0, $slice); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | public static function remove($string, $remove) : string |
389 | 389 | { |
390 | 390 | if (\is_array($remove)) { |
391 | - $string = preg_replace('#('.implode('|', $remove).')#', '', (string) $string); |
|
391 | + $string = preg_replace('#('.implode('|', $remove).')#', '', (string)$string); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | // Trim and return |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | * |
405 | 405 | * @return string|string[] |
406 | 406 | */ |
407 | - public static function replace($string, $replace, $with) : array|string |
|
407 | + public static function replace($string, $replace, $with) : array | string |
|
408 | 408 | { |
409 | 409 | return str_replace($replace, $with, $string); |
410 | 410 | } |
@@ -445,12 +445,12 @@ discard block |
||
445 | 445 | $title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title); |
446 | 446 | |
447 | 447 | // Remove all characters that are not the separator, letters, numbers, or whitespace. |
448 | - $title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower((string) $title)); |
|
448 | + $title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower((string)$title)); |
|
449 | 449 | |
450 | 450 | // Replace all separator characters and whitespace by a single separator |
451 | - $title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, (string) $title); |
|
451 | + $title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, (string)$title); |
|
452 | 452 | |
453 | - return trim((string) $title, $separator); |
|
453 | + return trim((string)$title, $separator); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | /** |
@@ -476,10 +476,10 @@ discard block |
||
476 | 476 | public static function explode($string, $with, $limit = null) : array |
477 | 477 | { |
478 | 478 | if ( ! $limit) { |
479 | - return explode($with, (string) $string); |
|
479 | + return explode($with, (string)$string); |
|
480 | 480 | } |
481 | 481 | |
482 | - return explode($with, (string) $string, $limit); |
|
482 | + return explode($with, (string)$string, $limit); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
@@ -53,17 +53,17 @@ discard block |
||
53 | 53 | return $collection; |
54 | 54 | } |
55 | 55 | |
56 | - $collection = (array) $collection; |
|
56 | + $collection = (array)$collection; |
|
57 | 57 | |
58 | 58 | if (isset($collection[$key])) { |
59 | 59 | return $collection[$key]; |
60 | 60 | } |
61 | 61 | |
62 | 62 | // Crawl through collection, get key according to object or not |
63 | - foreach (explode('.', (string) $key) as $segment) { |
|
64 | - $collection = (array) $collection; |
|
63 | + foreach (explode('.', (string)$key) as $segment) { |
|
64 | + $collection = (array)$collection; |
|
65 | 65 | |
66 | - if (!isset($collection[$segment])) { |
|
66 | + if ( ! isset($collection[$segment])) { |
|
67 | 67 | return $default instanceof Closure ? $default() : $default; |
68 | 68 | } |
69 | 69 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | public static function setAndGet(mixed &$collection, string $key, mixed $default = null) : mixed |
98 | 98 | { |
99 | 99 | // If the key doesn't exist, set it |
100 | - if (!static::has($collection, $key)) { |
|
100 | + if ( ! static::has($collection, $key)) { |
|
101 | 101 | $collection = static::set($collection, $key, $default); |
102 | 102 | } |
103 | 103 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * |
110 | 110 | * |
111 | 111 | */ |
112 | - public static function remove(mixed $collection, string|array $key) : mixed |
|
112 | + public static function remove(mixed $collection, string | array $key) : mixed |
|
113 | 113 | { |
114 | 114 | // Recursive call |
115 | 115 | if (\is_array($key)) { |
@@ -131,13 +131,13 @@ discard block |
||
131 | 131 | * @param $collection |
132 | 132 | * @param $property |
133 | 133 | */ |
134 | - public static function pluck($collection, $property) : object|array |
|
134 | + public static function pluck($collection, $property) : object | array |
|
135 | 135 | { |
136 | - $plucked = array_map(fn($value): mixed => ArraysMethods::get($value, $property), (array) $collection); |
|
136 | + $plucked = array_map(fn($value): mixed => ArraysMethods::get($value, $property), (array)$collection); |
|
137 | 137 | |
138 | 138 | // Convert back to object if necessary |
139 | 139 | if (\is_object($collection)) { |
140 | - return (object) $plucked; |
|
140 | + return (object)$plucked; |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | return $plucked; |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | * |
153 | 153 | */ |
154 | 154 | public static function filterBy($collection, string $property, mixed $value, string $comparisonOp = null) : |
155 | - object|array |
|
155 | + object | array |
|
156 | 156 | { |
157 | - if (!$comparisonOp) { |
|
157 | + if ( ! $comparisonOp) { |
|
158 | 158 | $comparisonOp = \is_array($value) ? 'contains' : 'eq'; |
159 | 159 | } |
160 | 160 | |
@@ -165,32 +165,32 @@ discard block |
||
165 | 165 | 'lt' => fn($item, $prop, $value) : bool => $item[$prop] < $value, |
166 | 166 | 'lte' => fn($item, $prop, $value) : bool => $item[$prop] <= $value, |
167 | 167 | 'ne' => fn($item, $prop, $value) : bool => $item[$prop] !== $value, |
168 | - 'contains' => fn($item, $prop, $value) : bool => \in_array($item[$prop], (array) $value, true), |
|
169 | - 'notContains' => fn($item, $prop, $value) : bool => ! \in_array($item[$prop], (array) $value, true), |
|
168 | + 'contains' => fn($item, $prop, $value) : bool => \in_array($item[$prop], (array)$value, true), |
|
169 | + 'notContains' => fn($item, $prop, $value) : bool => ! \in_array($item[$prop], (array)$value, true), |
|
170 | 170 | 'newer' => fn( |
171 | 171 | $item, |
172 | 172 | $prop, |
173 | 173 | $value |
174 | - ) : bool => strtotime((string) $item[$prop]) > strtotime((string) $value), |
|
174 | + ) : bool => strtotime((string)$item[$prop]) > strtotime((string)$value), |
|
175 | 175 | 'older' => fn( |
176 | 176 | $item, |
177 | 177 | $prop, |
178 | 178 | $value |
179 | - ) : bool => strtotime((string) $item[$prop]) < strtotime((string) $value), |
|
179 | + ) : bool => strtotime((string)$item[$prop]) < strtotime((string)$value), |
|
180 | 180 | ]; |
181 | - $result = array_values(array_filter((array) $collection, function ($item) use ( |
|
181 | + $result = array_values(array_filter((array)$collection, function($item) use ( |
|
182 | 182 | $property, |
183 | 183 | $value, |
184 | 184 | $ops, |
185 | 185 | $comparisonOp |
186 | 186 | ): bool { |
187 | - $item = (array) $item; |
|
187 | + $item = (array)$item; |
|
188 | 188 | $item[$property] = static::get($item, $property, []); |
189 | 189 | |
190 | 190 | return $ops[$comparisonOp]($item, $property, $value); |
191 | 191 | })); |
192 | 192 | if (\is_object($collection)) { |
193 | - return (object) $result; |
|
193 | + return (object)$result; |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | return $result; |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | { |
208 | 208 | $filtered = static::filterBy($collection, $property, $value, $comparisonOp); |
209 | 209 | |
210 | - return ArraysMethods::first(\is_array($filtered) ? $filtered : (array) $filtered); |
|
210 | + return ArraysMethods::first(\is_array($filtered) ? $filtered : (array)$filtered); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | //////////////////////////////////////////////////////////////////// |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | */ |
221 | 221 | public static function keys($collection) : array |
222 | 222 | { |
223 | - return array_keys((array) $collection); |
|
223 | + return array_keys((array)$collection); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | */ |
231 | 231 | public static function values($collection) : array |
232 | 232 | { |
233 | - return array_values((array) $collection); |
|
233 | + return array_values((array)$collection); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | //////////////////////////////////////////////////////////////////// |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * |
242 | 242 | * |
243 | 243 | */ |
244 | - public static function replace(array|object $collection, string $replace, string $key, mixed $value) : mixed |
|
244 | + public static function replace(array | object $collection, string $replace, string $key, mixed $value) : mixed |
|
245 | 245 | { |
246 | 246 | $collection = static::remove($collection, $replace); |
247 | 247 | |
@@ -255,10 +255,10 @@ discard block |
||
255 | 255 | * @param string|callable|null $sorter |
256 | 256 | * |
257 | 257 | */ |
258 | - public static function sort(array|object $collection, string|callable $sorter = null, string $direction = 'asc') : |
|
258 | + public static function sort(array | object $collection, string | callable $sorter = null, string $direction = 'asc') : |
|
259 | 259 | array |
260 | 260 | { |
261 | - $collection = (array) $collection; |
|
261 | + $collection = (array)$collection; |
|
262 | 262 | |
263 | 263 | // Get correct PHP constant for direction |
264 | 264 | $directionNumber = (strtolower($direction) === 'desc') ? SORT_DESC : SORT_ASC; |
@@ -286,9 +286,9 @@ discard block |
||
286 | 286 | * @param $grouper |
287 | 287 | * |
288 | 288 | */ |
289 | - public static function group(mixed $collection, callable|string $grouper, bool $saveKeys = false) : array |
|
289 | + public static function group(mixed $collection, callable | string $grouper, bool $saveKeys = false) : array |
|
290 | 290 | { |
291 | - $collection = (array) $collection; |
|
291 | + $collection = (array)$collection; |
|
292 | 292 | $result = []; |
293 | 293 | |
294 | 294 | // Iterate over values, group by property/results from closure |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | } |
327 | 327 | |
328 | 328 | // Explode the keys |
329 | - $keys = explode('.', (string) $key); |
|
329 | + $keys = explode('.', (string)$key); |
|
330 | 330 | |
331 | 331 | // Crawl through the keys |
332 | 332 | while (\count($keys) > 1) { |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | * @param string $key |
361 | 361 | * |
362 | 362 | */ |
363 | - protected static function internalRemove(array|object &$collection, mixed $key) : bool |
|
363 | + protected static function internalRemove(array | object &$collection, mixed $key) : bool |
|
364 | 364 | { |
365 | 365 | // Explode keys |
366 | 366 | $keys = explode('.', $key); |