TsRange::getSubElement()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 4
nc 4
nop 1
1
<?php
2
/*
3
 * This file is part of PommProject's Foundation package.
4
 *
5
 * (c) 2014 Grégoire HUBERT <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PommProject\Foundation\Converter\Type;
11
12
/**
13
 * TsRange
14
 *
15
 * Type for range of timestamps.
16
 *
17
 * @package Foundation
18
 * @copyright 2014 Grégoire HUBERT
19
 * @author Grégoire HUBERT
20
 * @license X11 {@link http://opensource.org/licenses/mit-license.php}
21
 */
22
class TsRange extends BaseRange
23
{
24
    /**
25
     * getRegexp
26
     *
27
     * @see BaseRange
28
     */
29
    protected function getRegexp()
30
    {
31
        return '/(empty)|([\[\(])"?([0-9 :+\.-]+|-?infinity)?"?, *"?([0-9 :+\.-]+|-?infinity)?"?([\]\)])/';
32
    }
33
34
    /**
35
     * getSubElement
36
     *
37
     * @see BaseRange
38
     */
39
    protected function getSubElement($element)
40
    {
41
        if ($element === BaseRange::INFINITY_MIN) {
42
            return BaseRange::INFINITY_MIN;
43
        } elseif ($element === BaseRange::INFINITY_MAX) {
44
            return BaseRange::INFINITY_MAX;
45
        } elseif ($element === '') {
46
            return null;
47
        }
48
49
        return new \DateTime($element);
50
    }
51
}
52