Week   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 78.56%

Importance

Changes 0
Metric Value
dl 0
loc 52
ccs 11
cts 14
cp 0.7856
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

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