Month::february()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Adlogix\EventScheduler\ValueObject;
6
7
use DateTimeInterface;
8
9
/**
10
 * @author Toni Van de Voorde <[email protected]>
11
 */
12
final class Month
13
{
14
    /**
15
     * @var int
16
     */
17
    private $number;
18
19
    /**
20
     * @param int $number
21
     */
22 22
    private function __construct(int $number)
23
    {
24 22
        $this->number = $number;
25 22
    }
26
27
    /**
28
     * @return int
29
     */
30 20
    public function number()
31
    {
32 20
        return $this->number;
33
    }
34
35
    /**
36
     * @param Month $month
37
     * @return bool
38
     */
39 17
    public function equals(Month $month): bool
40
    {
41 17
        return $this->number === $month->number();
42
    }
43
44
    /**
45
     * @return Month
46
     */
47
    final public static function january(): self
48
    {
49
        return new self(1);
50
    }
51
52
    /**
53
     * @return Month
54
     */
55
    final public static function february(): self
56
    {
57
        return new self(2);
58
    }
59
60
    /**
61
     * @return Month
62
     */
63
    final public static function march(): self
64
    {
65
        return new self(3);
66
    }
67
68
    /**
69
     * @return Month
70
     */
71 1
    final public static function april(): self
72
    {
73 1
        return new self(4);
74
    }
75
76
    /**
77
     * @return Month
78
     */
79
    final public static function may(): self
80
    {
81
        return new self(5);
82
    }
83
84
    /**
85
     * @return Month
86
     */
87
    final public static function june(): self
88
    {
89
        return new self(6);
90
    }
91
92
    /**
93
     * @return Month
94
     */
95
    final public static function july(): self
96
    {
97
        return new self(7);
98
    }
99
100
    /**
101
     * @return Month
102
     */
103
    final public static function august(): self
104
    {
105
        return new self(8);
106
    }
107
108
    /**
109
     * @return Month
110
     */
111
    final public static function september(): self
112
    {
113
        return new self(9);
114
    }
115
116
    /**
117
     * @return Month
118
     */
119
    final public static function october(): self
120
    {
121
        return new self(10);
122
    }
123
124
    /**
125
     * @return Month
126
     */
127 1
    final public static function november(): self
128
    {
129 1
        return new self(11);
130
    }
131
132
    /**
133
     * @return Month
134
     */
135
    final public static function december(): self
136
    {
137
        return new self(12);
138
    }
139
140
    /**
141
     * @param DateTimeInterface $dateTime
142
     * @return Month
143
     */
144 10
    final public static function fromDateTime(DateTimeInterface $dateTime): self
145
    {
146 10
        return Month::fromNumber((int)$dateTime->format('n'));
147
    }
148
149
    /**
150
     * @param int $number
151
     * @return Month
152
     */
153 22
    final public static function fromNumber(int $number): self
154
    {
155
        switch ($number) {
156 22
            case 1:
157 20
            case 2:
158 17
            case 3:
159 12
            case 4:
160 9
            case 5:
161 8
            case 6:
162 7
            case 7:
163 5
            case 8:
164 4
            case 9:
165 3
            case 10:
166 2
            case 11:
167 1
            case 12:
168 22
                return new self($number);
169
        }
170
171
        throw new \InvalidArgumentException(sprintf('Given number %d is an invalid Month number', $number));
172
    }
173
}
174