Completed
Pull Request — master (#68)
by Bas
03:30
created

Month::fromNative()   A

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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
namespace ValueObjects\DateTime;
4
5
use ValueObjects\Enum\Enum;
6
7
class Month extends Enum
8
{
9
    const JANUARY   = 'January';
10
    const FEBRUARY  = 'February';
11
    const MARCH     = 'March';
12
    const APRIL     = 'April';
13
    const MAY       = 'May';
14
    const JUNE      = 'June';
15
    const JULY      = 'July';
16
    const AUGUST    = 'August';
17
    const SEPTEMBER = 'September';
18
    const OCTOBER   = 'October';
19
    const NOVEMBER  = 'November';
20
    const DECEMBER  = 'December';
21
22
    /**
23
     * Get current Month
24
     *
25
     * @return Month
26
     */
27 4
    public static function now()
28
    {
29 4
        $now = new \DateTime('now');
30
31 4
        return static::fromNativeDateTime($now);
32
    }
33
34
    /**
35
     * Returns Month from a native PHP value
36
     *
37
     * @param  int $month
0 ignored issues
show
Bug introduced by
There is no parameter named $month. 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...
38
     * @return Month
39
     */
40 3
    public static function fromNative()
41
    {
42 3
        $month = func_get_arg(0);
43
44 3
        return static::getByOrdinal($month - 1);
45
    }
46
47
    /**
48
     * Returns Month from a native PHP \DateTime
49
     *
50
     * @param  \DateTime $date
51
     * @return Month
52
     */
53 8
    public static function fromNativeDateTime(\DateTime $date)
54
    {
55 8
        $month = \strtoupper($date->format('F'));
56
57 8
        return static::getByName($month);
58
    }
59
60
    /**
61
     * Returns a numeric representation of the Month.
62
     * 1 for January to 12 for December.
63
     *
64
     * @return int
65
     */
66 11
    public function getNumericValue()
67
    {
68 11
        return $this->getOrdinal() + 1;
69
    }
70
}
71