Hour   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 51
ccs 15
cts 15
cp 1
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromNative() 0 6 1
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 Hour extends Natural
9
{
10
    const MIN_HOUR = 0;
11
    const MAX_HOUR = 23;
12
13
    /**
14
     * Returns a new Hour from native int value
15
     *
16
     * @param  int  $value
0 ignored issues
show
Bug introduced by
There is no parameter named $value. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
17
     * @return Hour
18
     */
19 1
    public static function fromNative()
20
    {
21 1
        $value = func_get_arg(0);
22
23 1
        return new static($value);
24
    }
25
26
    /**
27
     * Returns a new Hour object
28
     *
29
     * @param int $value
30
     */
31 31
    public function __construct($value)
32
    {
33
        $options = array(
34 31
            'options' => array('min_range' => self::MIN_HOUR, 'max_range' => self::MAX_HOUR)
35 31
        );
36
37 31
        $filteredValue = filter_var($value, FILTER_VALIDATE_INT, $options);
38
39 31
        if (false === $filteredValue) {
40 1
            throw new InvalidNativeArgumentException($value, array('int (>=0, <=23)'));
41
        }
42
43 30
        parent::__construct($filteredValue);
44 30
    }
45
46
    /**
47
     * Returns the current hour.
48
     *
49
     * @return Hour
50
     */
51 4
    public static function now()
52
    {
53 4
        $now  = new \DateTime('now');
54 4
        $hour = \intval($now->format('G'));
55
56 4
        return new static($hour);
57
    }
58
}
59