Completed
Pull Request — master (#314)
by
unknown
04:48
created

Offer   F

Complexity

Total Complexity 78

Size/Duplication

Total Lines 703
Duplicated Lines 3.41 %

Coupling/Cohesion

Components 1
Dependencies 21

Importance

Changes 0
Metric Value
wmc 78
lcom 1
cbo 21
dl 24
loc 703
rs 1.526
c 0
b 0
f 0

72 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A getMainImageId() 0 5 2
A addLabel() 0 8 2
A removeLabel() 0 8 2
A translateTitle() 0 6 1
A updateDescription() 0 12 3
A updateTypicalAgeRange() 0 6 1
A deleteTypicalAgeRange() 0 6 1
A updateOrganizer() 0 8 2
A deleteOrganizer() 0 8 2
A updateContactPoint() 0 6 1
A updateBookingInfo() 0 6 1
A updatePriceInfo() 0 8 3
A applyPriceInfoUpdated() 0 4 1
A applyLabelAdded() 0 4 1
A applyLabelRemoved() 0 4 1
A applyDescriptionUpdated() 0 5 1
A applyDescriptionTranslated() 0 5 1
A addImage() 0 8 2
A updateImage() 0 6 1
A removeImage() 0 8 2
A selectMainImage() 0 14 4
A delete() 0 6 1
A importWorkflowStatus() 0 9 2
A publish() 0 6 2
A guardPublish() 12 12 3
A approve() 0 4 2
A guardApprove() 12 12 3
A reject() 0 4 2
A flagAsDuplicate() 0 5 2
A flagAsInappropriate() 0 5 2
B guardRejection() 0 16 5
A isDescriptionChanged() 0 7 2
A importImagesFromUDB2() 0 4 1
A updateImagesFromUDB2() 0 4 1
A applyPublished() 0 4 1
A applyApproved() 0 4 1
A applyRejected() 0 5 1
A applyFlaggedAsDuplicate() 0 5 1
A applyFlaggedAsInappropriate() 0 5 1
A applyImageAdded() 0 4 1
A applyImageRemoved() 0 4 1
A applyMainImageSelected() 0 4 1
A applyOrganizerUpdated() 0 4 1
A applyOrganizerDeleted() 0 4 1
A applyImagesImportedFromUDB2() 0 4 1
A applyImagesUpdatedFromUDB2() 0 4 1
A applyUdb2ImagesEvent() 0 16 2
createLabelAddedEvent() 0 1 ?
createLabelRemovedEvent() 0 1 ?
createTitleTranslatedEvent() 0 1 ?
createDescriptionTranslatedEvent() 0 1 ?
createImageAddedEvent() 0 1 ?
createImageRemovedEvent() 0 1 ?
createImageUpdatedEvent() 0 3 ?
createMainImageSelectedEvent() 0 1 ?
createOfferDeletedEvent() 0 1 ?
createDescriptionUpdatedEvent() 0 1 ?
createTypicalAgeRangeUpdatedEvent() 0 1 ?
createTypicalAgeRangeDeletedEvent() 0 1 ?
createOrganizerUpdatedEvent() 0 1 ?
createOrganizerDeletedEvent() 0 1 ?
createContactPointUpdatedEvent() 0 1 ?
createBookingInfoUpdatedEvent() 0 1 ?
createPriceInfoUpdatedEvent() 0 1 ?
createPublishedEvent() 0 1 ?
createApprovedEvent() 0 1 ?
createRejectedEvent() 0 1 ?
createFlaggedAsDuplicate() 0 1 ?
createFlaggedAsInappropriate() 0 1 ?
createImagesImportedFromUDB2() 0 1 ?
createImagesUpdatedFromUDB2() 0 1 ?

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Offer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Offer, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace CultuurNet\UDB3\Offer;
4
5
use Broadway\EventSourcing\EventSourcedAggregateRoot;
6
use CultureFeed_Cdb_Item_Base;
7
use CultuurNet\UDB3\BookingInfo;
8
use CultuurNet\UDB3\ContactPoint;
9
use CultuurNet\UDB3\Description;
10
use CultuurNet\UDB3\Label;
11
use CultuurNet\UDB3\LabelAwareAggregateRoot;
12
use CultuurNet\UDB3\LabelCollection;
13
use CultuurNet\UDB3\Media\Image;
14
use CultuurNet\UDB3\Media\ImageCollection;
15
use CultuurNet\UDB3\Offer\Commands\Image\AbstractUpdateImage;
16
use CultuurNet\UDB3\Language;
17
use CultuurNet\UDB3\Offer\Events\AbstractBookingInfoUpdated;
18
use CultuurNet\UDB3\Offer\Events\AbstractContactPointUpdated;
19
use CultuurNet\UDB3\Offer\Events\AbstractDescriptionTranslated;
20
use CultuurNet\UDB3\Offer\Events\AbstractDescriptionUpdated;
21
use CultuurNet\UDB3\Offer\Events\AbstractLabelAdded;
22
use CultuurNet\UDB3\Offer\Events\AbstractLabelRemoved;
23
use CultuurNet\UDB3\Offer\Events\AbstractOfferDeleted;
24
use CultuurNet\UDB3\Offer\Events\AbstractOrganizerDeleted;
25
use CultuurNet\UDB3\Offer\Events\AbstractOrganizerUpdated;
26
use CultuurNet\UDB3\Offer\Events\AbstractPriceInfoUpdated;
27
use CultuurNet\UDB3\Offer\Events\AbstractTypicalAgeRangeDeleted;
28
use CultuurNet\UDB3\Offer\Events\AbstractTypicalAgeRangeUpdated;
29
use CultuurNet\UDB3\Offer\Events\Image\AbstractImageAdded;
30
use CultuurNet\UDB3\Offer\Events\Image\AbstractImageRemoved;
31
use CultuurNet\UDB3\Offer\Events\Image\AbstractImagesEvent;
32
use CultuurNet\UDB3\Offer\Events\Image\AbstractImagesImportedFromUDB2;
33
use CultuurNet\UDB3\Offer\Events\Image\AbstractImagesUpdatedFromUDB2;
34
use CultuurNet\UDB3\Offer\Events\Image\AbstractImageUpdated;
35
use CultuurNet\UDB3\Offer\Events\Image\AbstractMainImageSelected;
36
use CultuurNet\UDB3\Offer\Events\AbstractTitleTranslated;
37
use CultuurNet\UDB3\Offer\Events\Moderation\AbstractApproved;
38
use CultuurNet\UDB3\Offer\Events\Moderation\AbstractFlaggedAsDuplicate;
39
use CultuurNet\UDB3\Offer\Events\Moderation\AbstractFlaggedAsInappropriate;
40
use CultuurNet\UDB3\Offer\Events\Moderation\AbstractPublished;
41
use CultuurNet\UDB3\Offer\Events\Moderation\AbstractRejected;
42
use CultuurNet\UDB3\PriceInfo\PriceInfo;
43
use Exception;
44
use ValueObjects\Identity\UUID;
45
use ValueObjects\StringLiteral\StringLiteral;
46
47
abstract class Offer extends EventSourcedAggregateRoot implements LabelAwareAggregateRoot
48
{
49
    const DUPLICATE_REASON = 'duplicate';
50
    const INAPPROPRIATE_REASON = 'inappropriate';
51
52
    /**
53
     * @var LabelCollection
54
     */
55
    protected $labels;
56
57
    /**
58
     * @var ImageCollection
59
     */
60
    protected $images;
61
62
    /**
63
     * @var string
64
     *
65
     * Organizer ids can come from UDB2 which does not strictly use UUIDs.
66
     */
67
    protected $organizerId;
68
69
    /**
70
     * @var WorkflowStatus
71
     */
72
    protected $workflowStatus;
73
74
    /**
75
     * @var StringLiteral|null
76
     */
77
    protected $rejectedReason;
78
79
    /**
80
     * @var PriceInfo
81
     */
82
    protected $priceInfo;
83
84
    /**
85
     * @var Description[]
86
     */
87
    protected $descriptions;
88
89
    /**
90
     * @var Language
91
     */
92
    protected $mainLanguage;
93
94
    /**
95
     * Offer constructor.
96
     */
97
    public function __construct()
98
    {
99
        // For now the main language is hard coded on nl.
100
        // In the future it should be set on create.
101
        $this->mainLanguage = new Language('nl');
102
103
        $this->descriptions = [];
104
        $this->labels = new LabelCollection();
105
        $this->images = new ImageCollection();
106
    }
107
108
    /**
109
     * Get the id of the main image if one is selected for this offer.
110
     *
111
     * @return UUID|null
112
     */
113
    protected function getMainImageId()
114
    {
115
        $mainImage = $this->images->getMain();
116
        return isset($mainImage) ? $mainImage->getMediaObjectId() : null;
117
    }
118
119
    /**
120
     * @inheritdoc
121
     */
122
    public function addLabel(Label $label)
123
    {
124
        if (!$this->labels->contains($label)) {
125
            $this->apply(
126
                $this->createLabelAddedEvent($label)
127
            );
128
        }
129
    }
130
131
    /**
132
     * @inheritdoc
133
     */
134
    public function removeLabel(Label $label)
135
    {
136
        if ($this->labels->contains($label)) {
137
            $this->apply(
138
                $this->createLabelRemovedEvent($label)
139
            );
140
        }
141
    }
142
143
    /**
144
     * @param Language $language
145
     * @param StringLiteral $title
146
     */
147
    public function translateTitle(Language $language, StringLiteral $title)
148
    {
149
        $this->apply(
150
            $this->createTitleTranslatedEvent($language, $title)
151
        );
152
    }
153
154
    /**
155
     * @param Description $description
156
     * @param Language $language
157
     */
158
    public function updateDescription(Description $description, Language $language)
159
    {
160
        if ($this->isDescriptionChanged($description, $language)) {
161
            if ($language->getCode() !== $this->mainLanguage->getCode()) {
162
                $event = $this->createDescriptionTranslatedEvent($language, $description);
163
            } else {
164
                $event = $this->createDescriptionUpdatedEvent((string) $description);
165
            }
166
167
            $this->apply($event);
168
        }
169
    }
170
171
    /**
172
     * @param string $typicalAgeRange
173
     */
174
    public function updateTypicalAgeRange($typicalAgeRange)
175
    {
176
        $this->apply(
177
            $this->createTypicalAgeRangeUpdatedEvent($typicalAgeRange)
178
        );
179
    }
180
181
    public function deleteTypicalAgeRange()
182
    {
183
        $this->apply(
184
            $this->createTypicalAgeRangeDeletedEvent()
185
        );
186
    }
187
188
    /**
189
     * @param string $organizerId
190
     */
191
    public function updateOrganizer($organizerId)
192
    {
193
        if ($this->organizerId !== $organizerId) {
194
            $this->apply(
195
                $this->createOrganizerUpdatedEvent($organizerId)
196
            );
197
        }
198
    }
199
200
    /**
201
     * Delete the given organizer.
202
     *
203
     * @param string $organizerId
204
     */
205
    public function deleteOrganizer($organizerId)
206
    {
207
        if ($this->organizerId === $organizerId) {
208
            $this->apply(
209
                $this->createOrganizerDeletedEvent($organizerId)
210
            );
211
        }
212
    }
213
214
    /**
215
     * Updated the contact info.
216
     * @param ContactPoint $contactPoint
217
     */
218
    public function updateContactPoint(ContactPoint $contactPoint)
219
    {
220
        $this->apply(
221
            $this->createContactPointUpdatedEvent($contactPoint)
222
        );
223
    }
224
225
    /**
226
     * Updated the booking info.
227
     *
228
     * @param BookingInfo $bookingInfo
229
     */
230
    public function updateBookingInfo(BookingInfo $bookingInfo)
231
    {
232
        $this->apply(
233
            $this->createBookingInfoUpdatedEvent($bookingInfo)
234
        );
235
    }
236
237
    /**
238
     * @param PriceInfo $priceInfo
239
     */
240
    public function updatePriceInfo(PriceInfo $priceInfo)
241
    {
242
        if (is_null($this->priceInfo) || $priceInfo->serialize() !== $this->priceInfo->serialize()) {
243
            $this->apply(
244
                $this->createPriceInfoUpdatedEvent($priceInfo)
245
            );
246
        }
247
    }
248
249
    /**
250
     * @param AbstractPriceInfoUpdated $priceInfoUpdated
251
     */
252
    protected function applyPriceInfoUpdated(AbstractPriceInfoUpdated $priceInfoUpdated)
253
    {
254
        $this->priceInfo = $priceInfoUpdated->getPriceInfo();
255
    }
256
257
    /**
258
     * @param AbstractLabelAdded $labelAdded
259
     */
260
    protected function applyLabelAdded(AbstractLabelAdded $labelAdded)
261
    {
262
        $this->labels = $this->labels->with($labelAdded->getLabel());
263
    }
264
265
    /**
266
     * @param AbstractLabelRemoved $labelRemoved
267
     */
268
    protected function applyLabelRemoved(AbstractLabelRemoved $labelRemoved)
269
    {
270
        $this->labels = $this->labels->without($labelRemoved->getLabel());
271
    }
272
273
    protected function applyDescriptionUpdated(AbstractDescriptionUpdated $descriptionUpdated)
274
    {
275
        $mainLanguageCode = $this->mainLanguage->getCode();
276
        $this->descriptions[$mainLanguageCode] = new Description($descriptionUpdated->getDescription());
277
    }
278
279
    protected function applyDescriptionTranslated(AbstractDescriptionTranslated $descriptionTranslated)
280
    {
281
        $languageCode = $descriptionTranslated->getLanguage()->getCode();
282
        $this->descriptions[$languageCode] = $descriptionTranslated->getDescription();
283
    }
284
285
    /**
286
     * Add a new image.
287
     *
288
     * @param Image $image
289
     */
290
    public function addImage(Image $image)
291
    {
292
        if (!$this->images->contains($image)) {
293
            $this->apply(
294
                $this->createImageAddedEvent($image)
295
            );
296
        }
297
    }
298
299
    /**
300
     * @param AbstractUpdateImage $updateImageCommand
301
     */
302
    public function updateImage(AbstractUpdateImage $updateImageCommand)
303
    {
304
        $this->apply(
305
            $this->createImageUpdatedEvent($updateImageCommand)
306
        );
307
    }
308
309
    /**
310
     * Remove an image.
311
     *
312
     * @param Image $image
313
     */
314
    public function removeImage(Image $image)
315
    {
316
        if ($this->images->contains($image)) {
317
            $this->apply(
318
                $this->createImageRemovedEvent($image)
319
            );
320
        }
321
    }
322
323
    /**
324
     * Make an existing image of the item the main image.
325
     *
326
     * @param Image $image
327
     */
328
    public function selectMainImage(Image $image)
329
    {
330
        if (!$this->images->contains($image)) {
331
            throw new \InvalidArgumentException('You can not select a random image to be main, it has to be added to the item.');
332
        }
333
334
        $oldMainImage = $this->images->getMain();
335
336
        if (!isset($oldMainImage) || $oldMainImage->getMediaObjectId() !== $image->getMediaObjectId()) {
337
            $this->apply(
338
                $this->createMainImageSelectedEvent($image)
339
            );
340
        }
341
    }
342
343
    /**
344
     * Delete the offer.
345
     */
346
    public function delete()
347
    {
348
        $this->apply(
349
            $this->createOfferDeletedEvent()
350
        );
351
    }
352
353
    /**
354
     * @param CultureFeed_Cdb_Item_Base $cdbItem
355
     */
356
    protected function importWorkflowStatus(CultureFeed_Cdb_Item_Base $cdbItem)
357
    {
358
        try {
359
            $workflowStatus = WorkflowStatus::fromNative($cdbItem->getWfStatus());
360
        } catch (\InvalidArgumentException $exception) {
361
            $workflowStatus = WorkflowStatus::READY_FOR_VALIDATION();
362
        }
363
        $this->workflowStatus = $workflowStatus;
364
    }
365
366
    /**
367
     * Publish the offer when it has workflowstatus draft.
368
     * @param \DateTimeInterface $publicationDate
369
     */
370
    public function publish(\DateTimeInterface $publicationDate)
371
    {
372
        $this->guardPublish() ?: $this->apply(
373
            $this->createPublishedEvent($publicationDate)
374
        );
375
    }
376
377
    /**
378
     * @return bool
379
     * @throws Exception
380
     */
381 View Code Duplication
    private function guardPublish()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
382
    {
383
        if ($this->workflowStatus === WorkflowStatus::READY_FOR_VALIDATION()) {
384
            return true; // nothing left to do if the offer has already been published
385
        }
386
387
        if ($this->workflowStatus !== WorkflowStatus::DRAFT()) {
388
            throw new Exception('You can not publish an offer that is not draft');
389
        }
390
391
        return false;
392
    }
393
394
    /**
395
     * Approve the offer when it's waiting for validation.
396
     */
397
    public function approve()
398
    {
399
        $this->guardApprove() ?: $this->apply($this->createApprovedEvent());
400
    }
401
402
    /**
403
     * @return bool
404
     * @throws Exception
405
     */
406 View Code Duplication
    private function guardApprove()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
407
    {
408
        if ($this->workflowStatus === WorkflowStatus::APPROVED()) {
409
            return true; // nothing left to do if the offer has already been approved
410
        }
411
412
        if ($this->workflowStatus !== WorkflowStatus::READY_FOR_VALIDATION()) {
413
            throw new Exception('You can not approve an offer that is not ready for validation');
414
        }
415
416
        return false;
417
    }
418
419
    /**
420
     * Reject an offer that is waiting for validation with a given reason.
421
     * @param StringLiteral $reason
422
     */
423
    public function reject(StringLiteral $reason)
424
    {
425
        $this->guardRejection($reason) ?: $this->apply($this->createRejectedEvent($reason));
426
    }
427
428
    public function flagAsDuplicate()
429
    {
430
        $reason = new StringLiteral(self::DUPLICATE_REASON);
431
        $this->guardRejection($reason) ?: $this->apply($this->createFlaggedAsDuplicate());
432
    }
433
434
    public function flagAsInappropriate()
435
    {
436
        $reason = new StringLiteral(self::INAPPROPRIATE_REASON);
437
        $this->guardRejection($reason) ?: $this->apply($this->createFlaggedAsInappropriate());
438
    }
439
440
    /**
441
     * @param StringLiteral $reason
442
     * @return bool
443
     *  false when the offer can still be rejected, true when the offer is already rejected for the same reason
444
     * @throws Exception
445
     */
446
    private function guardRejection(StringLiteral $reason)
447
    {
448
        if ($this->workflowStatus === WorkflowStatus::REJECTED()) {
449
            if ($this->rejectedReason && $reason->sameValueAs($this->rejectedReason)) {
450
                return true; // nothing left to do if the offer has already been rejected for the same reason
451
            } else {
452
                throw new Exception('The offer has already been rejected for another reason: ' . $this->rejectedReason);
453
            }
454
        }
455
456
        if ($this->workflowStatus !== WorkflowStatus::READY_FOR_VALIDATION()) {
457
            throw new Exception('You can not reject an offer that is not ready for validation');
458
        }
459
460
        return false;
461
    }
462
463
    /**
464
     * @param Description $description
465
     * @param Language $language
466
     * @return bool
467
     */
468
    private function isDescriptionChanged(Description $description, Language $language)
469
    {
470
        $languageCode = $language->getCode();
471
472
        return !isset($this->descriptions[$languageCode]) ||
473
            !$description->sameValueAs($this->descriptions[$languageCode]);
474
    }
475
476
    /**
477
     * Overwrites or resets the main image and all media objects
478
     * by importing a new collection of images from UDB2.
479
     *
480
     * @param ImageCollection $images
481
     */
482
    public function importImagesFromUDB2(ImageCollection $images)
483
    {
484
        $this->apply($this->createImagesImportedFromUDB2($images));
485
    }
486
487
    /**
488
     * Overwrites or resets the main image and all media objects
489
     * by updating with a new collection of images from UDB2.
490
     *
491
     * @param ImageCollection $images
492
     */
493
    public function updateImagesFromUDB2(ImageCollection $images)
494
    {
495
        $this->apply($this->createImagesUpdatedFromUDB2($images));
496
    }
497
498
    /**
499
     * @param AbstractPublished $published
500
     */
501
    protected function applyPublished(AbstractPublished $published)
0 ignored issues
show
Unused Code introduced by
The parameter $published is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
502
    {
503
        $this->workflowStatus = WorkflowStatus::READY_FOR_VALIDATION();
504
    }
505
506
    /**
507
     * @param AbstractApproved $approved
508
     */
509
    protected function applyApproved(AbstractApproved $approved)
0 ignored issues
show
Unused Code introduced by
The parameter $approved is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
510
    {
511
        $this->workflowStatus = WorkflowStatus::APPROVED();
512
    }
513
514
    /**
515
     * @param AbstractRejected $rejected
516
     */
517
    protected function applyRejected(AbstractRejected $rejected)
518
    {
519
        $this->rejectedReason = $rejected->getReason();
520
        $this->workflowStatus = WorkflowStatus::REJECTED();
521
    }
522
523
    /**
524
     * @param AbstractFlaggedAsDuplicate $flaggedAsDuplicate
525
     */
526
    protected function applyFlaggedAsDuplicate(AbstractFlaggedAsDuplicate $flaggedAsDuplicate)
0 ignored issues
show
Unused Code introduced by
The parameter $flaggedAsDuplicate is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
527
    {
528
        $this->rejectedReason = new StringLiteral(self::DUPLICATE_REASON);
529
        $this->workflowStatus = WorkflowStatus::REJECTED();
530
    }
531
532
    /**
533
     * @param AbstractFlaggedAsInappropriate $flaggedAsInappropriate
534
     */
535
    protected function applyFlaggedAsInappropriate(AbstractFlaggedAsInappropriate $flaggedAsInappropriate)
0 ignored issues
show
Unused Code introduced by
The parameter $flaggedAsInappropriate is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
536
    {
537
        $this->rejectedReason = new StringLiteral(self::INAPPROPRIATE_REASON);
538
        $this->workflowStatus = WorkflowStatus::REJECTED();
539
    }
540
541
    protected function applyImageAdded(AbstractImageAdded $imageAdded)
542
    {
543
        $this->images = $this->images->with($imageAdded->getImage());
544
    }
545
546
    protected function applyImageRemoved(AbstractImageRemoved $imageRemoved)
547
    {
548
        $this->images = $this->images->without($imageRemoved->getImage());
549
    }
550
551
    protected function applyMainImageSelected(AbstractMainImageSelected $mainImageSelected)
552
    {
553
        $this->images = $this->images->withMain($mainImageSelected->getImage());
554
    }
555
556
    protected function applyOrganizerUpdated(AbstractOrganizerUpdated $organizerUpdated)
557
    {
558
        $this->organizerId = $organizerUpdated->getOrganizerId();
559
    }
560
561
    protected function applyOrganizerDeleted(AbstractOrganizerDeleted $organizerDeleted)
0 ignored issues
show
Unused Code introduced by
The parameter $organizerDeleted is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
562
    {
563
        $this->organizerId = null;
564
    }
565
566
    /**
567
     * @param AbstractImagesImportedFromUDB2 $imagesImportedFromUDB2
568
     */
569
    protected function applyImagesImportedFromUDB2(AbstractImagesImportedFromUDB2 $imagesImportedFromUDB2)
570
    {
571
        $this->applyUdb2ImagesEvent($imagesImportedFromUDB2);
572
    }
573
574
    /**
575
     * @param AbstractImagesUpdatedFromUDB2 $imagesUpdatedFromUDB2
576
     */
577
    protected function applyImagesUpdatedFromUDB2(AbstractImagesUpdatedFromUDB2 $imagesUpdatedFromUDB2)
578
    {
579
        $this->applyUdb2ImagesEvent($imagesUpdatedFromUDB2);
580
    }
581
582
    /**
583
     * This indirect apply method can be called internally to deal with images coming from UDB2.
584
     * Imports from UDB2 only contain the native Dutch content.
585
     * @see https://github.com/cultuurnet/udb3-udb2-bridge/blob/db0a7ab2444f55bb3faae3d59b82b39aaeba253b/test/Media/ImageCollectionFactoryTest.php#L79-L103
586
     * Because of this we have to make sure translated images are left in place.
587
     *
588
     * @param AbstractImagesEvent $imagesEvent
589
     */
590
    protected function applyUdb2ImagesEvent(AbstractImagesEvent $imagesEvent)
591
    {
592
        $newMainImage = $imagesEvent->getImages()->getMain();
593
        $dutchImagesList = $imagesEvent->getImages()->toArray();
594
        $translatedImagesList = array_filter(
595
            $this->images->toArray(),
596
            function (Image $image) {
597
                return $image->getLanguage()->getCode() !== 'nl';
598
            }
599
        );
600
601
        $imagesList = array_merge($dutchImagesList, $translatedImagesList);
602
        $images = ImageCollection::fromArray($imagesList);
603
604
        $this->images = isset($newMainImage) ? $images->withMain($newMainImage) : $images;
605
    }
606
607
    /**
608
     * @param Label $label
609
     * @return AbstractLabelAdded
610
     */
611
    abstract protected function createLabelAddedEvent(Label $label);
612
613
    /**
614
     * @param Label $label
615
     * @return AbstractLabelRemoved
616
     */
617
    abstract protected function createLabelRemovedEvent(Label $label);
618
619
    /**
620
     * @param Language $language
621
     * @param StringLiteral $title
622
     * @return AbstractTitleTranslated
623
     */
624
    abstract protected function createTitleTranslatedEvent(Language $language, StringLiteral $title);
625
626
    /**
627
     * @param Language $language
628
     * @param StringLiteral $description
629
     * @return AbstractDescriptionTranslated
630
     */
631
    abstract protected function createDescriptionTranslatedEvent(Language $language, StringLiteral $description);
632
633
    /**
634
     * @param Image $image
635
     * @return AbstractImageAdded
636
     */
637
    abstract protected function createImageAddedEvent(Image $image);
638
639
    /**
640
     * @param Image $image
641
     * @return AbstractImageRemoved
642
     */
643
    abstract protected function createImageRemovedEvent(Image $image);
644
645
    /**
646
     * @param AbstractUpdateImage $updateImageCommand
647
     * @return AbstractImageUpdated
648
     */
649
    abstract protected function createImageUpdatedEvent(
650
        AbstractUpdateImage $updateImageCommand
651
    );
652
653
    /**
654
     * @param Image $image
655
     * @return AbstractMainImageSelected
656
     */
657
    abstract protected function createMainImageSelectedEvent(Image $image);
658
659
    /**
660
     * @return AbstractOfferDeleted
661
     */
662
    abstract protected function createOfferDeletedEvent();
663
664
    /**
665
     * @param string $description
666
     * @return AbstractDescriptionUpdated
667
     */
668
    abstract protected function createDescriptionUpdatedEvent($description);
669
670
    /**
671
     * @param string $typicalAgeRange
672
     * @return AbstractTypicalAgeRangeUpdated
673
     */
674
    abstract protected function createTypicalAgeRangeUpdatedEvent($typicalAgeRange);
675
676
    /**
677
     * @return AbstractTypicalAgeRangeDeleted
678
     */
679
    abstract protected function createTypicalAgeRangeDeletedEvent();
680
681
    /**
682
     * @param string $organizerId
683
     * @return AbstractOrganizerUpdated
684
     */
685
    abstract protected function createOrganizerUpdatedEvent($organizerId);
686
687
    /**
688
     * @param string $organizerId
689
     * @return AbstractOrganizerDeleted
690
     */
691
    abstract protected function createOrganizerDeletedEvent($organizerId);
692
693
    /**
694
     * @param ContactPoint $contactPoint
695
     * @return AbstractContactPointUpdated
696
     */
697
    abstract protected function createContactPointUpdatedEvent(ContactPoint $contactPoint);
698
699
    /**
700
     * @param BookingInfo $bookingInfo
701
     * @return AbstractBookingInfoUpdated
702
     */
703
    abstract protected function createBookingInfoUpdatedEvent(BookingInfo $bookingInfo);
704
705
    /**
706
     * @param PriceInfo $priceInfo
707
     * @return AbstractPriceInfoUpdated
708
     */
709
    abstract protected function createPriceInfoUpdatedEvent(PriceInfo $priceInfo);
710
711
    /**
712
     * @param \DateTimeInterface $publicationDate
713
     * @return AbstractPublished
714
     */
715
    abstract protected function createPublishedEvent(\DateTimeInterface $publicationDate);
716
717
    /**
718
     * @return AbstractApproved
719
     */
720
    abstract protected function createApprovedEvent();
721
722
    /**
723
     * @param StringLiteral $reason
724
     * @return AbstractRejected
725
     */
726
    abstract protected function createRejectedEvent(StringLiteral $reason);
727
728
    /**
729
     * @return AbstractFlaggedAsDuplicate
730
     */
731
    abstract protected function createFlaggedAsDuplicate();
732
733
    /**
734
     * @return AbstractFlaggedAsInappropriate
735
     */
736
    abstract protected function createFlaggedAsInappropriate();
737
738
    /**
739
     * @param ImageCollection $images
740
     * @return AbstractImagesImportedFromUDB2
741
     */
742
    abstract protected function createImagesImportedFromUDB2(ImageCollection $images);
743
744
    /**
745
     * @param ImageCollection $images
746
     * @return AbstractImagesUpdatedFromUDB2
747
     */
748
    abstract protected function createImagesUpdatedFromUDB2(ImageCollection $images);
749
}
750