Second::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
crap 2
1
<?php
2
3
namespace ValueObjects\DateTime;
4
5
use ValueObjects\Exception\InvalidNativeArgumentException;
6
use ValueObjects\Number\Natural;
7
8
class Second extends Natural
9
{
10
    const MIN_SECOND = 0;
11
    const MAX_SECOND = 59;
12
13
    /**
14
     * Returns a new Second object
15
     *
16
     * @param int $value
17
     */
18 31
    public function __construct($value)
19
    {
20
        $options = array(
21 31
            'options' => array('min_range' => self::MIN_SECOND, 'max_range' => self::MAX_SECOND)
22 31
        );
23
24 31
        $value = filter_var($value, FILTER_VALIDATE_INT, $options);
25
26 31
        if (false === $value) {
27 1
            throw new InvalidNativeArgumentException($value, array('int (>=0, <=59)'));
28
        }
29
30 30
        parent::__construct($value);
31 30
    }
32
33
    /**
34
     * Returns the current second.
35
     *
36
     * @return Second
37
     */
38 4
    public static function now()
39
    {
40 4
        $now    = new \DateTime('now');
41 4
        $second = \intval($now->format('s'));
42
43 4
        return new static($second);
44
    }
45
}
46