Issues (19)

src/helpers.php (1 issue)

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
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
29
                throw \Greenlyst\BaseCommerce\LogicException::requiredFieldDoesntExist($key);
30
            }
31
        }
32
    }
33
}
34