Completed
Pull Request — master (#436)
by
unknown
03:00
created

OrganizerLDProjector   A

Complexity

Total Complexity 39

Size/Duplication

Total Lines 521
Duplicated Lines 27.06 %

Coupling/Cohesion

Components 1
Dependencies 34

Importance

Changes 0
Metric Value
wmc 39
lcom 1
cbo 34
dl 141
loc 521
rs 9.28
c 0
b 0
f 0

22 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A handle() 0 19 3
A applyOrganizerImportedFromUDB2() 20 20 1
A applyOrganizerCreated() 0 39 2
A appendCreator() 0 11 2
A applyOrganizerCreatedWithUniqueWebsite() 0 32 1
A applyWebsiteUpdated() 11 11 1
A applyTitleUpdated() 0 4 1
A applyTitleTranslated() 0 8 1
A applyAddressUpdated() 0 4 1
A applyAddressTranslated() 0 4 1
A applyContactPointUpdated() 0 12 1
A applyOrganizerUpdatedFromUDB2() 27 27 2
A applyLabelAdded() 17 17 3
A applyLabelRemoved() 32 32 5
A applyOrganizerDeleted() 0 11 1
A newDocument() 14 14 1
A applyTitle() 0 30 4
A applyAddress() 0 21 3
A applyGeoCoordinatesUpdated() 11 11 1
A loadDocumentFromRepository() 0 10 2
A updateModified() 9 9 1

How to fix   Duplicated Code   

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:

1
<?php
2
3
namespace CultuurNet\UDB3\Organizer;
4
5
use Broadway\Domain\DateTime;
6
use Broadway\Domain\DomainMessage;
7
use Broadway\EventHandling\EventBusInterface;
8
use Broadway\EventHandling\EventListenerInterface;
9
use CultuurNet\UDB3\Actor\ActorEvent;
10
use CultuurNet\UDB3\Cdb\ActorItemFactory;
11
use CultuurNet\UDB3\Event\ReadModel\DocumentGoneException;
12
use CultuurNet\UDB3\Event\ReadModel\DocumentRepositoryInterface;
13
use CultuurNet\UDB3\EventHandling\DelegateEventHandlingToSpecificMethodTrait;
14
use CultuurNet\UDB3\Iri\IriGeneratorInterface;
15
use CultuurNet\UDB3\Label;
16
use CultuurNet\UDB3\Language;
17
use CultuurNet\UDB3\Organizer\Events\AddressTranslated;
18
use CultuurNet\UDB3\Organizer\Events\AddressUpdated;
19
use CultuurNet\UDB3\Organizer\Events\ContactPointUpdated;
20
use CultuurNet\UDB3\Organizer\Events\GeoCoordinatesUpdated;
21
use CultuurNet\UDB3\Organizer\Events\LabelAdded;
22
use CultuurNet\UDB3\Organizer\Events\LabelRemoved;
23
use CultuurNet\UDB3\Organizer\Events\OrganizerCreated;
24
use CultuurNet\UDB3\Organizer\Events\OrganizerCreatedWithUniqueWebsite;
25
use CultuurNet\UDB3\Organizer\Events\OrganizerDeleted;
26
use CultuurNet\UDB3\Organizer\Events\OrganizerEvent;
27
use CultuurNet\UDB3\Organizer\Events\OrganizerImportedFromUDB2;
28
use CultuurNet\UDB3\Organizer\Events\OrganizerUpdatedFromUDB2;
29
use CultuurNet\UDB3\Organizer\Events\TitleTranslated;
30
use CultuurNet\UDB3\Organizer\Events\TitleUpdated;
31
use CultuurNet\UDB3\Organizer\Events\WebsiteUpdated;
32
use CultuurNet\UDB3\Organizer\ReadModel\JSONLD\CdbXMLImporter;
33
use CultuurNet\UDB3\ReadModel\JsonDocument;
34
use CultuurNet\UDB3\ReadModel\JsonDocumentMetaDataEnricherInterface;
35
use CultuurNet\UDB3\ReadModel\MultilingualJsonLDProjectorTrait;
36
use CultuurNet\UDB3\RecordedOn;
37
use CultuurNet\UDB3\Title;
38
39
class OrganizerLDProjector implements EventListenerInterface
40
{
41
    use MultilingualJsonLDProjectorTrait;
42
    /**
43
     * @uses applyOrganizerImportedFromUDB2
44
     * @uses applyOrganizerCreated
45
     * @uses applyOrganizerCreatedWithUniqueWebsite
46
     * @uses applyWebsiteUpdated
47
     * @uses applyTitleUpdated
48
     * @uses applyTitleTranslated
49
     * @uses applyAddressUpdated
50
     * @uses applyAddressTranslated
51
     * @uses applyContactPointUpdated
52
     * @uses applyOrganizerUpdatedFRomUDB2
53
     * @uses applyLabelAdded
54
     * @uses applyLabelRemoved
55
     * @uses applyOrganizerDeleted
56
     */
57
    use DelegateEventHandlingToSpecificMethodTrait {
58
        DelegateEventHandlingToSpecificMethodTrait::handle as handleMethodSpecificEvents;
59
    }
60
61
    /**
62
     * @var DocumentRepositoryInterface
63
     */
64
    private $repository;
65
66
    /**
67
     * @var IriGeneratorInterface
68
     */
69
    private $iriGenerator;
70
71
    /**
72
     * @var EventBusInterface
73
     */
74
    private $eventBus;
75
76
    /**
77
     * @var JsonDocumentMetaDataEnricherInterface
78
     */
79
    private $jsonDocumentMetaDataEnricher;
80
81
    /**
82
     * @var CdbXMLImporter
83
     */
84
    private $cdbXMLImporter;
85
86
    /**
87
     * @param DocumentRepositoryInterface $repository
88
     * @param IriGeneratorInterface $iriGenerator
89
     * @param EventBusInterface $eventBus
90
     * @param JsonDocumentMetaDataEnricherInterface $jsonDocumentMetaDataEnricher
91
     */
92
    public function __construct(
93
        DocumentRepositoryInterface $repository,
94
        IriGeneratorInterface $iriGenerator,
95
        EventBusInterface $eventBus,
96
        JsonDocumentMetaDataEnricherInterface $jsonDocumentMetaDataEnricher
97
    ) {
98
        $this->repository = $repository;
99
        $this->iriGenerator = $iriGenerator;
100
        $this->eventBus = $eventBus;
101
        $this->jsonDocumentMetaDataEnricher = $jsonDocumentMetaDataEnricher;
102
        $this->cdbXMLImporter = new CdbXMLImporter();
103
    }
104
105
    /**
106
     * @inheritdoc
107
     */
108
    public function handle(DomainMessage $domainMessage)
109
    {
110
        $event = $domainMessage->getPayload();
111
112
        $handleMethod = $this->getHandleMethodName($event);
113
        if (!$handleMethod) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $handleMethod of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
114
            return;
115
        }
116
117
        $jsonDocument = $this->{$handleMethod}($event, $domainMessage);
118
119
        if ($jsonDocument) {
120
            $jsonDocument = $this->jsonDocumentMetaDataEnricher->enrich($jsonDocument, $domainMessage->getMetadata());
121
122
            $jsonDocument = $this->updateModified($jsonDocument, $domainMessage);
123
124
            $this->repository->save($jsonDocument);
125
        }
126
    }
127
128
    /**
129
     * @param OrganizerImportedFromUDB2 $organizerImportedFromUDB2
130
     * @return JsonDocument
131
     * @throws \CultureFeed_Cdb_ParseException
132
     */
133 View Code Duplication
    private function applyOrganizerImportedFromUDB2(
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...
134
        OrganizerImportedFromUDB2 $organizerImportedFromUDB2
135
    ) {
136
        $udb2Actor = ActorItemFactory::createActorFromCdbXml(
137
            $organizerImportedFromUDB2->getCdbXmlNamespaceUri(),
138
            $organizerImportedFromUDB2->getCdbXml()
139
        );
140
141
        $document = $this->newDocument($organizerImportedFromUDB2->getActorId());
142
        $jsonLD = $document->getBody();
143
144
        $jsonLD = $this->cdbXMLImporter->documentWithCdbXML(
145
            $jsonLD,
146
            $udb2Actor
147
        );
148
149
        $jsonLD->workflowStatus = WorkflowStatus::ACTIVE()->getName();
150
151
        return $document->withBody($jsonLD);
152
    }
153
154
    /**
155
     * @param OrganizerCreated $organizerCreated
156
     * @param DomainMessage $domainMessage
157
     * @return JsonDocument
158
     */
159
    private function applyOrganizerCreated(OrganizerCreated $organizerCreated, DomainMessage $domainMessage)
160
    {
161
        $document = $this->newDocument($organizerCreated->getOrganizerId());
162
163
        $jsonLD = $document->getBody();
164
165
        $jsonLD->{'@id'} = $this->iriGenerator->iri(
166
            $organizerCreated->getOrganizerId()
167
        );
168
169
        $jsonLD->name = [
170
            $this->getMainLanguage($jsonLD)->getCode() => $organizerCreated->getTitle(),
171
        ];
172
173
        // Only take the first address into account.
174
        $addresses = $organizerCreated->getAddresses();
175
        if (!empty($addresses)) {
176
            $address = $addresses[0];
177
            $jsonLD->address = [
178
                $this->getMainLanguage($jsonLD)->getCode() => $address->toJsonLd(),
179
            ];
180
        }
181
182
        $jsonLD->phone = $organizerCreated->getPhones();
183
        $jsonLD->email = $organizerCreated->getEmails();
184
        $jsonLD->url = $organizerCreated->getUrls();
185
186
        $recordedOn = $domainMessage->getRecordedOn()->toString();
187
        $jsonLD->created = \DateTime::createFromFormat(
188
            DateTime::FORMAT_STRING,
189
            $recordedOn
190
        )->format('c');
191
192
        $jsonLD = $this->appendCreator($jsonLD, $domainMessage);
193
194
        $jsonLD->workflowStatus = WorkflowStatus::ACTIVE()->getName();
195
196
        return $document->withBody($jsonLD);
197
    }
198
199
    /**
200
     * @param $jsonLD
201
     * @param DomainMessage $domainMessage
202
     * @return mixed
203
     */
204
    private function appendCreator($jsonLD, $domainMessage)
205
    {
206
        $newJsonLD = clone $jsonLD;
207
208
        $metaData = $domainMessage->getMetadata()->serialize();
209
        if (isset($metaData['user_id'])) {
210
            $newJsonLD->creator = $metaData['user_id'];
211
        }
212
213
        return $newJsonLD;
214
    }
215
216
    /**
217
     * @param OrganizerCreatedWithUniqueWebsite $organizerCreated
218
     * @param DomainMessage $domainMessage
219
     * @return JsonDocument
220
     */
221
    private function applyOrganizerCreatedWithUniqueWebsite(
222
        OrganizerCreatedWithUniqueWebsite $organizerCreated,
223
        DomainMessage $domainMessage
224
    ) {
225
        $document = $this->newDocument($organizerCreated->getOrganizerId());
226
227
        $jsonLD = $document->getBody();
228
229
        $jsonLD->{'@id'} = $this->iriGenerator->iri(
230
            $organizerCreated->getOrganizerId()
231
        );
232
233
        $this->setMainLanguage($jsonLD, $organizerCreated->getMainLanguage());
234
235
        $jsonLD->url = (string) $organizerCreated->getWebsite();
236
237
        $jsonLD->name = [
238
            $this->getMainLanguage($jsonLD)->getCode() => $organizerCreated->getTitle(),
239
        ];
240
241
        $recordedOn = $domainMessage->getRecordedOn()->toString();
242
        $jsonLD->created = \DateTime::createFromFormat(
243
            DateTime::FORMAT_STRING,
244
            $recordedOn
245
        )->format('c');
246
247
        $jsonLD = $this->appendCreator($jsonLD, $domainMessage);
248
249
        $jsonLD->workflowStatus = WorkflowStatus::ACTIVE()->getName();
250
251
        return $document->withBody($jsonLD);
252
    }
253
254
    /**
255
     * @param WebsiteUpdated $websiteUpdated
256
     * @return JsonDocument
257
     */
258 View Code Duplication
    private function applyWebsiteUpdated(WebsiteUpdated $websiteUpdated)
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...
259
    {
260
        $organizerId = $websiteUpdated->getOrganizerId();
261
262
        $document = $this->repository->get($organizerId);
263
264
        $jsonLD = $document->getBody();
265
        $jsonLD->url = (string) $websiteUpdated->getWebsite();
266
267
        return $document->withBody($jsonLD);
268
    }
269
270
    /**
271
     * @param TitleUpdated $titleUpdated
272
     * @return JsonDocument
273
     */
274
    private function applyTitleUpdated(TitleUpdated $titleUpdated)
275
    {
276
        return $this->applyTitle($titleUpdated, $titleUpdated->getTitle());
277
    }
278
279
    /**
280
     * @param TitleTranslated $titleTranslated
281
     * @return JsonDocument
282
     */
283
    private function applyTitleTranslated(TitleTranslated $titleTranslated)
284
    {
285
        return $this->applyTitle(
286
            $titleTranslated,
287
            $titleTranslated->getTitle(),
288
            $titleTranslated->getLanguage()
289
        );
290
    }
291
292
    /**
293
     * @param AddressUpdated $addressUpdated
294
     * @return JsonDocument
295
     */
296
    private function applyAddressUpdated(AddressUpdated $addressUpdated)
297
    {
298
        return $this->applyAddress($addressUpdated);
299
    }
300
301
    /**
302
     * @param AddressTranslated $addressTranslated
303
     * @return JsonDocument
304
     */
305
    private function applyAddressTranslated(AddressTranslated $addressTranslated)
306
    {
307
        return $this->applyAddress($addressTranslated, $addressTranslated->getLanguage());
308
    }
309
310
    /**
311
     * @param ContactPointUpdated $contactPointUpdated
312
     * @return JsonDocument
313
     */
314
    private function applyContactPointUpdated(ContactPointUpdated $contactPointUpdated)
315
    {
316
        $organizerId = $contactPointUpdated->getOrganizerId();
317
        $contactPoint = $contactPointUpdated->getContactPoint();
318
319
        $document = $this->repository->get($organizerId);
320
321
        $jsonLD = $document->getBody();
322
        $jsonLD->contactPoint = $contactPoint->toJsonLd();
323
324
        return $document->withBody($jsonLD);
325
    }
326
327
    /**
328
     * @param OrganizerUpdatedFromUDB2 $organizerUpdatedFromUDB2
329
     * @return JsonDocument
330
     * @throws \CultureFeed_Cdb_ParseException
331
     */
332 View Code Duplication
    private function applyOrganizerUpdatedFromUDB2(
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...
333
        OrganizerUpdatedFromUDB2 $organizerUpdatedFromUDB2
334
    ) {
335
        // It's possible that an organizer has been deleted in udb3, but never
336
        // in udb2. If an update comes for that organizer from udb2, it should
337
        // be imported again. This is intended by design.
338
        // @see https://jira.uitdatabank.be/browse/III-1092
339
        try {
340
            $document = $this->loadDocumentFromRepository(
341
                $organizerUpdatedFromUDB2
342
            );
343
        } catch (DocumentGoneException $e) {
344
            $document = $this->newDocument($organizerUpdatedFromUDB2->getActorId());
345
        }
346
347
        $udb2Actor = ActorItemFactory::createActorFromCdbXml(
348
            $organizerUpdatedFromUDB2->getCdbXmlNamespaceUri(),
349
            $organizerUpdatedFromUDB2->getCdbXml()
350
        );
351
352
        $actorLd = $this->cdbXMLImporter->documentWithCdbXML(
353
            $document->getBody(),
354
            $udb2Actor
355
        );
356
357
        return $document->withBody($actorLd);
358
    }
359
360
    /**
361
     * @param LabelAdded $labelAdded
362
     * @return JsonDocument
363
     */
364 View Code Duplication
    private function applyLabelAdded(LabelAdded $labelAdded)
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...
365
    {
366
        $document = $this->repository->get($labelAdded->getOrganizerId());
367
368
        $jsonLD = $document->getBody();
369
370
        // Check the visibility of the label to update the right property.
371
        $labelsProperty = $labelAdded->getLabel()->isVisible() ? 'labels' : 'hiddenLabels';
372
373
        $labels = isset($jsonLD->{$labelsProperty}) ? $jsonLD->{$labelsProperty} : [];
374
        $label = (string) $labelAdded->getLabel();
375
376
        $labels[] = $label;
377
        $jsonLD->{$labelsProperty} = array_unique($labels);
378
379
        return $document->withBody($jsonLD);
380
    }
381
382
    /**
383
     * @param LabelRemoved $labelRemoved
384
     * @return JsonDocument
385
     */
386 View Code Duplication
    private function applyLabelRemoved(LabelRemoved $labelRemoved)
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...
387
    {
388
        $document = $this->repository->get($labelRemoved->getOrganizerId());
389
        $jsonLD = $document->getBody();
390
391
        // Don't presume that the label visibility is correct when removing.
392
        // So iterate over both the visible and invisible labels.
393
        $labelsProperties = ['labels', 'hiddenLabels'];
394
395
        foreach ($labelsProperties as $labelsProperty) {
396
            if (isset($jsonLD->{$labelsProperty}) && is_array($jsonLD->{$labelsProperty})) {
397
                $jsonLD->{$labelsProperty} = array_filter(
398
                    $jsonLD->{$labelsProperty},
399
                    function ($label) use ($labelRemoved) {
400
                        return !$labelRemoved->getLabel()->equals(
401
                            new Label($label)
402
                        );
403
                    }
404
                );
405
406
                // Ensure array keys start with 0 so json_encode() does encode it
407
                // as an array and not as an object.
408
                if (count($jsonLD->{$labelsProperty}) > 0) {
409
                    $jsonLD->{$labelsProperty} = array_values($jsonLD->{$labelsProperty});
410
                } else {
411
                    unset($jsonLD->{$labelsProperty});
412
                }
413
            }
414
        }
415
416
        return $document->withBody($jsonLD);
417
    }
418
419
    /**
420
     * @param OrganizerDeleted $organizerDeleted
421
     * @return null
422
     */
423
    private function applyOrganizerDeleted(
424
        OrganizerDeleted $organizerDeleted
425
    ) {
426
        $document =  $this->repository->get($organizerDeleted->getOrganizerId());
427
428
        $jsonLD = $document->getBody();
429
430
        $jsonLD->workflowStatus = WorkflowStatus::DELETED()->getName();
431
432
        return $document->withBody($jsonLD);
433
    }
434
435
    /**
436
     * @param string $id
437
     * @return JsonDocument
438
     */
439 View Code Duplication
    private function newDocument($id)
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...
440
    {
441
        $document = new JsonDocument($id);
442
443
        $organizerLd = $document->getBody();
444
        $organizerLd->{'@id'} = $this->iriGenerator->iri($id);
445
        $organizerLd->{'@context'} = '/contexts/organizer';
446
        // For an new organizer document set a default language of nl.
447
        // This avoids a missing language for imports.
448
        // When created with UDB3 this main language gets overwritten by the real one.
449
        $organizerLd->mainLanguage = 'nl';
450
451
        return $document->withBody($organizerLd);
452
    }
453
454
    /**
455
     * @param OrganizerEvent $organizerEvent
456
     * @param Title $title
457
     * @param Language|null $language
458
     * @return JsonDocument
459
     */
460
    private function applyTitle(
461
        OrganizerEvent $organizerEvent,
462
        Title $title,
463
        Language $language = null
464
    ) {
465
        $organizerId = $organizerEvent->getOrganizerId();
466
467
        $document = $this->repository->get($organizerId);
468
469
        $jsonLD = $document->getBody();
470
471
        $mainLanguage = $this->getMainLanguage($jsonLD);
472
        if ($language === null) {
473
            $language = $mainLanguage;
474
        }
475
476
        // @replay_i18n For old projections the name is untranslated and just a string.
477
        // This needs to be upgraded to an object with languages and translation.
478
        // When a full replay is done this code becomes obsolete.
479
        // @see https://jira.uitdatabank.be/browse/III-2201
480
        if (isset($jsonLD->name) && is_string($jsonLD->name)) {
481
            $previousTitle = $jsonLD->name;
482
            $jsonLD->name = new \StdClass();
483
            $jsonLD->name->{$mainLanguage->getCode()} = $previousTitle;
484
        }
485
486
        $jsonLD->name->{$language->getCode()} = $title->toNative();
487
488
        return $document->withBody($jsonLD);
489
    }
490
491
    /**
492
     * @param AddressUpdated $addressUpdated
493
     * @param Language $language
494
     * @return JsonDocument|null
495
     */
496
    private function applyAddress(
497
        AddressUpdated $addressUpdated,
498
        Language $language = null
499
    ) {
500
        $organizerId = $addressUpdated->getOrganizerId();
501
        $document = $this->repository->get($organizerId);
502
        $jsonLD = $document->getBody();
503
504
        $mainLanguage = $this->getMainLanguage($jsonLD);
505
        if ($language === null) {
506
            $language = $mainLanguage;
507
        }
508
509
        if (!isset($jsonLD->address)) {
510
            $jsonLD->address = new \stdClass();
511
        }
512
513
        $jsonLD->address->{$language->getCode()} = $addressUpdated->getAddress()->toJsonLd();
514
515
        return $document->withBody($jsonLD);
516
    }
517
518 View Code Duplication
    public function applyGeoCoordinatesUpdated(GeoCoordinatesUpdated $geoCoordinatesUpdated)
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...
519
    {
520
521
        $document = $this->repository->get($geoCoordinatesUpdated->getOrganizerId());
522
523
        $jsonLD = $document->getBody();
524
525
        $jsonLD->geo = $geoCoordinatesUpdated->toJsonLd();
526
527
        return $document->withBody($jsonLD);
528
    }
529
530
    /**
531
     * @param ActorEvent $actor
532
     * @return JsonDocument
533
     */
534
    private function loadDocumentFromRepository(ActorEvent $actor)
535
    {
536
        $document = $this->repository->get($actor->getActorId());
537
538
        if (!$document) {
539
            return $this->newDocument($actor->getActorId());
540
        }
541
542
        return $document;
543
    }
544
545
    /**
546
     * @param JsonDocument $jsonDocument
547
     * @param DomainMessage $domainMessage
548
     * @return JsonDocument
549
     */
550 View Code Duplication
    private function updateModified(JsonDocument $jsonDocument, DomainMessage $domainMessage)
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...
551
    {
552
        $body = $jsonDocument->getBody();
553
554
        $recordedDateTime = RecordedOn::fromDomainMessage($domainMessage);
555
        $body->modified = $recordedDateTime->toString();
556
557
        return $jsonDocument->withBody($body);
558
    }
559
}
560