@@ -52,8 +52,7 @@ |
||
52 | 52 | * Class Path |
53 | 53 | * @package Platine\Stdlib\Helper |
54 | 54 | */ |
55 | -class Path |
|
56 | -{ |
|
55 | +class Path { |
|
57 | 56 | |
58 | 57 | /** |
59 | 58 | * normalize the path by replace the "\" to "/" |
@@ -50,8 +50,7 @@ |
||
50 | 50 | * Class Env |
51 | 51 | * @package Platine\Stdlib\Helper |
52 | 52 | */ |
53 | -class Env |
|
54 | -{ |
|
53 | +class Env { |
|
55 | 54 | |
56 | 55 | /** |
57 | 56 | * Whether the application is running on CLI |
@@ -50,8 +50,7 @@ |
||
50 | 50 | * Class Xml |
51 | 51 | * @package Platine\Stdlib\Helper |
52 | 52 | */ |
53 | -class Xml |
|
54 | -{ |
|
53 | +class Xml { |
|
55 | 54 | |
56 | 55 | /** |
57 | 56 | * Transform an XML string to array |
@@ -74,7 +74,7 @@ |
||
74 | 74 | return self::$classLoader; |
75 | 75 | } |
76 | 76 | |
77 | - $autoloadFunctions = (array)spl_autoload_functions(); |
|
77 | + $autoloadFunctions = (array) spl_autoload_functions(); |
|
78 | 78 | foreach ($autoloadFunctions as $loader) { |
79 | 79 | if (is_array($loader) && isset($loader[0])) { |
80 | 80 | $composerLoader = $loader[0]; |
@@ -53,8 +53,7 @@ |
||
53 | 53 | * Class Composer |
54 | 54 | * @package Platine\Stdlib\Helper |
55 | 55 | */ |
56 | -class Composer |
|
57 | -{ |
|
56 | +class Composer { |
|
58 | 57 | |
59 | 58 | /** |
60 | 59 | * The composer class loader instance |
@@ -67,7 +67,7 @@ |
||
67 | 67 | if (array_key_exists('unit', $matches)) { |
68 | 68 | $unit = strtoupper($matches['unit']); |
69 | 69 | } |
70 | - return (int)(floatval($matches['size']) * pow(1024, $units[$unit])); |
|
70 | + return (int) (floatval($matches['size']) * pow(1024, $units[$unit])); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -50,8 +50,7 @@ |
||
50 | 50 | * Class Unit |
51 | 51 | * @package Platine\Stdlib\Helper |
52 | 52 | */ |
53 | -class Unit |
|
54 | -{ |
|
53 | +class Unit { |
|
55 | 54 | |
56 | 55 | /** |
57 | 56 | * Convert the size like 4G, 7T, 19B to byte |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $value = str_replace($val, $key, $value); |
86 | 86 | } |
87 | 87 | |
88 | - return (string)preg_replace('/[^\x20-\x7E]/u', '', $value); |
|
88 | + return (string) preg_replace('/[^\x20-\x7E]/u', '', $value); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | // pattern such as "library/*", making any string check convenient. |
253 | 253 | $cleanQuoted = str_replace('\*', '.*', $quoted); |
254 | 254 | |
255 | - return (bool)preg_match('#^' . $cleanQuoted . '\z#', $value); |
|
255 | + return (bool) preg_match('#^' . $cleanQuoted . '\z#', $value); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | */ |
565 | 565 | public static function isAscii(string $value): bool |
566 | 566 | { |
567 | - return (bool)!preg_match('/[^\x00-\x7F]/S', $value); |
|
567 | + return (bool) !preg_match('/[^\x00-\x7F]/S', $value); |
|
568 | 568 | } |
569 | 569 | |
570 | 570 | /** |
@@ -597,7 +597,7 @@ discard block |
||
597 | 597 | { |
598 | 598 | $bytes = random_bytes((int) ceil($length / 2)); |
599 | 599 | |
600 | - return (string)substr(bin2hex($bytes), 0, $length); |
|
600 | + return (string) substr(bin2hex($bytes), 0, $length); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | /** |
@@ -662,7 +662,7 @@ discard block |
||
662 | 662 | $pool = '2345679ACDEFHJKLMNPRSTUVWXYZ'; |
663 | 663 | break; |
664 | 664 | default: |
665 | - $pool = (string)$type; |
|
665 | + $pool = (string) $type; |
|
666 | 666 | $utf8 = !self::isAscii($pool); |
667 | 667 | break; |
668 | 668 | } |
@@ -50,8 +50,7 @@ |
||
50 | 50 | * Class Str |
51 | 51 | * @package Platine\Stdlib\Helper |
52 | 52 | */ |
53 | -class Str |
|
54 | -{ |
|
53 | +class Str { |
|
55 | 54 | |
56 | 55 | /** |
57 | 56 | * The cache of snake-cased words. |
@@ -52,8 +52,7 @@ discard block |
||
52 | 52 | * Class Php |
53 | 53 | * @package Platine\Stdlib\Helper |
54 | 54 | */ |
55 | -class Php |
|
56 | -{ |
|
55 | +class Php { |
|
57 | 56 | |
58 | 57 | /** |
59 | 58 | * Call by callback |
@@ -62,13 +61,13 @@ discard block |
||
62 | 61 | * |
63 | 62 | * @return mixed |
64 | 63 | */ |
65 | - public static function call($callback, ...$args) |
|
66 | - { |
|
64 | + public static function call($callback, ...$args) { |
|
67 | 65 | if (is_string($callback)) { |
68 | 66 | // className::method |
69 | 67 | if (strpos($callback, '::') > 0) { |
70 | 68 | $callback = explode('::', $callback, 2); |
71 | - } elseif (function_exists($callback)) { //function |
|
69 | + } elseif (function_exists($callback)) { |
|
70 | +//function |
|
72 | 71 | return $callback(...$args); |
73 | 72 | } |
74 | 73 | } elseif (is_object($callback) && method_exists($callback, '__invoke')) { |
@@ -93,8 +92,7 @@ discard block |
||
93 | 92 | * |
94 | 93 | * @return mixed |
95 | 94 | */ |
96 | - public static function callArray($callback, array $args) |
|
97 | - { |
|
95 | + public static function callArray($callback, array $args) { |
|
98 | 96 | return self::call($callback, ...$args); |
99 | 97 | } |
100 | 98 |
@@ -52,8 +52,7 @@ |
||
52 | 52 | * Class Json |
53 | 53 | * @package Platine\Stdlib\Helper |
54 | 54 | */ |
55 | -class Json |
|
56 | -{ |
|
55 | +class Json { |
|
57 | 56 | |
58 | 57 | /** |
59 | 58 | * Decode JSON string |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | $result = $object->toArray(); |
108 | 108 | } else { |
109 | 109 | $result = []; |
110 | - foreach ((array)$object as $key => $value) { |
|
110 | + foreach ((array) $object as $key => $value) { |
|
111 | 111 | $result[$key] = $value; |
112 | 112 | } |
113 | 113 | } |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public static function merge(array ...$args): array |
129 | 129 | { |
130 | - $res = (array)array_shift($args); |
|
130 | + $res = (array) array_shift($args); |
|
131 | 131 | while (!empty($args)) { |
132 | 132 | $next = array_shift($args); |
133 | 133 | foreach ($next as $key => $value) { |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | return; |
468 | 468 | } |
469 | 469 | |
470 | - $count = count($keys); |
|
470 | + $count = count($keys); |
|
471 | 471 | if (is_scalar($direction)) { |
472 | 472 | $direction = array_fill(0, $count, $direction); |
473 | 473 | } elseif (count($direction) !== $count) { |
@@ -929,7 +929,7 @@ discard block |
||
929 | 929 | $max = 0; |
930 | 930 | foreach ($array as $key => $value) { |
931 | 931 | if (!$expectInt || !is_numeric($key)) { |
932 | - $width = mb_strlen((string)$key, 'UTF-8'); |
|
932 | + $width = mb_strlen((string) $key, 'UTF-8'); |
|
933 | 933 | if ($width > $max) { |
934 | 934 | $max = $width; |
935 | 935 | } |
@@ -1049,7 +1049,7 @@ discard block |
||
1049 | 1049 | } else { |
1050 | 1050 | $itemKey = static::get($item, $key); |
1051 | 1051 | if (is_object($itemKey) && method_exists($itemKey, '__toString')) { |
1052 | - $itemKey = (string)$itemKey; |
|
1052 | + $itemKey = (string) $itemKey; |
|
1053 | 1053 | } |
1054 | 1054 | |
1055 | 1055 | $results[$itemKey] = $itemValue; |
@@ -1152,7 +1152,7 @@ discard block |
||
1152 | 1152 | $keys = array_rand($array, $number); |
1153 | 1153 | |
1154 | 1154 | $results = []; |
1155 | - foreach ((array)$keys as $key) { |
|
1155 | + foreach ((array) $keys as $key) { |
|
1156 | 1156 | $results[] = $array[$key]; |
1157 | 1157 | } |
1158 | 1158 | |
@@ -1202,18 +1202,18 @@ discard block |
||
1202 | 1202 | if (preg_match('/^\-\w=/', $arg)) { |
1203 | 1203 | $normalized = array_merge( |
1204 | 1204 | $normalized, |
1205 | - (array)explode('=', $arg) |
|
1205 | + (array) explode('=', $arg) |
|
1206 | 1206 | ); |
1207 | 1207 | } elseif (preg_match('/^\-\w{2,}/', $arg)) { |
1208 | 1208 | $splitArgs = implode(' -', str_split(ltrim($arg, '-'))); |
1209 | 1209 | $normalized = array_merge( |
1210 | 1210 | $normalized, |
1211 | - (array)explode(' ', '-' . $splitArgs) |
|
1211 | + (array) explode(' ', '-' . $splitArgs) |
|
1212 | 1212 | ); |
1213 | 1213 | } elseif (preg_match('/^\-\-([^\s\=]+)\=/', $arg)) { |
1214 | 1214 | $normalized = array_merge( |
1215 | 1215 | $normalized, |
1216 | - (array)explode('=', $arg) |
|
1216 | + (array) explode('=', $arg) |
|
1217 | 1217 | ); |
1218 | 1218 | } else { |
1219 | 1219 | $normalized[] = $arg; |
@@ -57,8 +57,7 @@ discard block |
||
57 | 57 | * Class Arr |
58 | 58 | * @package Platine\Stdlib\Helper |
59 | 59 | */ |
60 | -class Arr |
|
61 | -{ |
|
60 | +class Arr { |
|
62 | 61 | |
63 | 62 | /** |
64 | 63 | * Convert an array, object or string to array |
@@ -159,8 +158,7 @@ discard block |
||
159 | 158 | * @return mixed If the key does not exist in the array or object, |
160 | 159 | * the default value will be returned instead. |
161 | 160 | */ |
162 | - public static function getValue($object, $key, $default = null) |
|
163 | - { |
|
161 | + public static function getValue($object, $key, $default = null) { |
|
164 | 162 | if ($key instanceof Closure) { |
165 | 163 | return $key($object, $default); |
166 | 164 | } |
@@ -220,8 +218,7 @@ discard block |
||
220 | 218 | * |
221 | 219 | * @return mixed|null |
222 | 220 | */ |
223 | - public static function remove(array &$array, string $key, $default = null) |
|
224 | - { |
|
221 | + public static function remove(array &$array, string $key, $default = null) { |
|
225 | 222 | if (isset($array[$key]) || array_key_exists($key, $array)) { |
226 | 223 | $value = $array[$key]; |
227 | 224 | |
@@ -294,8 +291,7 @@ discard block |
||
294 | 291 | * @param mixed $default |
295 | 292 | * @return mixed |
296 | 293 | */ |
297 | - public static function pull(array &$array, string $key, $default = null) |
|
298 | - { |
|
294 | + public static function pull(array &$array, string $key, $default = null) { |
|
299 | 295 | $value = static::get($array, $key, $default); |
300 | 296 | |
301 | 297 | static::forget($array, $key); |
@@ -752,8 +748,7 @@ discard block |
||
752 | 748 | * @param mixed $default |
753 | 749 | * @return mixed |
754 | 750 | */ |
755 | - public static function get($array, ?string $key = null, $default = null) |
|
756 | - { |
|
751 | + public static function get($array, ?string $key = null, $default = null) { |
|
757 | 752 | if ($key === null) { |
758 | 753 | return $array; |
759 | 754 | } |
@@ -1128,8 +1123,7 @@ discard block |
||
1128 | 1123 | * |
1129 | 1124 | * @return mixed |
1130 | 1125 | */ |
1131 | - public static function random(array $array, ?int $number = null) |
|
1132 | - { |
|
1126 | + public static function random(array $array, ?int $number = null) { |
|
1133 | 1127 | $requested = $number === null ? 1 : $number; |
1134 | 1128 | $count = count($array); |
1135 | 1129 |