@@ -57,7 +57,7 @@ |
||
57 | 57 | * |
58 | 58 | * @return int|string |
59 | 59 | */ |
60 | - protected function algorithm(): int|string |
|
60 | + protected function algorithm(): int | string |
|
61 | 61 | { |
62 | 62 | return PASSWORD_ARGON2ID; |
63 | 63 | } |
@@ -129,7 +129,7 @@ |
||
129 | 129 | 'memory_cost' => $this->memory($options), |
130 | 130 | 'time_cost' => $this->time($options), |
131 | 131 | 'threads' => $this->threads($options), |
132 | - ]); |
|
132 | + ]); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -179,7 +179,7 @@ |
||
179 | 179 | * |
180 | 180 | * @return int|string |
181 | 181 | */ |
182 | - protected function algorithm(): int|string |
|
182 | + protected function algorithm(): int | string |
|
183 | 183 | { |
184 | 184 | return PASSWORD_ARGON2I; |
185 | 185 | } |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | return array_search($value, $this->items, $strict); |
693 | 693 | } |
694 | 694 | |
695 | - foreach($this->items as $key => $item) { |
|
695 | + foreach ($this->items as $key => $item) { |
|
696 | 696 | if ($value($item, $key)) { |
697 | 697 | return $key; |
698 | 698 | } |
@@ -745,9 +745,9 @@ discard block |
||
745 | 745 | * |
746 | 746 | * @return static |
747 | 747 | */ |
748 | - public function sort(callable|int $callback = null): static |
|
748 | + public function sort(callable | int $callback = null): static |
|
749 | 749 | { |
750 | - $items = $this->items; |
|
750 | + $items = $this->items; |
|
751 | 751 | |
752 | 752 | $callback && is_callable($callback) |
753 | 753 | ? uasort($items, $callback) |
@@ -796,7 +796,7 @@ discard block |
||
796 | 796 | * |
797 | 797 | * @return static |
798 | 798 | */ |
799 | - public function sortKeysDesc(int $options = SORT_REGULAR): static |
|
799 | + public function sortKeysDesc(int $options = SORT_REGULAR): static |
|
800 | 800 | { |
801 | 801 | return $this->sortKeys($options, true); |
802 | 802 | } |
@@ -29,42 +29,42 @@ discard block |
||
29 | 29 | */ |
30 | 30 | class Arr |
31 | 31 | { |
32 | - /** |
|
33 | - * Determine whether the value is accessible in a array. |
|
34 | - * |
|
35 | - * @param mixed $value The default value |
|
36 | - * |
|
37 | - * @return mixed |
|
38 | - * |
|
39 | - * @uses instanceof ArrayAccess |
|
40 | - */ |
|
41 | - public static function accessible(mixed $value): mixed |
|
42 | - { |
|
43 | - return is_array($value) || $value instanceof ArrayAccess; |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Add an element to an array using "dot" notation if it doesn't exist. |
|
48 | - * |
|
49 | - * @param array $array The search array |
|
50 | - * @param string $key The key exist |
|
51 | - * @param mixed $value The default value |
|
52 | - * |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - public static function add(array $array, string $key, mixed $value): array |
|
56 | - { |
|
57 | - if (is_null(static::get($array, $key))) { |
|
58 | - static::set($array, $key, $value); |
|
59 | - } |
|
60 | - |
|
61 | - return $array; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
32 | + /** |
|
33 | + * Determine whether the value is accessible in a array. |
|
34 | + * |
|
35 | + * @param mixed $value The default value |
|
36 | + * |
|
37 | + * @return mixed |
|
38 | + * |
|
39 | + * @uses instanceof ArrayAccess |
|
40 | + */ |
|
41 | + public static function accessible(mixed $value): mixed |
|
42 | + { |
|
43 | + return is_array($value) || $value instanceof ArrayAccess; |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Add an element to an array using "dot" notation if it doesn't exist. |
|
48 | + * |
|
49 | + * @param array $array The search array |
|
50 | + * @param string $key The key exist |
|
51 | + * @param mixed $value The default value |
|
52 | + * |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + public static function add(array $array, string $key, mixed $value): array |
|
56 | + { |
|
57 | + if (is_null(static::get($array, $key))) { |
|
58 | + static::set($array, $key, $value); |
|
59 | + } |
|
60 | + |
|
61 | + return $array; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | 65 | * Collapse the collection items into a single array. |
66 | - * |
|
67 | - * @param array $array |
|
66 | + * |
|
67 | + * @param array $array |
|
68 | 68 | * |
69 | 69 | * @return array |
70 | 70 | */ |
@@ -73,440 +73,440 @@ discard block |
||
73 | 73 | $results = []; |
74 | 74 | |
75 | 75 | foreach ($array as $values) { |
76 | - if ($values instanceof Collection) { |
|
77 | - $values = $values->all(); |
|
78 | - } elseif ( ! is_array($values)) { |
|
79 | - continue; |
|
80 | - } |
|
76 | + if ($values instanceof Collection) { |
|
77 | + $values = $values->all(); |
|
78 | + } elseif ( ! is_array($values)) { |
|
79 | + continue; |
|
80 | + } |
|
81 | 81 | |
82 | - $results[] = $values; |
|
82 | + $results[] = $values; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | return array_merge([], ...$results); |
86 | 86 | } |
87 | 87 | |
88 | - /** |
|
89 | - * Divide an array into two arrays. One with keys and the other with values. |
|
90 | - * |
|
91 | - * @param array $array |
|
92 | - * |
|
93 | - * @return array |
|
94 | - */ |
|
95 | - public static function divide(array $array): array |
|
96 | - { |
|
97 | - return [array_keys($array), array_values($array)]; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Get all of the given array except for a specified array of items. |
|
102 | - * |
|
103 | - * @param array $array |
|
104 | - * @param string|array $keys |
|
105 | - * |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - public static function except(array $array, string|array $keys): array |
|
109 | - { |
|
110 | - static::erase($array, $keys); |
|
111 | - |
|
112 | - return $array; |
|
113 | - } |
|
88 | + /** |
|
89 | + * Divide an array into two arrays. One with keys and the other with values. |
|
90 | + * |
|
91 | + * @param array $array |
|
92 | + * |
|
93 | + * @return array |
|
94 | + */ |
|
95 | + public static function divide(array $array): array |
|
96 | + { |
|
97 | + return [array_keys($array), array_values($array)]; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Get all of the given array except for a specified array of items. |
|
102 | + * |
|
103 | + * @param array $array |
|
104 | + * @param string|array $keys |
|
105 | + * |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + public static function except(array $array, string|array $keys): array |
|
109 | + { |
|
110 | + static::erase($array, $keys); |
|
111 | + |
|
112 | + return $array; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Determine if the given key exists in the provided array. |
|
117 | - * |
|
118 | - * @param ArrayAccess|array $array The search array |
|
119 | - * @param string|int $key The key exist |
|
120 | - * |
|
121 | - * @return bool |
|
122 | - */ |
|
123 | - public static function exists($array, $key): bool |
|
124 | - { |
|
125 | - if ($array instanceof ArrayAccess) { |
|
126 | - return $array->offsetExists($key); |
|
127 | - } |
|
115 | + /** |
|
116 | + * Determine if the given key exists in the provided array. |
|
117 | + * |
|
118 | + * @param ArrayAccess|array $array The search array |
|
119 | + * @param string|int $key The key exist |
|
120 | + * |
|
121 | + * @return bool |
|
122 | + */ |
|
123 | + public static function exists($array, $key): bool |
|
124 | + { |
|
125 | + if ($array instanceof ArrayAccess) { |
|
126 | + return $array->offsetExists($key); |
|
127 | + } |
|
128 | 128 | |
129 | - return array_key_exists($key, $array); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Unsets dot-notated key from an array. |
|
134 | - * |
|
135 | - * @param array $array The search array |
|
136 | - * @param mixed $keys The dot-notated key or array of keys |
|
137 | - * |
|
138 | - * @return mixed |
|
139 | - */ |
|
140 | - public static function erase(array &$array, mixed $keys) |
|
141 | - { |
|
142 | - $original = &$array; |
|
143 | - |
|
144 | - $keys = (array) $keys; |
|
145 | - |
|
146 | - if (count($keys) === 0) { |
|
147 | - return; |
|
148 | - } |
|
149 | - |
|
150 | - foreach ($keys as $key) { |
|
151 | - if (static::exists($array, $key)) { |
|
152 | - unset($array[$key]); |
|
153 | - |
|
154 | - continue; |
|
155 | - } |
|
129 | + return array_key_exists($key, $array); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Unsets dot-notated key from an array. |
|
134 | + * |
|
135 | + * @param array $array The search array |
|
136 | + * @param mixed $keys The dot-notated key or array of keys |
|
137 | + * |
|
138 | + * @return mixed |
|
139 | + */ |
|
140 | + public static function erase(array &$array, mixed $keys) |
|
141 | + { |
|
142 | + $original = &$array; |
|
143 | + |
|
144 | + $keys = (array) $keys; |
|
145 | + |
|
146 | + if (count($keys) === 0) { |
|
147 | + return; |
|
148 | + } |
|
149 | + |
|
150 | + foreach ($keys as $key) { |
|
151 | + if (static::exists($array, $key)) { |
|
152 | + unset($array[$key]); |
|
153 | + |
|
154 | + continue; |
|
155 | + } |
|
156 | 156 | |
157 | - $parts = explode('.', $key); |
|
157 | + $parts = explode('.', $key); |
|
158 | 158 | |
159 | - // Clean up after each pass |
|
160 | - $array = &$original; |
|
159 | + // Clean up after each pass |
|
160 | + $array = &$original; |
|
161 | 161 | |
162 | - // traverse the array into the second last key |
|
163 | - while (count($parts) > 1) { |
|
164 | - $part = array_shift($parts); |
|
162 | + // traverse the array into the second last key |
|
163 | + while (count($parts) > 1) { |
|
164 | + $part = array_shift($parts); |
|
165 | 165 | |
166 | - if (isset($array[$part]) && is_array($array[$part])) { |
|
167 | - $array = &$array[$key]; |
|
168 | - } else { |
|
169 | - continue 2; |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - unset($array[array_shift($parts)]); |
|
174 | - } |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Flatten a multi-dimensional array into a single level. |
|
179 | - * |
|
180 | - * @param array $array |
|
181 | - * |
|
182 | - * @return array |
|
183 | - */ |
|
184 | - public static function flatten(array $array): array |
|
185 | - { |
|
186 | - $result = []; |
|
187 | - |
|
188 | - array_walk_recursive($array, function ($value) use (&$result) { |
|
189 | - $result[] = $value; |
|
190 | - }); |
|
191 | - |
|
192 | - return $result; |
|
193 | - } |
|
166 | + if (isset($array[$part]) && is_array($array[$part])) { |
|
167 | + $array = &$array[$key]; |
|
168 | + } else { |
|
169 | + continue 2; |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + unset($array[array_shift($parts)]); |
|
174 | + } |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Flatten a multi-dimensional array into a single level. |
|
179 | + * |
|
180 | + * @param array $array |
|
181 | + * |
|
182 | + * @return array |
|
183 | + */ |
|
184 | + public static function flatten(array $array): array |
|
185 | + { |
|
186 | + $result = []; |
|
187 | + |
|
188 | + array_walk_recursive($array, function ($value) use (&$result) { |
|
189 | + $result[] = $value; |
|
190 | + }); |
|
191 | + |
|
192 | + return $result; |
|
193 | + } |
|
194 | 194 | |
195 | - /** |
|
196 | - * Fetch a flattened array of a nested array element. |
|
197 | - * |
|
198 | - * @param array $array |
|
199 | - * @param string $key |
|
200 | - * |
|
201 | - * @return array |
|
202 | - */ |
|
203 | - public static function fetch(array $array, string $key): array |
|
204 | - { |
|
205 | - $segments = explode('.', $key); |
|
195 | + /** |
|
196 | + * Fetch a flattened array of a nested array element. |
|
197 | + * |
|
198 | + * @param array $array |
|
199 | + * @param string $key |
|
200 | + * |
|
201 | + * @return array |
|
202 | + */ |
|
203 | + public static function fetch(array $array, string $key): array |
|
204 | + { |
|
205 | + $segments = explode('.', $key); |
|
206 | 206 | |
207 | - foreach ($segments as $segment) { |
|
208 | - $results = array(); |
|
207 | + foreach ($segments as $segment) { |
|
208 | + $results = array(); |
|
209 | 209 | |
210 | - foreach ($array as $value) { |
|
211 | - if (array_key_exists($segment, $value = (array) $value)) { |
|
212 | - $results[] = $value[$segment]; |
|
213 | - } |
|
214 | - } |
|
210 | + foreach ($array as $value) { |
|
211 | + if (array_key_exists($segment, $value = (array) $value)) { |
|
212 | + $results[] = $value[$segment]; |
|
213 | + } |
|
214 | + } |
|
215 | 215 | |
216 | - $array = array_values($results); |
|
217 | - } |
|
216 | + $array = array_values($results); |
|
217 | + } |
|
218 | 218 | |
219 | - return array_values($results); |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Return the first element in an array passing a given truth test. |
|
224 | - * |
|
225 | - * @param array $array |
|
226 | - * @param \callable|null $callback |
|
227 | - * @param mixed $default |
|
228 | - * |
|
229 | - * @return mixed |
|
230 | - */ |
|
231 | - public static function first(array $array, callable $callback = null, mixed $default = null) |
|
232 | - { |
|
233 | - if (is_null($callback)) { |
|
234 | - if (empty($array)) { |
|
235 | - return value($default); |
|
236 | - } |
|
219 | + return array_values($results); |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Return the first element in an array passing a given truth test. |
|
224 | + * |
|
225 | + * @param array $array |
|
226 | + * @param \callable|null $callback |
|
227 | + * @param mixed $default |
|
228 | + * |
|
229 | + * @return mixed |
|
230 | + */ |
|
231 | + public static function first(array $array, callable $callback = null, mixed $default = null) |
|
232 | + { |
|
233 | + if (is_null($callback)) { |
|
234 | + if (empty($array)) { |
|
235 | + return value($default); |
|
236 | + } |
|
237 | 237 | |
238 | - foreach ($array as $item) { |
|
239 | - return $item; |
|
240 | - } |
|
241 | - } |
|
238 | + foreach ($array as $item) { |
|
239 | + return $item; |
|
240 | + } |
|
241 | + } |
|
242 | 242 | |
243 | - foreach ($array as $key => $value) { |
|
244 | - if ($callback($value, $key)) return $value; |
|
245 | - } |
|
246 | - |
|
247 | - return value($default); |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Get an item from an array using "dot" notation. |
|
252 | - * |
|
253 | - * @param \ArrayAccess|array $array The search array |
|
254 | - * @param string|array|null $key The dot-notated key or array of keys or null |
|
255 | - * @param mixed $default The default value |
|
256 | - * |
|
257 | - * @return mixed |
|
258 | - */ |
|
259 | - public static function get($array, string|array $key = null, mixed $default = null) |
|
260 | - { |
|
261 | - if ( ! static::accessible($array)) { |
|
262 | - return value($default); |
|
263 | - } |
|
264 | - |
|
265 | - if (is_null($key)) { |
|
266 | - return $array; |
|
267 | - } |
|
268 | - |
|
269 | - if (static::exists($array, $key)) { |
|
270 | - return $array[$key]; |
|
271 | - } |
|
243 | + foreach ($array as $key => $value) { |
|
244 | + if ($callback($value, $key)) return $value; |
|
245 | + } |
|
246 | + |
|
247 | + return value($default); |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Get an item from an array using "dot" notation. |
|
252 | + * |
|
253 | + * @param \ArrayAccess|array $array The search array |
|
254 | + * @param string|array|null $key The dot-notated key or array of keys or null |
|
255 | + * @param mixed $default The default value |
|
256 | + * |
|
257 | + * @return mixed |
|
258 | + */ |
|
259 | + public static function get($array, string|array $key = null, mixed $default = null) |
|
260 | + { |
|
261 | + if ( ! static::accessible($array)) { |
|
262 | + return value($default); |
|
263 | + } |
|
264 | + |
|
265 | + if (is_null($key)) { |
|
266 | + return $array; |
|
267 | + } |
|
268 | + |
|
269 | + if (static::exists($array, $key)) { |
|
270 | + return $array[$key]; |
|
271 | + } |
|
272 | 272 | |
273 | - if (strpos($key, '.') === false) { |
|
274 | - return $array[$key] ?? value($default); |
|
275 | - } |
|
276 | - |
|
277 | - $segments = explode('.', $key); |
|
278 | - |
|
279 | - foreach ($segments as $segment) { |
|
280 | - if (static::accessible($array) && static::exists($array, $segment)) { |
|
281 | - $array = $array[$segment]; |
|
282 | - } else { |
|
283 | - return value($default); |
|
284 | - } |
|
285 | - } |
|
286 | - |
|
287 | - return $array; |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Return the last element in an array passing a given truth test. |
|
292 | - * |
|
293 | - * @param array $array |
|
294 | - * @param \callable|null $callback |
|
295 | - * @param mixed $default |
|
296 | - * |
|
297 | - * @return mixed |
|
298 | - */ |
|
299 | - public static function last(array $array, callable $callback = null, mixed $default = null) |
|
300 | - { |
|
301 | - if (is_null($callback)) { |
|
302 | - return empty($array) ? value($default) : lastItem($array); |
|
303 | - } |
|
273 | + if (strpos($key, '.') === false) { |
|
274 | + return $array[$key] ?? value($default); |
|
275 | + } |
|
276 | + |
|
277 | + $segments = explode('.', $key); |
|
278 | + |
|
279 | + foreach ($segments as $segment) { |
|
280 | + if (static::accessible($array) && static::exists($array, $segment)) { |
|
281 | + $array = $array[$segment]; |
|
282 | + } else { |
|
283 | + return value($default); |
|
284 | + } |
|
285 | + } |
|
286 | + |
|
287 | + return $array; |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Return the last element in an array passing a given truth test. |
|
292 | + * |
|
293 | + * @param array $array |
|
294 | + * @param \callable|null $callback |
|
295 | + * @param mixed $default |
|
296 | + * |
|
297 | + * @return mixed |
|
298 | + */ |
|
299 | + public static function last(array $array, callable $callback = null, mixed $default = null) |
|
300 | + { |
|
301 | + if (is_null($callback)) { |
|
302 | + return empty($array) ? value($default) : lastItem($array); |
|
303 | + } |
|
304 | 304 | |
305 | - return static::first(array_reverse($array), $callback, $default); |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Check if an item exists in an array using "dot" notation. |
|
310 | - * |
|
311 | - * @param array $array |
|
312 | - * @param string $key |
|
313 | - * |
|
314 | - * @return bool |
|
315 | - */ |
|
316 | - public static function has(array $array, string $key): bool |
|
317 | - { |
|
318 | - if (empty($array) || is_null($key)) return false; |
|
305 | + return static::first(array_reverse($array), $callback, $default); |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Check if an item exists in an array using "dot" notation. |
|
310 | + * |
|
311 | + * @param array $array |
|
312 | + * @param string $key |
|
313 | + * |
|
314 | + * @return bool |
|
315 | + */ |
|
316 | + public static function has(array $array, string $key): bool |
|
317 | + { |
|
318 | + if (empty($array) || is_null($key)) return false; |
|
319 | 319 | |
320 | - if (static::exists($array, $key)) return true; |
|
320 | + if (static::exists($array, $key)) return true; |
|
321 | 321 | |
322 | - $segments = explode('.', $key); |
|
322 | + $segments = explode('.', $key); |
|
323 | 323 | |
324 | - foreach ($segments as $segment) { |
|
325 | - if ( ! is_array($array) || ! static::exists($array, $segment)) { |
|
326 | - return false; |
|
327 | - } |
|
324 | + foreach ($segments as $segment) { |
|
325 | + if ( ! is_array($array) || ! static::exists($array, $segment)) { |
|
326 | + return false; |
|
327 | + } |
|
328 | 328 | |
329 | - $array = $array[$segment]; |
|
330 | - } |
|
329 | + $array = $array[$segment]; |
|
330 | + } |
|
331 | 331 | |
332 | - return true; |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Gets max width of an array. |
|
337 | - * |
|
338 | - * @param array $data |
|
339 | - * @param bool $exclude |
|
340 | - * |
|
341 | - * @return int |
|
342 | - */ |
|
343 | - public static function getMaxWidth(array $data, bool $exclude = true): int |
|
344 | - { |
|
345 | - $maxWidth = 0; |
|
332 | + return true; |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Gets max width of an array. |
|
337 | + * |
|
338 | + * @param array $data |
|
339 | + * @param bool $exclude |
|
340 | + * |
|
341 | + * @return int |
|
342 | + */ |
|
343 | + public static function getMaxWidth(array $data, bool $exclude = true): int |
|
344 | + { |
|
345 | + $maxWidth = 0; |
|
346 | 346 | |
347 | - foreach ($data as $key => $value) { |
|
348 | - // key is not a integer |
|
349 | - if ( ! $exclude || ! is_numeric($key)) { |
|
350 | - $width = mb_strlen((string) $key, 'UTF-8'); |
|
351 | - $maxWidth = $width > $maxWidth ? $width : $maxWidth; |
|
352 | - } |
|
353 | - } |
|
347 | + foreach ($data as $key => $value) { |
|
348 | + // key is not a integer |
|
349 | + if ( ! $exclude || ! is_numeric($key)) { |
|
350 | + $width = mb_strlen((string) $key, 'UTF-8'); |
|
351 | + $maxWidth = $width > $maxWidth ? $width : $maxWidth; |
|
352 | + } |
|
353 | + } |
|
354 | 354 | |
355 | - return $maxWidth; |
|
356 | - } |
|
357 | - |
|
358 | - /** |
|
359 | - * Get a subset of the items from the given array. |
|
360 | - * |
|
361 | - * @param array $array |
|
362 | - * @param array|string $keys |
|
363 | - * |
|
364 | - * @return array |
|
365 | - */ |
|
366 | - public static function only(array $array, array|string $keys): array |
|
367 | - { |
|
368 | - return array_intersect_key($array, array_flip($array), $keys); |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Sets a value in an array using "dot" notation. |
|
373 | - * |
|
374 | - * @param array $array The search array |
|
375 | - * @param string $key The dot-notated key or array of keys |
|
376 | - * @param mixed $value The default value |
|
377 | - * |
|
378 | - * @return mixed |
|
379 | - */ |
|
380 | - public static function set(array &$array, string $key, mixed $value = null): mixed |
|
381 | - { |
|
382 | - if (is_null($key)) { |
|
383 | - return $array = $value; |
|
384 | - } |
|
385 | - |
|
386 | - $keys = explode('.', $key); |
|
387 | - |
|
388 | - while (count($keys) > 1) { |
|
389 | - $key = array_shift($keys); |
|
390 | - |
|
391 | - if ( ! static::exists($array, $key)) { |
|
392 | - $array[$key] = []; |
|
393 | - } |
|
394 | - |
|
395 | - $array = &$array[$key]; |
|
396 | - } |
|
397 | - |
|
398 | - $array[array_shift($keys)] = $value; |
|
399 | - |
|
400 | - return $array; |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * Push an item onto the beginning of an array. |
|
405 | - * |
|
406 | - * @param mixed $array |
|
407 | - * @param mixed $value |
|
408 | - * @param mixed key |
|
409 | - * |
|
410 | - * @return array |
|
411 | - */ |
|
412 | - public static function prepend(mixed $array, mixed $value, mixed $key = null): array |
|
413 | - { |
|
414 | - if (func_num_args() == 2) { |
|
415 | - array_unshift($array, $value); |
|
416 | - } else { |
|
417 | - $array = [$key => $value] + $array; |
|
418 | - } |
|
419 | - |
|
420 | - return $array; |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Get a value from the array, and remove it. |
|
425 | - * |
|
426 | - * @param array $array |
|
427 | - * @param string $key |
|
428 | - * @param mixed $default |
|
429 | - * |
|
430 | - * @return mixed |
|
431 | - */ |
|
432 | - public static function pull(array &$array, string $key, mixed $default = null): mixed |
|
433 | - { |
|
434 | - $value = static::get($array, $key, $default); |
|
435 | - |
|
436 | - static::erase($array, $key); |
|
437 | - |
|
438 | - return $value; |
|
439 | - } |
|
355 | + return $maxWidth; |
|
356 | + } |
|
357 | + |
|
358 | + /** |
|
359 | + * Get a subset of the items from the given array. |
|
360 | + * |
|
361 | + * @param array $array |
|
362 | + * @param array|string $keys |
|
363 | + * |
|
364 | + * @return array |
|
365 | + */ |
|
366 | + public static function only(array $array, array|string $keys): array |
|
367 | + { |
|
368 | + return array_intersect_key($array, array_flip($array), $keys); |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Sets a value in an array using "dot" notation. |
|
373 | + * |
|
374 | + * @param array $array The search array |
|
375 | + * @param string $key The dot-notated key or array of keys |
|
376 | + * @param mixed $value The default value |
|
377 | + * |
|
378 | + * @return mixed |
|
379 | + */ |
|
380 | + public static function set(array &$array, string $key, mixed $value = null): mixed |
|
381 | + { |
|
382 | + if (is_null($key)) { |
|
383 | + return $array = $value; |
|
384 | + } |
|
385 | + |
|
386 | + $keys = explode('.', $key); |
|
387 | + |
|
388 | + while (count($keys) > 1) { |
|
389 | + $key = array_shift($keys); |
|
390 | + |
|
391 | + if ( ! static::exists($array, $key)) { |
|
392 | + $array[$key] = []; |
|
393 | + } |
|
394 | + |
|
395 | + $array = &$array[$key]; |
|
396 | + } |
|
397 | + |
|
398 | + $array[array_shift($keys)] = $value; |
|
399 | + |
|
400 | + return $array; |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * Push an item onto the beginning of an array. |
|
405 | + * |
|
406 | + * @param mixed $array |
|
407 | + * @param mixed $value |
|
408 | + * @param mixed key |
|
409 | + * |
|
410 | + * @return array |
|
411 | + */ |
|
412 | + public static function prepend(mixed $array, mixed $value, mixed $key = null): array |
|
413 | + { |
|
414 | + if (func_num_args() == 2) { |
|
415 | + array_unshift($array, $value); |
|
416 | + } else { |
|
417 | + $array = [$key => $value] + $array; |
|
418 | + } |
|
419 | + |
|
420 | + return $array; |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Get a value from the array, and remove it. |
|
425 | + * |
|
426 | + * @param array $array |
|
427 | + * @param string $key |
|
428 | + * @param mixed $default |
|
429 | + * |
|
430 | + * @return mixed |
|
431 | + */ |
|
432 | + public static function pull(array &$array, string $key, mixed $default = null): mixed |
|
433 | + { |
|
434 | + $value = static::get($array, $key, $default); |
|
435 | + |
|
436 | + static::erase($array, $key); |
|
437 | + |
|
438 | + return $value; |
|
439 | + } |
|
440 | 440 | |
441 | - /** |
|
442 | - * Pluck an array of values from an array. |
|
443 | - * |
|
444 | - * @param \iterable $array |
|
445 | - * @param string|array|int|null $value |
|
446 | - * @param string|array|null $key |
|
447 | - * |
|
448 | - * @return array |
|
449 | - */ |
|
450 | - public static function pluck($array, $value, $key = null): array |
|
451 | - { |
|
452 | - $results = []; |
|
453 | - |
|
454 | - foreach ($array as $item) { |
|
455 | - $itemValue = is_object($item) ? $item->{$value} : $item[$value]; |
|
441 | + /** |
|
442 | + * Pluck an array of values from an array. |
|
443 | + * |
|
444 | + * @param \iterable $array |
|
445 | + * @param string|array|int|null $value |
|
446 | + * @param string|array|null $key |
|
447 | + * |
|
448 | + * @return array |
|
449 | + */ |
|
450 | + public static function pluck($array, $value, $key = null): array |
|
451 | + { |
|
452 | + $results = []; |
|
453 | + |
|
454 | + foreach ($array as $item) { |
|
455 | + $itemValue = is_object($item) ? $item->{$value} : $item[$value]; |
|
456 | 456 | |
457 | - // If the key is "null", we will just append the value to the array and keep |
|
458 | - // looping. Otherwise we will key the array using the value of the key we |
|
459 | - // received from the developer. Then we'll return the final array form. |
|
460 | - if (is_null($key)) { |
|
461 | - $results[] = $itemValue; |
|
462 | - } else { |
|
463 | - $itemKey = is_object($item) ? $item->{$key} : $item[$key]; |
|
457 | + // If the key is "null", we will just append the value to the array and keep |
|
458 | + // looping. Otherwise we will key the array using the value of the key we |
|
459 | + // received from the developer. Then we'll return the final array form. |
|
460 | + if (is_null($key)) { |
|
461 | + $results[] = $itemValue; |
|
462 | + } else { |
|
463 | + $itemKey = is_object($item) ? $item->{$key} : $item[$key]; |
|
464 | 464 | |
465 | - $results[$itemKey] = $itemValue; |
|
466 | - } |
|
467 | - } |
|
465 | + $results[$itemKey] = $itemValue; |
|
466 | + } |
|
467 | + } |
|
468 | 468 | |
469 | - return $results; |
|
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * Convert the array into a query string. |
|
474 | - * |
|
475 | - * @param array $array |
|
476 | - * |
|
477 | - * @return bool |
|
478 | - */ |
|
479 | - public static function query(array $array): bool |
|
480 | - { |
|
481 | - return http_build_query($array, '', '&', PHP_QUERY_RFC3986); |
|
482 | - } |
|
483 | - |
|
484 | - /** |
|
485 | - * Filter the array using the given callback. |
|
486 | - * |
|
487 | - * @param array $array |
|
488 | - * @param \Callable $callback |
|
489 | - * |
|
490 | - * @return array |
|
491 | - */ |
|
492 | - public static function where(array $array, Callable $callback): array |
|
493 | - { |
|
494 | - return array_filter($array, $callback, ARRAY_FILTER_USE_BOTH); |
|
495 | - } |
|
496 | - |
|
497 | - /** |
|
498 | - * If the given value is not an array and not null, wrap it in one. |
|
499 | - * |
|
500 | - * @param mixed $value |
|
501 | - * |
|
502 | - * @return array |
|
503 | - */ |
|
504 | - public static function wrap(mixed $value): array |
|
505 | - { |
|
506 | - if (is_null($value)) { |
|
507 | - return []; |
|
508 | - } |
|
509 | - |
|
510 | - return is_array($value) ? $value : [$value]; |
|
511 | - } |
|
469 | + return $results; |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * Convert the array into a query string. |
|
474 | + * |
|
475 | + * @param array $array |
|
476 | + * |
|
477 | + * @return bool |
|
478 | + */ |
|
479 | + public static function query(array $array): bool |
|
480 | + { |
|
481 | + return http_build_query($array, '', '&', PHP_QUERY_RFC3986); |
|
482 | + } |
|
483 | + |
|
484 | + /** |
|
485 | + * Filter the array using the given callback. |
|
486 | + * |
|
487 | + * @param array $array |
|
488 | + * @param \Callable $callback |
|
489 | + * |
|
490 | + * @return array |
|
491 | + */ |
|
492 | + public static function where(array $array, Callable $callback): array |
|
493 | + { |
|
494 | + return array_filter($array, $callback, ARRAY_FILTER_USE_BOTH); |
|
495 | + } |
|
496 | + |
|
497 | + /** |
|
498 | + * If the given value is not an array and not null, wrap it in one. |
|
499 | + * |
|
500 | + * @param mixed $value |
|
501 | + * |
|
502 | + * @return array |
|
503 | + */ |
|
504 | + public static function wrap(mixed $value): array |
|
505 | + { |
|
506 | + if (is_null($value)) { |
|
507 | + return []; |
|
508 | + } |
|
509 | + |
|
510 | + return is_array($value) ? $value : [$value]; |
|
511 | + } |
|
512 | 512 | } |
513 | 513 | \ No newline at end of file |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @return array |
107 | 107 | */ |
108 | - public static function except(array $array, string|array $keys): array |
|
108 | + public static function except(array $array, string | array $keys): array |
|
109 | 109 | { |
110 | 110 | static::erase($array, $keys); |
111 | 111 | |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | { |
186 | 186 | $result = []; |
187 | 187 | |
188 | - array_walk_recursive($array, function ($value) use (&$result) { |
|
188 | + array_walk_recursive($array, function($value) use (&$result) { |
|
189 | 189 | $result[] = $value; |
190 | 190 | }); |
191 | 191 | |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * |
257 | 257 | * @return mixed |
258 | 258 | */ |
259 | - public static function get($array, string|array $key = null, mixed $default = null) |
|
259 | + public static function get($array, string | array $key = null, mixed $default = null) |
|
260 | 260 | { |
261 | 261 | if ( ! static::accessible($array)) { |
262 | 262 | return value($default); |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | * |
364 | 364 | * @return array |
365 | 365 | */ |
366 | - public static function only(array $array, array|string $keys): array |
|
366 | + public static function only(array $array, array | string $keys): array |
|
367 | 367 | { |
368 | 368 | return array_intersect_key($array, array_flip($array), $keys); |
369 | 369 | } |
@@ -241,7 +241,9 @@ discard block |
||
241 | 241 | } |
242 | 242 | |
243 | 243 | foreach ($array as $key => $value) { |
244 | - if ($callback($value, $key)) return $value; |
|
244 | + if ($callback($value, $key)) { |
|
245 | + return $value; |
|
246 | + } |
|
245 | 247 | } |
246 | 248 | |
247 | 249 | return value($default); |
@@ -315,9 +317,13 @@ discard block |
||
315 | 317 | */ |
316 | 318 | public static function has(array $array, string $key): bool |
317 | 319 | { |
318 | - if (empty($array) || is_null($key)) return false; |
|
320 | + if (empty($array) || is_null($key)) { |
|
321 | + return false; |
|
322 | + } |
|
319 | 323 | |
320 | - if (static::exists($array, $key)) return true; |
|
324 | + if (static::exists($array, $key)) { |
|
325 | + return true; |
|
326 | + } |
|
321 | 327 | |
322 | 328 | $segments = explode('.', $key); |
323 | 329 |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return mixed |
50 | 50 | */ |
51 | - function data_get($target, string|array $key, mixed $default = null) |
|
51 | + function data_get($target, string | array $key, mixed $default = null) |
|
52 | 52 | { |
53 | 53 | if (is_null($key)) return $target; |
54 | 54 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | if ($segment === '*') { |
59 | 59 | if ($target instanceof Collection) { |
60 | 60 | $target = $target->all(); |
61 | - } elseif (! is_array($target)) { |
|
61 | + } elseif ( ! is_array($target)) { |
|
62 | 62 | return value($default); |
63 | 63 | } |
64 | 64 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | } |
81 | 81 | } |
82 | 82 | |
83 | -if( ! function_exists('data_set')) { |
|
83 | +if ( ! function_exists('data_set')) { |
|
84 | 84 | /** |
85 | 85 | * Set an item on an array or object using dot notation. |
86 | 86 | * |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * |
92 | 92 | * @return mixed |
93 | 93 | */ |
94 | - function data_set(&$target, string|array $key, mixed $value, bool $overwrite = true) |
|
94 | + function data_set(&$target, string | array $key, mixed $value, bool $overwrite = true) |
|
95 | 95 | { |
96 | 96 | $segments = is_array($key) ? $key : explode('.', $key); |
97 | 97 |
@@ -50,7 +50,9 @@ |
||
50 | 50 | */ |
51 | 51 | function data_get($target, string|array $key, mixed $default = null) |
52 | 52 | { |
53 | - if (is_null($key)) return $target; |
|
53 | + if (is_null($key)) { |
|
54 | + return $target; |
|
55 | + } |
|
54 | 56 | |
55 | 57 | $key = is_array($key) ? $key : explode('.', $key); |
56 | 58 |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | $operator = '='; |
70 | 70 | } |
71 | 71 | |
72 | - return function ($item) use ($key, $operator, $value) { |
|
72 | + return function($item) use ($key, $operator, $value) { |
|
73 | 73 | $retrieved = data_get($item, $key); |
74 | 74 | |
75 | 75 | switch ($operator) { |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | */ |
148 | 148 | public function jsonSerialize(): array |
149 | 149 | { |
150 | - return array_map(function ($value) { |
|
150 | + return array_map(function($value) { |
|
151 | 151 | if ($value instanceof JsonSerializable) { |
152 | 152 | return $value->jsonSerialize(); |
153 | 153 | } elseif ($value instanceof Arrayable) { |
@@ -55,7 +55,9 @@ |
||
55 | 55 | */ |
56 | 56 | public function operatorCallback($key, $operator = null, $value = null) |
57 | 57 | { |
58 | - if ($this->useAsCallable($key)) return $key; |
|
58 | + if ($this->useAsCallable($key)) { |
|
59 | + return $key; |
|
60 | + } |
|
59 | 61 | |
60 | 62 | if (func_num_args() === 1) { |
61 | 63 | $value = true; |
@@ -153,7 +153,7 @@ |
||
153 | 153 | * |
154 | 154 | * @return string|object |
155 | 155 | */ |
156 | - protected function getReflectionClass($class): string|object |
|
156 | + protected function getReflectionClass($class): string | object |
|
157 | 157 | { |
158 | 158 | $object = new ReflectionClass($class); |
159 | 159 |
@@ -40,7 +40,7 @@ |
||
40 | 40 | { |
41 | 41 | $this->registerLoader(); |
42 | 42 | |
43 | - $this->app->singleton('translator', function ($app) { |
|
43 | + $this->app->singleton('translator', function($app) { |
|
44 | 44 | $locale = $app['config']['app.locale']; |
45 | 45 | $loader = $app['translator.loader']; |
46 | 46 |
@@ -205,7 +205,7 @@ |
||
205 | 205 | */ |
206 | 206 | public function create($table, Closure $callback): void |
207 | 207 | { |
208 | - $this->build(take($this->createDataprint($table), function ($dataprint) use ($callback) { |
|
208 | + $this->build(take($this->createDataprint($table), function($dataprint) use ($callback) { |
|
209 | 209 | $dataprint->create(); |
210 | 210 | |
211 | 211 | $callback($dataprint); |