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

HttpValue   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 5
c 1
b 0
f 0
dl 0
loc 31
ccs 6
cts 6
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A orDefault() 0 7 3
A isEmpty() 0 3 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