Completed
Push — master ( 5c1695...d9ce31 )
by Theo
03:38 queued 20s
created

Event::getCustomFieldValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Toiba\FullCalendarBundle\Entity;
4
5
class Event
6
{
7
    /**
8
     * @var int
9
     */
10
    protected $id;
11
12
    /**
13
     * @var string
14
     */
15
    protected $title;
16
17
    /**
18
     * @var bool
19
     */
20
    protected $allDay = true;
21
22
    /**
23
     * @var \DateTimeInterface
24
     */
25
    protected $startDate;
26
27
    /**
28
     * @var \DateTimeInterface
29
     */
30
    protected $endDate = null;
31
32
    /**
33
     * @var string
34
     */
35
    protected $url;
36
37
    /**
38
     * @var string
39
     */
40
    protected $className;
41
42
    /**
43
     * @var bool
44
     */
45
    protected $editable = false;
46
47
    /**
48
     * @var bool
49
     */
50
    protected $startEditable = false;
51
52
    /**
53
     * @var bool
54
     */
55
    protected $durationEditable = false;
56
57
    /**
58
     * @var string
59
     */
60
    protected $rendering;
61
62
    /**
63
     * @var bool
64
     */
65
    protected $overlap = true;
66
67
    /**
68
     * @var int
69
     */
70
    protected $constraint;
71
72
    /**
73
     * @var string
74
     */
75
    protected $source;
76
77
    /**
78
     * @var string
79
     */
80
    protected $color;
81
82
    /**
83
     * @var string
84
     */
85
    protected $backgroundColor;
86
87
    /**
88
     * @var string
89
     */
90
    protected $textColor;
91
92
    /**
93
     * @var array
94
     */
95
    protected $customFields = [];
96
97
    /**
98
     * @param string             $title
99
     * @param \DateTimeInterface $start
100
     * @param \DateTimeInterface $end
101
     */
102
    public function __construct(
103
        string $title,
104
        \DateTimeInterface $start,
105
        \DateTimeInterface $end = null
106
    ) {
107
        $this->setTitle($title);
108
        $this->setStartDate($start);
109
        $this->setEndDate($end);
110
    }
111
112
    /**
113
     * @return int|string
114
     */
115
    public function getId()
116
    {
117
        return $this->id;
118
    }
119
120
    /**
121
     * @param int|string $id
122
     */
123
    public function setId($id): void
124
    {
125
        $this->id = $id;
0 ignored issues
show
Documentation Bug introduced by
It seems like $id can also be of type string. However, the property $id is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
126
    }
127
128
    /**
129
     * @return string
130
     */
131
    public function getTitle(): ?string
132
    {
133
        return $this->title;
134
    }
135
136
    /**
137
     * @param string $title
138
     */
139
    public function setTitle(string $title): void
140
    {
141
        $this->title = $title;
142
    }
143
144
    /**
145
     * @return bool
146
     */
147
    public function isAllDay(): bool
148
    {
149
        return $this->allDay;
150
    }
151
152
    /**
153
     * @param bool $allDay
154
     */
155
    public function setAllDay(bool $allDay): void
156
    {
157
        $this->allDay = $allDay;
158
    }
159
160
    /**
161
     * @return \DateTimeInterface
162
     */
163
    public function getStartDate(): ?\DateTimeInterface
164
    {
165
        return $this->startDate;
166
    }
167
168
    /**
169
     * @param \DateTimeInterface $startDate
170
     */
171
    public function setStartDate(\DateTimeInterface $startDate): void
172
    {
173
        $this->startDate = $startDate;
174
    }
175
176
    /**
177
     * @return \DateTimeInterface
178
     */
179
    public function getEndDate(): ?\DateTimeInterface
180
    {
181
        return $this->endDate;
182
    }
183
184
    /**
185
     * @param \DateTimeInterface $endDate
186
     */
187
    public function setEndDate(\DateTimeInterface $endDate = null): void
188
    {
189
        if (null !== $endDate) {
190
            $this->allDay = false;
191
        }
192
        $this->endDate = $endDate;
193
    }
194
195
    /**
196
     * @return string
197
     */
198
    public function getUrl(): ?string
199
    {
200
        return $this->url;
201
    }
202
203
    /**
204
     * @param string $url
205
     */
206
    public function setUrl(?string $url): void
207
    {
208
        $this->url = $url;
209
    }
210
211
    /**
212
     * @return string
213
     */
214
    public function getClassName(): ?string
215
    {
216
        return $this->className;
217
    }
218
219
    /**
220
     * @param string $className
221
     */
222
    public function setClassName(?string $className): void
223
    {
224
        $this->className = $className;
225
    }
226
227
    /**
228
     * @return bool
229
     */
230
    public function isEditable(): bool
231
    {
232
        return $this->editable;
233
    }
234
235
    /**
236
     * @param bool $editable
237
     */
238
    public function setEditable(bool $editable): void
239
    {
240
        $this->editable = $editable;
241
    }
242
243
    /**
244
     * @return bool
245
     */
246
    public function isStartEditable(): bool
247
    {
248
        return $this->startEditable;
249
    }
250
251
    /**
252
     * @param bool $startEditable
253
     */
254
    public function setStartEditable(bool $startEditable): void
255
    {
256
        $this->startEditable = $startEditable;
257
    }
258
259
    /**
260
     * @return bool
261
     */
262
    public function isDurationEditable(): bool
263
    {
264
        return $this->durationEditable;
265
    }
266
267
    /**
268
     * @param bool $durationEditable
269
     */
270
    public function setDurationEditable(bool $durationEditable): void
271
    {
272
        $this->durationEditable = $durationEditable;
273
    }
274
275
    /**
276
     * @return string
277
     */
278
    public function getRendering(): ?string
279
    {
280
        return $this->rendering;
281
    }
282
283
    /**
284
     * @param string $rendering
285
     */
286
    public function setRendering(?string $rendering): void
287
    {
288
        $this->rendering = $rendering;
289
    }
290
291
    /**
292
     * @return bool
293
     */
294
    public function isOverlap(): bool
295
    {
296
        return $this->overlap;
297
    }
298
299
    /**
300
     * @param bool $overlap
301
     */
302
    public function setOverlap(bool $overlap): void
303
    {
304
        $this->overlap = $overlap;
305
    }
306
307
    /**
308
     * @return array
309
     */
310
    public function getConstraint(): ?array
311
    {
312
        return $this->constraint;
313
    }
314
315
    /**
316
     * @param array $constraint
317
     */
318
    public function setConstraint(?array $constraint): void
319
    {
320
        $this->constraint = $constraint;
0 ignored issues
show
Documentation Bug introduced by
It seems like $constraint of type array is incompatible with the declared type integer of property $constraint.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
321
    }
322
323
    /**
324
     * @return string
325
     */
326
    public function getSource(): ?string
327
    {
328
        return $this->source;
329
    }
330
331
    /**
332
     * @param string $source
333
     */
334
    public function setSource(?string $source): void
335
    {
336
        $this->source = $source;
337
    }
338
339
    /**
340
     * @return string
341
     */
342
    public function getColor(): ?string
343
    {
344
        return $this->color;
345
    }
346
347
    /**
348
     * @param string $color
349
     */
350
    public function setColor(?string $color): void
351
    {
352
        $this->color = $color;
353
    }
354
355
    /**
356
     * @return string
357
     */
358
    public function getBackgroundColor(): ?string
359
    {
360
        return $this->backgroundColor;
361
    }
362
363
    /**
364
     * @param string $backgroundColor
365
     */
366
    public function setBackgroundColor(?string $backgroundColor): void
367
    {
368
        $this->backgroundColor = $backgroundColor;
369
    }
370
371
    /**
372
     * @return string
373
     */
374
    public function getTextColor(): ?string
375
    {
376
        return $this->textColor;
377
    }
378
379
    /**
380
     * @param string $textColor
381
     */
382
    public function setTextColor(?string $textColor): void
383
    {
384
        $this->textColor = $textColor;
385
    }
386
387
    /**
388
     * @param $name
389
     * @param $value
390
     *
391
     * @return mixed
392
     */
393
    public function setCustomField(?string $name, $value): void
394
    {
395
        $this->customFields[$name] = $value;
396
    }
397
398
    /**
399
     * @param $name
400
     *
401
     * @return mixed
402
     */
403
    public function getCustomFieldValue($name)
404
    {
405
        return $this->customFields[$name];
406
    }
407
408
    /**
409
     * @return array
410
     */
411
    public function getCustomFields(): array
412
    {
413
        return $this->customFields;
414
    }
415
416
    /**
417
     * @param $name
418
     *
419
     * @return mixed
420
     */
421
    public function removeCustomField($name)
422
    {
423
        if (!isset($this->customFields[$name]) && !array_key_exists($name, $this->customFields)) {
424
            return null;
425
        }
426
427
        $removed = $this->customFields[$name];
428
        unset($this->customFields[$name]);
429
430
        return $removed;
431
    }
432
433
    /**
434
     * @return array
435
     */
436
    public function toArray(): array
437
    {
438
        $event = [];
439
440
        $event['title'] = $this->getTitle();
441
        $event['start'] = $this->getStartDate()->format('Y-m-d\\TH:i:sP');
442
        $event['allDay'] = $this->isAllDay();
443
        $event['editable'] = $this->isEditable();
444
        $event['startEditable'] = $this->isStartEditable();
445
        $event['durationEditable'] = $this->isDurationEditable();
446
        $event['overlap'] = $this->isOverlap();
447
448
        if (null !== $this->getId()) {
0 ignored issues
show
introduced by
The condition null !== $this->getId() is always true.
Loading history...
449
            $event['id'] = $this->getId();
450
        }
451
452
        if (null !== $this->getUrl()) {
0 ignored issues
show
introduced by
The condition null !== $this->getUrl() is always true.
Loading history...
453
            $event['url'] = $this->getUrl();
454
        }
455
456
        if (null !== $this->getBackgroundColor()) {
0 ignored issues
show
introduced by
The condition null !== $this->getBackgroundColor() is always true.
Loading history...
457
            $event['backgroundColor'] = $this->getBackgroundColor();
458
        }
459
460
        if (null !== $this->getTextColor()) {
0 ignored issues
show
introduced by
The condition null !== $this->getTextColor() is always true.
Loading history...
461
            $event['textColor'] = $this->getTextColor();
462
        }
463
464
        if (null !== $this->getClassName()) {
0 ignored issues
show
introduced by
The condition null !== $this->getClassName() is always true.
Loading history...
465
            $event['className'] = $this->getClassName();
466
        }
467
468
        if (null !== $this->getEndDate()) {
469
            $event['end'] = $this->getEndDate()->format('Y-m-d\\TH:i:sP');
470
        }
471
472
        if (null !== $this->getRendering()) {
0 ignored issues
show
introduced by
The condition null !== $this->getRendering() is always true.
Loading history...
473
            $event['rendering'] = $this->getRendering();
474
        }
475
476
        if (null !== $this->getConstraint()) {
477
            $event['constraint'] = $this->getConstraint();
478
        }
479
480
        if (null !== $this->getSource()) {
0 ignored issues
show
introduced by
The condition null !== $this->getSource() is always true.
Loading history...
481
            $event['source'] = $this->getSource();
482
        }
483
484
        if (null !== $this->getColor()) {
0 ignored issues
show
introduced by
The condition null !== $this->getColor() is always true.
Loading history...
485
            $event['color'] = $this->getColor();
486
        }
487
488
        foreach ($this->getCustomFields() as $field => $value) {
489
            $event[$field] = $value;
490
        }
491
492
        return $event;
493
    }
494
}
495