Second   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 38
ccs 12
cts 12
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 2
A now() 0 7 1
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