CalendarEvent::getEnd()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CalendarBundle\Event;
6
7
use CalendarBundle\Entity\Event;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, CalendarBundle\Event\Event. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
8
use CalendarBundle\Event\Event as BaseEvent;
9
use DateTimeInterface;
10
11
/**
12
 * This event is triggered before the serialization of the events.
13
 *
14
 * This event allows you to fill the calendar with your data.
15
 */
16
class CalendarEvent extends BaseEvent
17
{
18
    /**
19
     * @var DateTimeInterface
20
     */
21
    protected $start;
22
23
    /**
24
     * @var DateTimeInterface
25
     */
26
    protected $end;
27
28
    /**
29
     * @var array
30
     */
31
    protected $filters;
32
33
    /**
34
     * @var Event[]
35
     */
36
    protected $events = [];
37
38 4
    public function __construct(
39
        DateTimeInterface $start,
40
        DateTimeInterface $end,
41
        array $filters
42
    ) {
43 4
        $this->start = $start;
44 4
        $this->end = $end;
45 4
        $this->filters = $filters;
46 4
    }
47
48 1
    public function getStart(): DateTimeInterface
49
    {
50 1
        return $this->start;
51
    }
52
53 1
    public function getEnd(): DateTimeInterface
54
    {
55 1
        return $this->end;
56
    }
57
58 1
    public function getFilters(): array
59
    {
60 1
        return $this->filters;
61
    }
62
63 1
    public function addEvent(Event $event): self
64
    {
65 1
        if (!\in_array($event, $this->events, true)) {
66 1
            $this->events[] = $event;
67
        }
68
69 1
        return $this;
70
    }
71
72
    /**
73
     * @return Event[]
74
     */
75 1
    public function getEvents(): array
76
    {
77 1
        return $this->events;
78
    }
79
}
80