Completed
Push — master ( 7e66ea...6a4de9 )
by Olivier
01:44
created

Event::getEndAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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
    private $classification;
16
17 6
    public function __construct(\DateTimeImmutable $startAt, \DateTimeImmutable $endAt)
18
    {
19 6
        $this->startAt = $startAt;
20 6
        $this->endAt = $endAt;
21 6
    }
22
23 3
    public function isRecurring(): bool
24
    {
25 3
        return null !== $this->recurrenceRule;
26
    }
27
28 3
    public function isARecurrence(): bool
29
    {
30 3
        return null !== $this->recurrenceId;
31
    }
32
33 1
    public function isBetween(\DateTimeImmutable $from, \DateTimeImmutable $to, bool $strict = true): bool
34
    {
35 1
        if ($strict) {
36 1
            return $this->startAt > $from && $this->endAt < $to;
37
        }
38
39 1
        if ($this->endAt < $from) {
40
            return false;
41
        }
42
43 1
        if ($this->startAt > $to) {
44
            return false;
45
        }
46
47 1
        return true;
48
    }
49
50 3
    public function getLastEventStartAt(): \DateTimeImmutable
51
    {
52 3
        if (!$this->isRecurring()) {
53
            throw new \BadMethodCallException('Not a recurring event');
54
        }
55
56 3
        return $this->getRecurrenceRule()->getLastEvent($this->getStartAt());
57
    }
58
59 4
    public function getStartAt(): ?\DateTimeImmutable
60
    {
61 4
        return $this->startAt;
62
    }
63
64 4
    public function getEndAt(): ?\DateTimeImmutable
65
    {
66 4
        return $this->endAt;
67
    }
68
69 5
    public function getSummary(): ?string
70
    {
71 5
        return $this->summary;
72
    }
73
74 5
    public function setSummary(string $summary): self
75
    {
76 5
        $this->summary = $summary;
77
78 5
        return $this;
79
    }
80
81 4
    public function getDescription(): ?string
82
    {
83 4
        return $this->description;
84
    }
85
86 5
    public function setDescription(string $description): self
87
    {
88 5
        $this->description = $description;
89
90 5
        return $this;
91
    }
92
93 3
    public function getRecurrenceRule(): ?RecurrenceRule
94
    {
95 3
        return $this->recurrenceRule;
96
    }
97
98 3
    public function setRecurrenceRule(RecurrenceRule $recurrenceRule): self
99
    {
100 3
        $this->recurrenceRule = $recurrenceRule;
101
102 3
        return $this;
103
    }
104
105 2
    public function getRecurrenceId(): ?\DateTimeImmutable
106
    {
107 2
        return $this->recurrenceId;
108
    }
109
110 2
    public function setRecurrenceId(\DateTimeImmutable $recurrenceId): self
111
    {
112 2
        $this->recurrenceId = $recurrenceId;
113
114 2
        return $this;
115
    }
116
117 1
    public function getClassification(): ?string
118
    {
119 1
        return $this->classification;
120
    }
121
122 2
    public function setClassification(string $classification): self
123
    {
124 2
        $this->classification = $classification;
125
126 2
        return $this;
127
    }
128
129 2
    public function isPrivate()
130
    {
131 2
        return 'PRIVATE' === $this->classification;
132
    }
133
134
    /**
135
     * Public by default
136
     * @see https://tools.ietf.org/html/rfc5545#section-3.8.1.3
137
     */
138 2
    public function isPublic()
139
    {
140 2
        return 'PUBLIC' === $this->classification || null === $this->classification;
141
    }
142
}
143