Trimester::second()   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 DateTime;
8
use Webmozart\Assert\Assert;
9
10
/**
11
 * @author Toni Van de Voorde <[email protected]>
12
 */
13
final class Trimester
14
{
15
    /**
16
     * @var int
17
     */
18
    private $value;
19
20
    /**
21
     * @param int $value
22
     */
23 16
    private function __construct(int $value)
24
    {
25 16
        Assert::range($value, 1, 4);
26 16
        $this->value = $value;
27 16
    }
28
29
    /**
30
     * @return int
31
     */
32 16
    public function value(): int
33
    {
34 16
        return $this->value;
35
    }
36
37
    /**
38
     * @param Trimester $trimester
39
     * @return bool
40
     */
41 16
    public function equals(Trimester $trimester): bool
42
    {
43 16
        return $this->value === $trimester->value();
44
    }
45
46
    /**
47
     * @return Trimester
48
     */
49
    public static function first(): self
50
    {
51
        return new self(1);
52
    }
53
54
    /**
55
     * @return Trimester
56
     */
57
    public static function second(): self
58
    {
59
        return new self(2);
60
    }
61
62
    /**
63
     * @return Trimester
64
     */
65
    public static function third(): self
66
    {
67
        return new self(3);
68
    }
69
70
    /**
71
     * @return Trimester
72
     */
73
    public static function fourth(): self
74
    {
75
        return new self(4);
76
    }
77
78
    /**
79
     * @return Trimester
80
     */
81
    public static function now(): self
82
    {
83
        $now = new DateTime('now');
84
        return self::fromNDateTime($now);
85
    }
86
87
    /**
88
     * @param \DateTimeInterface $date
89
     * @return Trimester
90
     */
91 16
    public static function fromNDateTime(\DateTimeInterface $date): self
92
    {
93 16
        $semester = ceil($date->format('n') / 3);
94 16
        return new self((int)$semester);
95
    }
96
}
97