Completed
Push — master ( 474cbc...4e1719 )
by Olivier
03:46
created

Event   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 0

Test Coverage

Coverage 95.92%

Importance

Changes 0
Metric Value
wmc 23
lcom 4
cbo 0
dl 0
loc 127
ccs 47
cts 49
cp 0.9592
rs 10
c 0
b 0
f 0

18 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A isRecurring() 0 4 1
A isARecurrence() 0 4 1
A isBetween() 0 16 5
A getStartAt() 0 4 1
A getEndAt() 0 4 1
A getSummary() 0 4 1
A setSummary() 0 6 1
A getDescription() 0 4 1
A setDescription() 0 6 1
A getRecurrenceRule() 0 4 1
A setRecurrenceRule() 0 6 1
A getRecurrenceId() 0 4 1
A setRecurrenceId() 0 6 1
A getClassification() 0 4 1
A setClassification() 0 6 1
A isPrivate() 0 4 1
A isPublic() 0 4 2
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 12
    public function __construct(\DateTimeImmutable $startAt, \DateTimeImmutable $endAt)
18
    {
19 12
        $this->startAt = $startAt;
20 12
        $this->endAt = $endAt;
21 12
    }
22
23 10
    public function isRecurring(): bool
24
    {
25 10
        return null !== $this->recurrenceRule;
26
    }
27
28 4
    public function isARecurrence(): bool
29
    {
30 4
        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 10
    public function getStartAt(): ?\DateTimeImmutable
51
    {
52 10
        return $this->startAt;
53
    }
54
55 9
    public function getEndAt(): ?\DateTimeImmutable
56
    {
57 9
        return $this->endAt;
58
    }
59
60 10
    public function getSummary(): ?string
61
    {
62 10
        return $this->summary;
63
    }
64
65 9
    public function setSummary(string $summary): self
66
    {
67 9
        $this->summary = $summary;
68
69 9
        return $this;
70
    }
71
72 9
    public function getDescription(): ?string
73
    {
74 9
        return $this->description;
75
    }
76
77 9
    public function setDescription(string $description): self
78
    {
79 9
        $this->description = $description;
80
81 9
        return $this;
82
    }
83
84 8
    public function getRecurrenceRule(): ?RecurrenceRule
85
    {
86 8
        return $this->recurrenceRule;
87
    }
88
89 8
    public function setRecurrenceRule(RecurrenceRule $recurrenceRule): self
90
    {
91 8
        $this->recurrenceRule = $recurrenceRule;
92
93 8
        return $this;
94
    }
95
96 2
    public function getRecurrenceId(): ?\DateTimeImmutable
97
    {
98 2
        return $this->recurrenceId;
99
    }
100
101 2
    public function setRecurrenceId(\DateTimeImmutable $recurrenceId): self
102
    {
103 2
        $this->recurrenceId = $recurrenceId;
104
105 2
        return $this;
106
    }
107
108 2
    public function getClassification(): ?string
109
    {
110 2
        return $this->classification;
111
    }
112
113 2
    public function setClassification(string $classification): self
114
    {
115 2
        $this->classification = $classification;
116
117 2
        return $this;
118
    }
119
120 3
    public function isPrivate()
121
    {
122 3
        return 'PRIVATE' === $this->classification;
123
    }
124
125
    /**
126
     * Public by default
127
     * @see https://tools.ietf.org/html/rfc5545#section-3.8.1.3
128
     */
129 3
    public function isPublic()
130
    {
131 3
        return 'PUBLIC' === $this->classification || null === $this->classification;
132
    }
133
}
134