Hour::now()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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