Total Complexity | 19 |
Total Lines | 118 |
Duplicated Lines | 0 % |
Coverage | 67.65% |
Changes | 0 |
1 | <?php |
||
13 | final class WeekDay |
||
14 | { |
||
15 | /** |
||
16 | * @var int |
||
17 | */ |
||
18 | private $number; |
||
19 | |||
20 | /** |
||
21 | * @param int $number |
||
22 | */ |
||
23 | 9 | private function __construct(int $number) |
|
24 | { |
||
25 | 9 | Assert::range($number, 1, 7); |
|
26 | 9 | $this->number = $number; |
|
27 | 9 | } |
|
28 | |||
29 | /** |
||
30 | * @return int |
||
31 | */ |
||
32 | 9 | public function number(): int |
|
33 | { |
||
34 | 9 | return $this->number; |
|
35 | } |
||
36 | |||
37 | /** |
||
38 | * @param WeekDay $weekDay |
||
39 | * @return bool |
||
40 | */ |
||
41 | 9 | public function equals(WeekDay $weekDay): bool |
|
42 | { |
||
43 | 9 | return $this->number === $weekDay->number(); |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * @return WeekDay |
||
48 | */ |
||
49 | public static function monday(): self |
||
50 | { |
||
51 | return new self(1); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @return WeekDay |
||
56 | */ |
||
57 | public static function tuesday(): self |
||
58 | { |
||
59 | return new self(2); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @return WeekDay |
||
64 | */ |
||
65 | public static function wednesday(): self |
||
66 | { |
||
67 | return new self(3); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @return WeekDay |
||
72 | */ |
||
73 | public static function thursday(): self |
||
74 | { |
||
75 | return new self(4); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @return WeekDay |
||
80 | */ |
||
81 | 1 | public static function friday(): self |
|
82 | { |
||
83 | 1 | return new self(5); |
|
84 | } |
||
85 | |||
86 | /** |
||
87 | * @return WeekDay |
||
88 | */ |
||
89 | public static function saturday(): self |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * @return WeekDay |
||
96 | */ |
||
97 | 1 | public static function sunday(): self |
|
98 | { |
||
99 | 1 | return new self(7); |
|
100 | } |
||
101 | |||
102 | /** |
||
103 | * @param DateTimeInterface $dateTime |
||
104 | * @return WeekDay |
||
105 | */ |
||
106 | 2 | final public static function fromDateTime(DateTimeInterface $dateTime): self |
|
107 | { |
||
108 | 2 | return WeekDay::fromNumber((int)$dateTime->format('N')); |
|
109 | } |
||
110 | |||
111 | /** |
||
112 | * Returns a WeekDay instance from a numeric value. The representation is according to ISO-8601. |
||
113 | * |
||
114 | * @param int $number |
||
115 | * @return WeekDay |
||
116 | */ |
||
117 | 9 | final public static function fromNumber(int $number): self |
|
131 | } |
||
132 | } |
||
133 |