clear_array()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 2
eloc 4
c 2
b 1
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
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