Completed
Push — master ( fc126f...40c3c0 )
by Peter
03:09
created

helpers.php ➔ str_empty()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 12
ccs 4
cts 5
cp 0.8
crap 3.072
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
if (! function_exists('str_empty')) {
4
    /**
5
     * Returns true if a string is empty or null.
6
     *
7
     * @param string|null $value
8
     * @param bool $trim
9
     * @return bool
10
     */
11
    function str_empty($value, $trim = false)
12
    {
13 40
        if ($value === null) {
14 9
            return true;
15
        }
16
17 40
        if ($trim) {
18
            return trim((string) $value) === '';
19
        }
20
21 40
        return (string) $value === '';
22
    }
23
}
24
25
if (! function_exists('str_array_filter')) {
26
    /**
27
     * Filter out null and empty string values.
28
     *
29
     * @param $array
30
     * @return array
31
     */
32
    function str_array_filter($array)
33
    {
34
        return array_filter($array, function ($value) {
35 12
            if (is_array($value)) {
36 1
                return ! empty($value);
37
            }
38
39 12
            return ! str_empty($value);
40 12
        });
41
    }
42
}
43