Completed
Push — master ( 2a5d39...9c9098 )
by Olivier
02:26
created

Event::isBetween()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 5.3906

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 6
cts 8
cp 0.75
rs 9.4222
c 0
b 0
f 0
cc 5
nc 5
nop 3
crap 5.3906
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shapin\Calendar\Model;
6
7
class Event
8
{
9
    private $startAt;
10
    private $endAt;
11
    private $summary;
12
    private $description;
13
    private $recurrenceRule;
14
    private $recurrenceId;
15
16 4
    public function __construct(\DateTimeImmutable $startAt, \DateTimeImmutable $endAt)
17
    {
18 4
        $this->startAt = $startAt;
19 4
        $this->endAt = $endAt;
20 4
    }
21
22 3
    public function isRecurring(): bool
23
    {
24 3
        return null !== $this->recurrenceRule;
25
    }
26
27 3
    public function isARecurrence(): bool
28
    {
29 3
        return null !== $this->recurrenceId;
30
    }
31
32 1
    public function isBetween(\DateTimeImmutable $from, \DateTimeImmutable $to, bool $strict = true): bool
33
    {
34 1
        if ($strict) {
35 1
            return $this->startAt > $from && $this->endAt < $to;
36
        }
37
38 1
        if ($this->endAt < $from) {
39
            return false;
40
        }
41
42 1
        if ($this->startAt > $to) {
43
            return false;
44
        }
45
46 1
        return true;
47
    }
48
49 3
    public function getLastEventStartAt(): \DateTimeImmutable
50
    {
51 3
        if (!$this->isRecurring()) {
52
            throw new \BadMethodCallException('Not a recurring event');
53
        }
54
55 3
        return $this->getRecurrenceRule()->getLastEvent($this->getStartAt());
56
    }
57
58 3
    public function getStartAt(): ?\DateTimeImmutable
59
    {
60 3
        return $this->startAt;
61
    }
62
63 3
    public function getEndAt(): ?\DateTimeImmutable
64
    {
65 3
        return $this->endAt;
66
    }
67
68 3
    public function getSummary(): ?string
69
    {
70 3
        return $this->summary;
71
    }
72
73 3
    public function setSummary(string $summary): self
74
    {
75 3
        $this->summary = $summary;
76
77 3
        return $this;
78
    }
79
80 3
    public function getDescription(): ?string
81
    {
82 3
        return $this->description;
83
    }
84
85 3
    public function setDescription(string $description): self
86
    {
87 3
        $this->description = $description;
88
89 3
        return $this;
90
    }
91
92 3
    public function getRecurrenceRule(): ?RecurrenceRule
93
    {
94 3
        return $this->recurrenceRule;
95
    }
96
97 3
    public function setRecurrenceRule(RecurrenceRule $recurrenceRule): self
98
    {
99 3
        $this->recurrenceRule = $recurrenceRule;
100
101 3
        return $this;
102
    }
103
104 2
    public function getRecurrenceId(): ?\DateTimeImmutable
105
    {
106 2
        return $this->recurrenceId;
107
    }
108
109 2
    public function setRecurrenceId(\DateTimeImmutable $recurrenceId): self
110
    {
111 2
        $this->recurrenceId = $recurrenceId;
112
113 2
        return $this;
114
    }
115
}
116