EventCreated   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 7
dl 0
loc 139
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 20 1
A getMainLanguage() 0 4 1
A getTitle() 0 4 1
A getEventType() 0 4 1
A getTheme() 0 4 1
A getCalendar() 0 4 1
A getLocation() 0 4 1
A getPublicationDate() 0 4 1
A serialize() 0 20 3
A deserialize() 0 24 3
1
<?php
2
3
namespace CultuurNet\UDB3\Event\Events;
4
5
use CultuurNet\UDB3\Calendar;
6
use CultuurNet\UDB3\Event\EventEvent;
7
use CultuurNet\UDB3\Event\EventType;
8
use CultuurNet\UDB3\Language;
9
use CultuurNet\UDB3\Event\ValueObjects\LocationId;
10
use CultuurNet\UDB3\Theme;
11
use CultuurNet\UDB3\Title;
12
use DateTimeImmutable;
13
14
final class EventCreated extends EventEvent
15
{
16
    /**
17
     * @var Language
18
     */
19
    private $mainLanguage;
20
21
    /**
22
     * @var Title
23
     */
24
    private $title;
25
26
    /**
27
     * @var EventType
28
     */
29
    private $eventType;
30
31
    /**
32
     * @var Theme|null
33
     */
34
    private $theme;
35
36
    /**
37
     * @var LocationId
38
     */
39
    private $location;
40
41
    /**
42
     * @var Calendar
43
     */
44
    private $calendar;
45
46
    /**
47
     * @var DateTimeImmutable|null
48
     */
49
    private $publicationDate;
50
51
    public function __construct(
52
        string $eventId,
53
        Language $mainLanguage,
54
        Title $title,
55
        EventType $eventType,
56
        LocationId $location,
57
        Calendar $calendar,
58
        ?Theme $theme = null,
59
        ?DateTimeImmutable $publicationDate = null
60
    ) {
61
        parent::__construct($eventId);
62
63
        $this->mainLanguage = $mainLanguage;
64
        $this->title = $title;
65
        $this->eventType = $eventType;
66
        $this->location = $location;
67
        $this->calendar = $calendar;
68
        $this->theme = $theme;
69
        $this->publicationDate = $publicationDate;
70
    }
71
72
    public function getMainLanguage(): Language
73
    {
74
        return $this->mainLanguage;
75
    }
76
77
    public function getTitle(): Title
78
    {
79
        return $this->title;
80
    }
81
82
    public function getEventType(): EventType
83
    {
84
        return $this->eventType;
85
    }
86
87
    public function getTheme(): ?Theme
88
    {
89
        return $this->theme;
90
    }
91
92
    public function getCalendar(): Calendar
93
    {
94
        return $this->calendar;
95
    }
96
97
    public function getLocation(): LocationId
98
    {
99
        return $this->location;
100
    }
101
102
    public function getPublicationDate(): ?DateTimeImmutable
103
    {
104
        return $this->publicationDate;
105
    }
106
107
    public function serialize(): array
108
    {
109
        $theme = null;
110
        if ($this->getTheme() !== null) {
111
            $theme = $this->getTheme()->serialize();
112
        }
113
        $publicationDate = null;
114
        if (!is_null($this->getPublicationDate())) {
115
            $publicationDate = $this->getPublicationDate()->format(\DateTime::ATOM);
116
        }
117
        return parent::serialize() + array(
118
            'main_language' => $this->mainLanguage->getCode(),
119
            'title' => (string)$this->getTitle(),
120
            'event_type' => $this->getEventType()->serialize(),
121
            'theme' => $theme,
122
            'location' => $this->getLocation()->toNative(),
123
            'calendar' => $this->getCalendar()->serialize(),
124
            'publication_date' => $publicationDate,
125
        );
126
    }
127
128
    public static function deserialize(array $data): EventCreated
129
    {
130
        $theme = null;
131
        if (!empty($data['theme'])) {
132
            $theme = Theme::deserialize($data['theme']);
133
        }
134
        $publicationDate = null;
135
        if (!empty($data['publication_date'])) {
136
            $publicationDate = DateTimeImmutable::createFromFormat(
137
                \DateTime::ATOM,
138
                $data['publication_date']
139
            );
140
        }
141
        return new self(
142
            $data['event_id'],
143
            new Language($data['main_language']),
144
            new Title($data['title']),
145
            EventType::deserialize($data['event_type']),
146
            new LocationId($data['location']),
147
            Calendar::deserialize($data['calendar']),
148
            $theme,
149
            $publicationDate
150
        );
151
    }
152
}
153