Passed
Pull Request — develop_3.0 (#510)
by Adrien
03:43
created

CellTypeHelper   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 0
dl 0
loc 60
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A isEmpty() 0 4 2
A isNonEmptyString() 0 4 2
A isNumeric() 0 6 2
A isBoolean() 0 4 1
A isDateTimeOrDateInterval() 0 7 2
1
<?php
2
3
namespace Box\Spout\Common\Helper;
4
5
/**
6
 * Class CellTypeHelper
7
 * This class provides helper functions to determine the type of the cell value
8
 */
9
class CellTypeHelper
10
{
11
    /**
12
     * @param $value
13
     * @return bool Whether the given value is considered "empty"
14
     */
15 180
    public static function isEmpty($value)
16
    {
17 180
        return ($value === null || $value === '');
18
    }
19
20
    /**
21
     * @param $value
22
     * @return bool Whether the given value is a non empty string
23
     */
24 165
    public static function isNonEmptyString($value)
25
    {
26 165
        return (gettype($value) === 'string' && $value !== '');
27
    }
28
29
    /**
30
     * Returns whether the given value is numeric.
31
     * A numeric value is from type "integer" or "double" ("float" is not returned by gettype).
32
     *
33
     * @param $value
34
     * @return bool Whether the given value is numeric
35
     */
36 173
    public static function isNumeric($value)
37
    {
38 173
        $valueType = gettype($value);
39
40 173
        return ($valueType === 'integer' || $valueType === 'double');
41
    }
42
43
    /**
44
     * Returns whether the given value is boolean.
45
     * "true"/"false" and 0/1 are not booleans.
46
     *
47
     * @param $value
48
     * @return bool Whether the given value is boolean
49
     */
50 183
    public static function isBoolean($value)
51
    {
52 183
        return gettype($value) === 'boolean';
53
    }
54
55
    /**
56
     * Returns whether the given value is a DateTime or DateInterval object.
57
     *
58
     * @param $value
59
     * @return bool Whether the given value is a DateTime or DateInterval object
60
     */
61 85
    public static function isDateTimeOrDateInterval($value)
62
    {
63
        return (
64 85
            $value instanceof \DateTime ||
65 85
            $value instanceof \DateInterval
66
        );
67
    }
68
}
69