Completed
Push — master ( 0b5802...c126d3 )
by Amine
02:04 queued 26s
created

Pause::getEnd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace AmineBenHariz\Attendance;
4
5
/**
6
 * Class Pause
7
 * @package AmineBenHariz\Attendance
8
 */
9
class Pause
10
{
11
    /**
12
     * @var \DateTime
13
     */
14
    private $start;
15
16
    /**
17
     * @var \DateTime
18
     */
19
    private $end;
20
21
    /**
22
     * Pause constructor.
23
     * @param \DateTime $start
24
     * @param \DateTime $end
25
     */
26 12
    public function __construct(\DateTime $start, \DateTime $end)
27
    {
28 12
        if ($start > $end) {
29 4
            throw new \InvalidArgumentException("Pause can't start after ending");
30
        }
31
32 8
        if ($start->format('Y-m-d') !== $end->format('Y-m-d')) {
33 4
            throw new \InvalidArgumentException("Pause must end in the same day");
34
        }
35
36 4
        $this->start = $start;
37 4
        $this->end = $end;
38 4
    }
39
40
    /**
41
     * @return \DateTime
42
     */
43 20
    public function getStart()
44
    {
45 20
        return $this->start;
46
    }
47
48
    /**
49
     * @return \DateTime
50
     */
51 20
    public function getEnd()
52
    {
53 20
        return $this->end;
54
    }
55
56
    /**
57
     * @param Pause $pause
58
     * @return bool
59
     */
60 16
    public function isOverlapping(Pause $pause)
61
    {
62 16
        if ($this->getEnd() <= $pause->getStart()) {
63 8
            return false;
64
        }
65
66 16
        if ($this->getStart() >= $pause->getEnd()) {
67 8
            return false;
68
        }
69
70 8
        return true;
71
    }
72
}
73