Total Complexity | 12 |
Total Lines | 74 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
10 | final class Date |
||
11 | { |
||
12 | /** |
||
13 | * @var DateTimeInterface|null Minimum date. |
||
14 | */ |
||
15 | private $min; |
||
16 | |||
17 | /** |
||
18 | * @var DateTimeInterface|null Maximum date. |
||
19 | */ |
||
20 | private $max; |
||
21 | |||
22 | /** |
||
23 | * @var int Constraint weight. |
||
24 | */ |
||
25 | private $weight; |
||
26 | |||
27 | /** |
||
28 | * @param DateTimeInterface|null $min Minimum date. |
||
29 | * @param DateTimeInterface|null $max Maximum date. |
||
30 | * @param int $weight Constraint weight. |
||
31 | */ |
||
32 | 7 | public function __construct(?DateTimeInterface $min, ?DateTimeInterface $max = null, int $weight = 1) |
|
33 | { |
||
34 | 7 | if ($min !== null && $max !== null && $max < $min) { |
|
35 | 1 | throw new InvalidArgumentException('Max cannot be smaller than min.'); |
|
36 | } |
||
37 | |||
38 | 6 | $this->min = $min; |
|
39 | 6 | $this->max = $max; |
|
40 | 6 | $this->weight = $weight; |
|
41 | 6 | } |
|
42 | |||
43 | /** |
||
44 | * @return DateTimeInterface|null Minimum date. |
||
45 | */ |
||
46 | 1 | public function getMin(): ?DateTimeInterface |
|
47 | { |
||
48 | 1 | return $this->min; |
|
49 | } |
||
50 | |||
51 | /** |
||
52 | * @return DateTimeInterface|null Maximum date. |
||
53 | */ |
||
54 | 1 | public function getMax(): ?DateTimeInterface |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * @return int Constraint weight. |
||
61 | */ |
||
62 | 1 | public function getWeight(): int |
|
65 | } |
||
66 | |||
67 | /** |
||
68 | * Check whether the date is in compliance with the constraint. |
||
69 | * |
||
70 | * @param DateTimeInterface $date Date to check. |
||
71 | * @return bool Whether the date is in compliance with the constraint. |
||
72 | */ |
||
73 | 4 | public function test(DateTimeInterface $date): bool |
|
84 | } |
||
85 | } |
||
86 |