MonthDay::lte()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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
use Webmozart\Assert\Assert;
9
10
/**
11
 * @author Toni Van de Voorde <[email protected]>
12
 */
13
final class MonthDay
14
{
15
    /**
16
     * @var int
17
     */
18
    private $value;
19
20
    /**
21
     * @param int $value
22
     */
23 7
    public function __construct(int $value)
24
    {
25 7
        Assert::range($value, 1, 31);
26 5
        $this->value = $value;
27 5
    }
28
29
    /**
30
     * @return int
31
     */
32 5
    public function value(): int
33
    {
34 5
        return $this->value;
35
    }
36
37
    /**
38
     * @param MonthDay $month
39
     * @return bool
40
     */
41 2
    public function equals(MonthDay $month): bool
42
    {
43 2
        return $this->value === $month->value();
44
    }
45
46
    /**
47
     * @param MonthDay $monthDay
48
     * @return bool
49
     */
50 1
    public function lte(MonthDay $monthDay): bool
51
    {
52 1
        return $this->value <= $monthDay->value();
53
    }
54
55
    /**
56
     * @param MonthDay $monthDay
57
     * @return bool
58
     */
59 2
    public function gte(MonthDay $monthDay): bool
60
    {
61 2
        return $this->value >= $monthDay->value();
62
    }
63
64
    /**
65
     * @param DateTimeInterface $dateTime
66
     * @return MonthDay
67
     */
68 5
    public static function fromDateTime(DateTimeInterface $dateTime): self
69
    {
70 5
        return new self((int)$dateTime->format('j'));
71
    }
72
}
73