MonthDay   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 58
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A gte() 0 3 1
A lte() 0 3 1
A fromDateTime() 0 3 1
A equals() 0 3 1
A value() 0 3 1
A __construct() 0 4 1
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