Month   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A now() 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 \DateTime
36
     *
37
     * @param  \DateTime $date
38
     * @return Month
39
     */
40 8
    public static function fromNativeDateTime(\DateTime $date)
41
    {
42 8
        $month = \strtoupper($date->format('F'));
43
44 8
        return static::getByName($month);
0 ignored issues
show
Deprecated Code introduced by
The method MabeEnum\Enum::getByName() has been deprecated.

This method has been deprecated.

Loading history...
45
    }
46
47
    /**
48
     * Returns a numeric representation of the Month.
49
     * 1 for January to 12 for December.
50
     *
51
     * @return int
52
     */
53 11
    public function getNumericValue()
54
    {
55 11
        return $this->getOrdinal() + 1;
56
    }
57
}
58