Total Complexity | 7 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | class ArrayHelper |
||
8 | { |
||
9 | /** |
||
10 | * Get a value from an array if it exists, otherwise a specified default value. |
||
11 | * For multi dimensional arrays please see ArrayStorage. |
||
12 | * |
||
13 | * @param array<mixed> $array |
||
14 | * @param mixed $key |
||
15 | * @param mixed $defaultValue |
||
16 | * @return mixed |
||
17 | */ |
||
18 | public static function get(array $array, $key, $defaultValue = null) |
||
19 | { |
||
20 | return \array_key_exists($key, $array) |
||
21 | ? $array[$key] |
||
22 | : $defaultValue; |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * @param array<mixed> $array |
||
27 | */ |
||
28 | public static function isMultidimensional(array $array): bool |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @param array<int|string,int|float|string> $array |
||
38 | */ |
||
39 | public static function toUrlQueryString(array $array): ?string |
||
51 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.