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

Month   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A now() 0 6 1
A fromNative() 0 6 1
A fromNativeDateTime() 0 6 1
A getNumericValue() 0 4 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