Week::value()   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 0
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 DateTime;
8
use Webmozart\Assert\Assert;
9
10
/**
11
 * @author Toni Van de Voorde <[email protected]>
12
 */
13
final class Week
14
{
15
    /**
16
     * @var int
17
     */
18
    private $value;
19
20
    /**
21
     * @param int $value
22
     */
23 4
    public function __construct(int $value)
24
    {
25 4
        Assert::range($value, 1, 53);
26 2
        $this->value = $value;
27 2
    }
28
29
    /**
30
     * @return int
31
     */
32 2
    public function value(): int
33
    {
34 2
        return $this->value;
35
    }
36
37
    /**
38
     * @param Week $week
39
     * @return bool
40
     */
41 2
    public function equals(Week $week): bool
42
    {
43 2
        return $this->value === $week->value();
44
    }
45
46
    /**
47
     * @return Week
48
     */
49
    public static function now(): self
50
    {
51
        $now = new DateTime('now');
52
53
        return self::fromDateTime($now);
54
    }
55
56
    /**
57
     * @param \DateTimeInterface $dateTime
58
     * @return Week
59
     */
60 2
    public static function fromDateTime(\DateTimeInterface $dateTime): self
61
    {
62 2
        $week = \intval($dateTime->format('W'));
63
64 2
        return new self($week);
65
    }
66
}
67