1 | <?php |
||
2 | |||
3 | use function ArrayHelpers\array_has; |
||
4 | |||
5 | if (!function_exists('clear_array')) { |
||
6 | function clear_array($data) |
||
7 | { |
||
8 | return array_filter($data, function ($item) { |
||
9 | if ($item === null) { |
||
10 | return false; |
||
11 | } |
||
12 | |||
13 | return true; |
||
14 | }); |
||
15 | } |
||
16 | } |
||
17 | |||
18 | if (!function_exists('validate_array')) { |
||
19 | /** |
||
20 | * @param $array |
||
21 | * @param $keys |
||
22 | * |
||
23 | * @throws \Greenlyst\BaseCommerce\LogicException |
||
24 | */ |
||
25 | function validate_array($array, $keys) |
||
26 | { |
||
27 | foreach ($keys as $key) { |
||
28 | if (array_has($array, $key) == false) { |
||
0 ignored issues
–
show
|
|||
29 | throw \Greenlyst\BaseCommerce\LogicException::requiredFieldDoesntExist($key); |
||
30 | } |
||
31 | } |
||
32 | } |
||
33 | } |
||
34 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.