1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace CalendarBundle\Entity; |
6
|
|
|
|
7
|
|
|
class Event |
8
|
|
|
{ |
9
|
|
|
// 2018-09-01T12:30:00+XX:XX |
10
|
|
|
public const DATE_FORMAT_ISO_8601_WITH_OFFSET = 'Y-m-d\\TH:i:sP'; |
11
|
|
|
// 2018-09-01T12:30:00 |
|
|
|
|
12
|
|
|
public const DATE_FORMAT_ISO_8601_WITHOUT_OFFSET = 'Y-m-d\\TH:i:s'; |
13
|
|
|
// 2018-09-01T12:30:00Z |
|
|
|
|
14
|
|
|
public const DATE_FORMAT_ISO_8601_UTC = 'Y-m-d\\TH:i:s\\Z'; |
15
|
|
|
// backward compatibility |
16
|
|
|
public const DATE_FORMAT = self::DATE_FORMAT_ISO_8601_UTC; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $title; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var \DateTimeInterface |
25
|
|
|
*/ |
26
|
|
|
protected $start; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var \DateTimeInterface |
30
|
|
|
*/ |
31
|
|
|
protected $end = null; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var bool |
35
|
|
|
*/ |
36
|
|
|
protected $allDay = true; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var array |
40
|
|
|
*/ |
41
|
|
|
protected $options = []; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
protected $dateFormat; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param \DateTimeInterface $end |
50
|
|
|
* @param string $dateFormat |
51
|
|
|
*/ |
52
|
2 |
|
public function __construct( |
53
|
|
|
string $title, |
54
|
|
|
\DateTimeInterface $start, |
55
|
|
|
\DateTimeInterface $end = null, |
56
|
|
|
array $options = [], |
57
|
|
|
string $dateFormat = self::DATE_FORMAT_ISO_8601_UTC |
58
|
|
|
) { |
59
|
2 |
|
$this->setTitle($title); |
60
|
2 |
|
$this->setStart($start); |
61
|
2 |
|
$this->setEnd($end); |
62
|
2 |
|
$this->setOptions($options); |
63
|
2 |
|
$this->setDateFormat($dateFormat); |
64
|
2 |
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
2 |
|
public function getTitle(): ?string |
70
|
|
|
{ |
71
|
2 |
|
return $this->title; |
72
|
|
|
} |
73
|
|
|
|
74
|
2 |
|
public function setTitle(string $title): void |
75
|
|
|
{ |
76
|
2 |
|
$this->title = $title; |
77
|
2 |
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return \DateTimeInterface |
81
|
|
|
*/ |
82
|
2 |
|
public function getStart(): ?\DateTimeInterface |
83
|
|
|
{ |
84
|
2 |
|
return $this->start; |
85
|
|
|
} |
86
|
|
|
|
87
|
2 |
|
public function setStart(\DateTimeInterface $start): void |
88
|
|
|
{ |
89
|
2 |
|
$this->start = $start; |
90
|
2 |
|
} |
91
|
|
|
|
92
|
2 |
|
public function getEnd(): ?\DateTimeInterface |
93
|
|
|
{ |
94
|
2 |
|
return $this->end; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param \DateTimeInterface $end |
99
|
|
|
*/ |
100
|
2 |
|
public function setEnd(?\DateTimeInterface $end): void |
101
|
|
|
{ |
102
|
2 |
|
if (null !== $end) { |
103
|
2 |
|
$this->allDay = false; |
104
|
|
|
} |
105
|
2 |
|
$this->end = $end; |
106
|
2 |
|
} |
107
|
|
|
|
108
|
1 |
|
public function isAllDay(): bool |
109
|
|
|
{ |
110
|
1 |
|
return $this->allDay; |
111
|
|
|
} |
112
|
|
|
|
113
|
1 |
|
public function setAllDay(bool $allDay): void |
114
|
|
|
{ |
115
|
1 |
|
$this->allDay = $allDay; |
116
|
1 |
|
} |
117
|
|
|
|
118
|
2 |
|
public function getOptions(): array |
119
|
|
|
{ |
120
|
2 |
|
return $this->options; |
121
|
|
|
} |
122
|
|
|
|
123
|
2 |
|
public function setOptions(array $options): void |
124
|
|
|
{ |
125
|
2 |
|
$this->options = $options; |
126
|
2 |
|
} |
127
|
|
|
|
128
|
1 |
|
public function getOption(string $name) |
129
|
|
|
{ |
130
|
1 |
|
return $this->options[$name]; |
131
|
|
|
} |
132
|
|
|
|
133
|
1 |
|
public function addOption(string $name, $value): void |
134
|
|
|
{ |
135
|
1 |
|
$this->options[$name] = $value; |
136
|
1 |
|
} |
137
|
|
|
|
138
|
1 |
|
public function removeOption(string $name) |
139
|
|
|
{ |
140
|
1 |
|
if (!isset($this->options[$name]) && !\array_key_exists($name, $this->options)) { |
141
|
1 |
|
return null; |
142
|
|
|
} |
143
|
|
|
|
144
|
1 |
|
$removed = $this->options[$name]; |
145
|
1 |
|
unset($this->options[$name]); |
146
|
|
|
|
147
|
1 |
|
return $removed; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return string |
152
|
|
|
*/ |
153
|
1 |
|
public function getDateFormat(): string |
154
|
|
|
{ |
155
|
1 |
|
return $this->dateFormat; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param string $dateFormat |
160
|
|
|
*/ |
161
|
2 |
|
public function setDateFormat(string $dateFormat): void |
162
|
|
|
{ |
163
|
2 |
|
$this->dateFormat = $dateFormat; |
164
|
2 |
|
} |
165
|
|
|
|
166
|
1 |
|
public function toArray(): array |
167
|
|
|
{ |
168
|
|
|
$event = [ |
169
|
1 |
|
'title' => $this->getTitle(), |
170
|
1 |
|
'start' => $this->getStart()->format($this->getDateFormat()), |
171
|
1 |
|
'allDay' => $this->isAllDay(), |
172
|
|
|
]; |
173
|
|
|
|
174
|
1 |
|
if (null !== $this->getEnd()) { |
175
|
1 |
|
$event['end'] = $this->getEnd()->format($this->getDateFormat()); |
176
|
|
|
} |
177
|
|
|
|
178
|
1 |
|
return array_merge($event, $this->getOptions()); |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.