Total Complexity | 22 |
Total Lines | 95 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
8 | final class GenericPeriod |
||
9 | { |
||
10 | /** |
||
11 | * @var DateTime |
||
12 | */ |
||
13 | private $start; |
||
14 | |||
15 | /** |
||
16 | * @var DateTime |
||
17 | */ |
||
18 | private $end; |
||
19 | |||
20 | 1 | private function __construct( |
|
21 | DateTime $start, |
||
22 | DateTime $end |
||
23 | ) { |
||
24 | 1 | $this->start = clone $start; |
|
25 | 1 | $this->end = clone $end; |
|
26 | 1 | } |
|
27 | |||
28 | 2 | public static function create( |
|
29 | DateTime $start, |
||
30 | DateTime $end |
||
31 | ) { |
||
32 | 2 | if ($start > $end) { |
|
33 | 1 | throw new EndBeforeStartException(); |
|
34 | } |
||
35 | |||
36 | 1 | return new static( |
|
37 | 1 | $start, |
|
38 | $end |
||
39 | ); |
||
40 | } |
||
41 | |||
42 | 1 | public function getStart(): DateTime |
|
43 | { |
||
44 | 1 | return $this->start; |
|
45 | } |
||
46 | |||
47 | 1 | public function getEnd(): DateTime |
|
48 | { |
||
49 | 1 | return $this->end; |
|
50 | } |
||
51 | |||
52 | 3 | public function equals(GenericPeriod $period): bool |
|
53 | { |
||
54 | 3 | return $this->getStart() == $period->getStart() |
|
55 | 3 | && $this->getEnd() == $period->getEnd(); |
|
56 | } |
||
57 | |||
58 | 2 | public function in(GenericPeriod $period): bool |
|
69 | } |
||
70 | |||
71 | 2 | public function encloses(GenericPeriod $period): bool |
|
80 | } |
||
81 | |||
82 | 5 | public function intersects(GenericPeriod $period): bool |
|
83 | { |
||
103 | } |
||
104 | } |