Slot   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 66
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A end() 0 3 1
A __construct() 0 14 3
B overlaps() 0 35 5
A start() 0 3 1
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 31
    public function __construct(
18
        PointInTimeInterface $start,
19
        PointInTimeInterface $end
20
    ) {
21 31
        if ($start->aheadOf($end)) {
22 1
            throw new LogicException;
23
        }
24
25 30
        if ($start->equals($end)) {
26 1
            throw new EmptySlot;
27
        }
28
29 29
        $this->start = $start;
30 29
        $this->end = $end;
31 29
    }
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