Completed
Push — master ( dc82d8...d048aa )
by Kristof
14:05
created

Place   C

Complexity

Total Complexity 21

Size/Duplication

Total Lines 261
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 19

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 21
lcom 1
cbo 19
dl 0
loc 261
c 6
b 0
f 0
rs 6.875

21 Methods

Rating   Name   Duplication   Size   Complexity  
A getAggregateRootId() 0 4 1
A createPlace() 0 7 1
A applyPlaceCreated() 0 4 1
A updateDescription() 0 4 1
A updateTypicalAgeRange() 0 4 1
A deleteTypicalAgeRange() 0 4 1
A updateOrganizer() 0 4 1
A deleteOrganizer() 0 4 1
A updateContactPoint() 0 4 1
A updateBookingInfo() 0 4 1
A updateFacilities() 0 4 1
A addImage() 0 4 1
A updateImage() 0 9 1
A deleteImage() 0 4 1
A updateMajorInfo() 0 4 1
A deletePlace() 0 4 1
A importFromUDB2Actor() 0 16 1
A importFromUDB2Event() 0 16 1
A applyPlaceImportedFromUDB2() 0 5 1
A applyPlaceImportedFromUDB2Event() 0 5 1
A updateWithCdbXml() 0 10 1
1
<?php
2
3
/**
4
 * @file
5
 * Contains \Cultuurnet\UDB3\Place\Place.
6
 */
7
8
namespace CultuurNet\UDB3\Place;
9
10
use Broadway\EventSourcing\EventSourcedAggregateRoot;
11
use CultuurNet\UDB3\Address;
12
use CultuurNet\UDB3\BookingInfo;
13
use CultuurNet\UDB3\CalendarInterface;
14
use CultuurNet\UDB3\Cdb\UpdateableWithCdbXmlInterface;
15
use CultuurNet\UDB3\ContactPoint;
16
use CultuurNet\UDB3\Event\EventType;
17
use CultuurNet\UDB3\Media\Image;
18
use CultuurNet\UDB3\Media\MediaObject;
19
use CultuurNet\UDB3\Place\Commands\UpdateImage;
20
use CultuurNet\UDB3\Place\Events\BookingInfoUpdated;
21
use CultuurNet\UDB3\Place\Events\ContactPointUpdated;
22
use CultuurNet\UDB3\Place\Events\DescriptionUpdated;
23
use CultuurNet\UDB3\Place\Events\FacilitiesUpdated;
24
use CultuurNet\UDB3\Place\Events\ImageAdded;
25
use CultuurNet\UDB3\Place\Events\ImageDeleted;
26
use CultuurNet\UDB3\Place\Events\ImageUpdated;
27
use CultuurNet\UDB3\Place\Events\MajorInfoUpdated;
28
use CultuurNet\UDB3\Place\Events\OrganizerDeleted;
29
use CultuurNet\UDB3\Place\Events\OrganizerUpdated;
30
use CultuurNet\UDB3\Place\Events\PlaceCreated;
31
use CultuurNet\UDB3\Place\Events\PlaceDeleted;
32
use CultuurNet\UDB3\Place\Events\PlaceImportedFromUDB2;
33
use CultuurNet\UDB3\Place\Events\PlaceImportedFromUDB2Event;
34
use CultuurNet\UDB3\Place\Events\PlaceUpdatedFromUDB2;
35
use CultuurNet\UDB3\Place\Events\TypicalAgeRangeDeleted;
36
use CultuurNet\UDB3\Place\Events\TypicalAgeRangeUpdated;
37
use CultuurNet\UDB3\Theme;
38
use CultuurNet\UDB3\Title;
39
use Symfony\Component\EventDispatcher\Event;
40
use ValueObjects\String\String;
41
42
class Place extends EventSourcedAggregateRoot implements UpdateableWithCdbXmlInterface
43
{
44
    /**
45
     * The actor id.
46
     *
47
     * @var string
48
     */
49
    protected $actorId;
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function getAggregateRootId()
55
    {
56
        return $this->actorId;
57
    }
58
59
    /**
60
     * Factory method to create a new Place.
61
     *
62
     * @todo Refactor this method so it can be called create. Currently the
63
     * normal behavior for create is taken by the legacy udb2 logic.
64
     * The PlaceImportedFromUDB2 could be a superclass of Place.
65
     *
66
     * @param String $id
67
     * @param Title $title
68
     * @param EventType $eventType
69
     * @param Address $address
70
     * @param CalendarInterface $calendar
71
     * @param Theme/null $theme
0 ignored issues
show
Documentation introduced by
The doc-type Theme/null could not be parsed: Unknown type name "Theme/null" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
72
     *
73
     * @return Event
74
     */
75
    public static function createPlace($id, Title $title, EventType $eventType, Address $address, CalendarInterface $calendar, Theme $theme = null)
76
    {
77
        $place = new self();
78
        $place->apply(new PlaceCreated($id, $title, $eventType, $address, $calendar, $theme));
79
80
        return $place;
81
    }
82
83
    /**
84
     * Apply the place created event.
85
     * @param PlaceCreate $placeCreated
86
     */
87
    protected function applyPlaceCreated(PlaceCreated $placeCreated)
88
    {
89
        $this->actorId = $placeCreated->getPlaceId();
90
    }
91
92
    /**
93
     * @param string $description
94
     */
95
    public function updateDescription($description)
96
    {
97
        $this->apply(new DescriptionUpdated($this->actorId, $description));
98
    }
99
100
    /**
101
     * @param string $typicalAgeRange
102
     */
103
    public function updateTypicalAgeRange($typicalAgeRange)
104
    {
105
        $this->apply(new TypicalAgeRangeUpdated($this->actorId, $typicalAgeRange));
106
    }
107
108
    public function deleteTypicalAgeRange()
109
    {
110
        $this->apply(new TypicalAgeRangeDeleted($this->actorId));
111
    }
112
113
    /**
114
     * Handle an update command to update organizer.
115
     */
116
    public function updateOrganizer($organizerId)
117
    {
118
        $this->apply(new OrganizerUpdated($this->actorId, $organizerId));
119
    }
120
121
    /**
122
     * Delete the given organizer.
123
     *
124
     * @param string $organizerId
125
     */
126
    public function deleteOrganizer($organizerId)
127
    {
128
        $this->apply(new OrganizerDeleted($this->actorId, $organizerId));
129
    }
130
131
    /**
132
     * Updated the contact point.
133
     *
134
     * @param ContactPoint $contactPoint
135
     */
136
    public function updateContactPoint(ContactPoint $contactPoint)
137
    {
138
        $this->apply(new ContactPointUpdated($this->actorId, $contactPoint));
139
    }
140
141
    /**
142
     * Updated the booking info.
143
     *
144
     * @param BookingInfo $bookingInfo
145
     */
146
    public function updateBookingInfo(BookingInfo $bookingInfo)
147
    {
148
        $this->apply(new BookingInfoUpdated($this->actorId, $bookingInfo));
149
    }
150
151
    /**
152
     * Update the facilities.
153
     *
154
     * @param array $facilities
155
     */
156
    public function updateFacilities(array $facilities)
157
    {
158
        $this->apply(new FacilitiesUpdated($this->actorId, $facilities));
159
    }
160
161
    /**
162
     * Add a new image.
163
     *
164
     * @param Image $image
165
     */
166
    public function addImage(Image $image)
167
    {
168
        $this->apply(new ImageAdded($this->actorId, $image));
169
    }
170
171
    /**
172
     * @param UpdateImage $updateImageCommand
173
     */
174
    public function updateImage(UpdateImage $updateImageCommand)
175
    {
176
        $this->apply(new ImageUpdated(
177
            $updateImageCommand->getItemId(),
178
            $updateImageCommand->getMediaObjectId(),
179
            $updateImageCommand->getDescription(),
180
            $updateImageCommand->getCopyrightHolder()
181
        ));
182
    }
183
184
    /**
185
     * Delet an image.
186
     *
187
     * @param int $indexToDelete
188
     * @param mixed int|string $internalId
189
     */
190
    public function deleteImage($indexToDelete, $internalId)
191
    {
192
        $this->apply(new ImageDeleted($this->actorId, $indexToDelete, $internalId));
193
    }
194
195
    /**
196
     * Update the major info.
197
     *
198
     * @param Title $title
199
     * @param EventType $eventType
200
     * @param Address $address
201
     * @param CalendarInterface $calendar
202
     * @param type $theme
203
     */
204
    public function updateMajorInfo(Title $title, EventType $eventType, Address $address, CalendarInterface $calendar, $theme = null)
205
    {
206
        $this->apply(new MajorInfoUpdated($this->actorId, $title, $eventType, $address, $calendar, $theme));
207
    }
208
209
    /**
210
     * Delete this item.
211
     */
212
    public function deletePlace()
213
    {
214
        $this->apply(new PlaceDeleted($this->actorId));
215
    }
216
217
    /**
218
     * Import from UDB2.
219
     *
220
     * @param string $actorId
221
     *   The actor id.
222
     * @param string $cdbXml
223
     *   The cdb xml.
224
     * @param string $cdbXmlNamespaceUri
225
     *   The cdb xml namespace uri.
226
     *
227
     * @return Actor
228
     *   The actor.
229
     */
230
    public static function importFromUDB2Actor(
231
        $actorId,
232
        $cdbXml,
233
        $cdbXmlNamespaceUri
234
    ) {
235
        $place = new static();
236
        $place->apply(
237
            new PlaceImportedFromUDB2(
238
                $actorId,
239
                $cdbXml,
240
                $cdbXmlNamespaceUri
241
            )
242
        );
243
244
        return $place;
245
    }
246
247
    /**
248
     * Import from UDB2.
249
     *
250
     * @param string $placeId
251
     *   The actor id.
252
     * @param string $cdbXml
253
     *   The cdb xml.
254
     * @param string $cdbXmlNamespaceUri
255
     *   The cdb xml namespace uri.
256
     *
257
     * @return Actor
258
     *   The actor.
259
     */
260
    public static function importFromUDB2Event(
261
        $placeId,
262
        $cdbXml,
263
        $cdbXmlNamespaceUri
264
    ) {
265
        $place = new static();
266
        $place->apply(
267
            new PlaceImportedFromUDB2Event(
268
                $placeId,
269
                $cdbXml,
270
                $cdbXmlNamespaceUri
271
            )
272
        );
273
274
        return $place;
275
    }
276
277
    public function applyPlaceImportedFromUDB2(
278
        PlaceImportedFromUDB2 $placeImported
279
    ) {
280
        $this->actorId = $placeImported->getActorId();
281
    }
282
283
    public function applyPlaceImportedFromUDB2Event(
284
        PlaceImportedFromUDB2Event $placeImported
285
    ) {
286
        $this->actorId = $placeImported->getActorId();
287
    }
288
289
    /**
290
     * @inheritdoc
291
     */
292
    public function updateWithCdbXml($cdbXml, $cdbXmlNamespaceUri)
293
    {
294
        $this->apply(
295
            new PlaceUpdatedFromUDB2(
296
                $this->actorId,
297
                $cdbXml,
298
                $cdbXmlNamespaceUri
299
            )
300
        );
301
    }
302
}
303