Passed
Pull Request — master (#14)
by Theo
03:38
created

CalendarEvent::getTimezone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
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
    /**
39
     * @var string|null
40
     */
41
    private $timezone;
42
43 4
    public function __construct(
44
        DateTimeInterface $start,
45
        DateTimeInterface $end,
46
        array $filters,
47
        ?string $timezone = null
48
    ) {
49 4
        $this->start = $start;
50 4
        $this->end = $end;
51 4
        $this->filters = $filters;
52 4
        $this->timezone = $timezone;
53 4
    }
54
55 1
    public function getStart(): DateTimeInterface
56
    {
57 1
        return $this->start;
58
    }
59
60 1
    public function getEnd(): DateTimeInterface
61
    {
62 1
        return $this->end;
63
    }
64
65 1
    public function getFilters(): array
66
    {
67 1
        return $this->filters;
68
    }
69
70 1
    public function addEvent(Event $event): self
71
    {
72 1
        if (!\in_array($event, $this->events, true)) {
73 1
            $this->events[] = $event;
74
        }
75
76 1
        return $this;
77
    }
78
79
    /**
80
     * @return Event[]
81
     */
82 1
    public function getEvents(): array
83
    {
84 1
        return $this->events;
85
    }
86
87
    public function getTimezone(): ?string
88
    {
89
        return $this->timezone;
90
    }
91
}
92