Completed
Push — develop ( 8e6584...40375e )
by Baptiste
02:11
created

Slot::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 2
dl 0
loc 14
ccs 7
cts 7
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace PersonalGalaxy\Calendar\Entity\Event;
5
6
use PersonalGalaxy\Calendar\Exception\{
7
    LogicException,
8
    EmptySlot,
9
};
10
use Innmind\TimeContinuum\PointInTimeInterface;
11
12
final class Slot
13
{
14
    private $start;
15
    private $end;
16
17 29
    public function __construct(
18
        PointInTimeInterface $start,
19
        PointInTimeInterface $end
20
    ) {
21 29
        if ($start->aheadOf($end)) {
22 1
            throw new LogicException;
23
        }
24
25 28
        if ($start->equals($end)) {
26 1
            throw new EmptySlot;
27
        }
28
29 27
        $this->start = $start;
30 27
        $this->end = $end;
31 27
    }
32
33 15
    public function start(): PointInTimeInterface
34
    {
35 15
        return $this->start;
36
    }
37
38 9
    public function end(): PointInTimeInterface
39
    {
40 9
        return $this->end;
41
    }
42
43 9
    public function overlaps(self $slot): bool
44
    {
45
        /**
46
         * this: |----|
47
         * slot:        |----|
48
         */
49 9
        if ($slot->start()->aheadOf($this->end)) {
50 1
            return false;
51
        }
52
53
        /**
54
         * this:        |----|
55
         * slot: |----|
56
         */
57 8
        if ($this->start->aheadOf($slot->end())) {
58 1
            return false;
59
        }
60
61
        /**
62
         * this: |----|
63
         * slot:      |----|
64
         */
65 7
        if ($slot->start()->equals($this->end)) {
66 1
            return false;
67
        }
68
69
        /**
70
         * this:      |----|
71
         * slot: |----|
72
         */
73 6
        if ($this->start->equals($slot->end())) {
74 1
            return false;
75
        }
76
77 5
        return true;
78
    }
79
}
80