Passed
Push — master ( ecf04c...355586 )
by Vincent
08:10
created

HttpValue::isEmpty()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
namespace Bdf\Form\Util;
4
5
/**
6
 * Utility class for handle http values
7
 */
8
final class HttpValue
9
{
10
    /**
11
     * Check if the given value should be considered as empty
12
     * Unlike php's `empty()` function, '0', false, 0, 0.0 are not considered as empty
13
     *
14
     * @param mixed $value Value to check
15
     *
16
     * @return bool true if the value is empty
17
     */
18 34
    public static function isEmpty($value): bool
19
    {
20 34
        return $value === null || $value === '' || $value === [];
21
    }
22
23
    /**
24
     * Get the http value or the default one if it's empty
25
     * Note: If not default value is provided, the http value is returned
26
     *
27
     * @param mixed $value
28
     * @param mixed $default
29
     *
30
     * @return mixed The value or the default
31
     */
32 136
    public static function orDefault($value, $default)
33
    {
34 136
        if ($default === null || !self::isEmpty($value)) {
35 113
            return $value;
36
        }
37
38 26
        return $default;
39
    }
40
}
41