Total Complexity | 8 |
Total Lines | 75 |
Duplicated Lines | 0 % |
Coverage | 57.89% |
Changes | 0 |
1 | <?php |
||
14 | final class Semester |
||
15 | { |
||
16 | /** |
||
17 | * @var int |
||
18 | */ |
||
19 | private $value; |
||
20 | |||
21 | /** |
||
22 | * @param int $value |
||
23 | */ |
||
24 | 12 | private function __construct(int $value) |
|
25 | { |
||
26 | 12 | Assert::range($value, 1, 2); |
|
27 | 12 | $this->value = $value; |
|
28 | 12 | } |
|
29 | |||
30 | /** |
||
31 | * @return int |
||
32 | */ |
||
33 | 12 | public function value(): int |
|
34 | { |
||
35 | 12 | return $this->value; |
|
36 | } |
||
37 | |||
38 | /** |
||
39 | * @param Semester $semester |
||
40 | * @return bool |
||
41 | */ |
||
42 | 12 | public function equals(Semester $semester): bool |
|
43 | { |
||
44 | 12 | return $this->value === $semester->value(); |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * @return Semester |
||
49 | */ |
||
50 | public static function first(): self |
||
51 | { |
||
52 | return new self(1); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @return Semester |
||
57 | */ |
||
58 | public static function second(): self |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @return Semester |
||
65 | */ |
||
66 | public static function now(): self |
||
67 | { |
||
68 | return self::fromDateTime(new DateTime('now')); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @param DateTimeInterface $dateTime |
||
73 | * @return Semester |
||
74 | */ |
||
75 | 12 | public static function fromDateTime(DateTimeInterface $dateTime): self |
|
76 | { |
||
77 | 12 | $semester = ceil($dateTime->format('n') / 6); |
|
78 | |||
79 | 12 | return new self((int)$semester); |
|
80 | } |
||
81 | |||
82 | /** |
||
83 | * @param int $value |
||
84 | * @return Semester |
||
85 | */ |
||
86 | public static function fromValue(int $value) |
||
89 | } |
||
90 | } |
||
91 |