Completed
Push — master ( 3bba11...039fa3 )
by Kristof
10s
created

Projector::applyEventCreatedFromCdbXml()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 33
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 17
nc 4
nop 2
1
<?php
2
3
namespace CultuurNet\UDB3\Event\ReadModel\Permission;
4
5
use Broadway\Domain\DomainMessage;
6
use Broadway\EventHandling\EventListenerInterface;
7
use CultuurNet\UDB3\Cdb\CreatedByToUserIdResolverInterface;
8
use CultuurNet\UDB3\Cdb\EventItemFactory;
9
use CultuurNet\UDB3\Event\Events\EventCreated;
10
use CultuurNet\UDB3\Event\Events\EventImportedFromUDB2;
11
use CultuurNet\UDB3\EventHandling\DelegateEventHandlingToSpecificMethodTrait;
12
use CultuurNet\UDB3\Offer\ReadModel\Permission\PermissionRepositoryInterface;
13
use ValueObjects\String\String;
14
15
class Projector implements EventListenerInterface
16
{
17
    use DelegateEventHandlingToSpecificMethodTrait;
18
19
    /**
20
     * @var CreatedByToUserIdResolverInterface
21
     */
22
    private $userIdResolver;
23
24
    /**
25
     * @var PermissionRepositoryInterface
26
     */
27
    private $permissionRepository;
28
29
    public function __construct(
30
        PermissionRepositoryInterface $permissionRepository,
31
        CreatedByToUserIdResolverInterface $createdByToUserIdResolver
32
    ) {
33
        $this->userIdResolver = $createdByToUserIdResolver;
34
        $this->permissionRepository = $permissionRepository;
35
    }
36
37 View Code Duplication
    protected function applyEventImportedFromUDB2(
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...
38
        EventImportedFromUDB2 $eventImportedFromUDB2
39
    ) {
40
        $cdbEvent = EventItemFactory::createEventFromCdbXml(
41
            $eventImportedFromUDB2->getCdbXmlNamespaceUri(),
42
            $eventImportedFromUDB2->getCdbXml()
43
        );
44
45
        $createdByIdentifier = $cdbEvent->getCreatedBy();
46
47
        if ($createdByIdentifier) {
48
            $ownerId = $this->userIdResolver->resolveCreatedByToUserId(
49
                new String($createdByIdentifier)
50
            );
51
52
            if (!$ownerId) {
53
                return;
54
            }
55
56
            $this->permissionRepository->markOfferEditableByUser(
57
                new String($eventImportedFromUDB2->getEventId()),
58
                $ownerId
59
            );
60
        }
61
    }
62
63 View Code Duplication
    protected function applyEventCreated(
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...
64
        EventCreated $eventCreated,
65
        DomainMessage $domainMessage
66
    ) {
67
        $metadata = $domainMessage->getMetadata()->serialize();
68
        $ownerId = new String($metadata['user_id']);
69
70
        $this->permissionRepository->markOfferEditableByUser(
71
            new String($eventCreated->getEventId()),
72
            $ownerId
73
        );
74
    }
75
}
76