| Total Complexity | 8 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 10 | class Helpers |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @param $data |
||
| 14 | * |
||
| 15 | * @return array |
||
| 16 | */ |
||
| 17 | public static function clearArray($data) |
||
| 18 | { |
||
| 19 | return array_filter($data, function ($item) { |
||
| 20 | if ($item === null) { |
||
| 21 | return false; |
||
| 22 | } |
||
| 23 | |||
| 24 | return true; |
||
| 25 | }); |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param $array |
||
| 30 | * @param $keys |
||
| 31 | * |
||
| 32 | * @throws LogicException |
||
| 33 | */ |
||
| 34 | public static function validateArray($array, $keys) |
||
| 35 | { |
||
| 36 | foreach ($keys as $key) { |
||
| 37 | if (array_has($array, $key) == false) { |
||
|
|
|||
| 38 | throw LogicException::requiredFieldDoesntExist($key); |
||
| 39 | } |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Get all of the given array except for a specified array of items. |
||
| 45 | * |
||
| 46 | * @param array $array |
||
| 47 | * @param array|string $keys |
||
| 48 | * |
||
| 49 | * @return array |
||
| 50 | */ |
||
| 51 | public static function array_except($array, $keys) |
||
| 52 | { |
||
| 53 | return array_diff_key($array, array_flip((array) $keys)); |
||
| 54 | } |
||
| 55 | |||
| 56 | public static function replaceArrayKeys($array, $search, $replace) |
||
| 65 | } |
||
| 66 | } |
||
| 67 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.