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

CellTypeHelper::isDateTimeOrDateInterval()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 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