Minute::fromNative()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
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 Minute extends Natural
9
{
10
    const MIN_MINUTE = 0;
11
12
    const MAX_MINUTE = 59;
13
14
    /**
15
     * Returns a new Minute from native int value
16
     *
17
     * @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...
18
     * @return Minute
19
     */
20 1
    public static function fromNative()
21
    {
22 1
        $value = func_get_arg(0);
23
24 1
        return new static($value);
25
    }
26
27
    /**
28
     * Returns a new Minute object
29
     *
30
     * @param int $value
31
     */
32 31
    public function __construct($value)
33
    {
34
        $options = array(
35 31
            'options' => array('min_range' => self::MIN_MINUTE, 'max_range' => self::MAX_MINUTE)
36 31
        );
37
38 31
        $filteredValue = filter_var($value, FILTER_VALIDATE_INT, $options);
39
40 31
        if (false === $filteredValue) {
41 1
            throw new InvalidNativeArgumentException($value, array('int (>=0, <=59)'));
42
        }
43
44 30
        parent::__construct($filteredValue);
45 30
    }
46
47
    /**
48
     * Returns the current minute.
49
     *
50
     * @return Minute
51
     */
52 4
    public static function now()
53
    {
54 4
        $now    = new \DateTime('now');
55 4
        $minute = \intval($now->format('i'));
56
57 4
        return new static($minute);
58
    }
59
}
60