Completed
Push — master ( 73f449...670c74 )
by Kristof
04:33
created

Projector::applyPlaceImportedFromUDB2Event()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 14

Duplication

Lines 25
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 25
loc 25
rs 8.8571
c 1
b 0
f 0
cc 3
eloc 14
nc 3
nop 1
1
<?php
2
3
namespace CultuurNet\UDB3\Place\ReadModel\Permission;
4
5
use Broadway\Domain\DomainMessage;
6
use Broadway\EventHandling\EventListenerInterface;
7
use CultuurNet\UDB3\Cdb\ActorItemFactory;
8
use CultuurNet\UDB3\Cdb\CreatedByToUserIdResolverInterface;
9
use CultuurNet\UDB3\Cdb\EventItemFactory;
10
use CultuurNet\UDB3\Offer\ReadModel\Permission\PermissionRepositoryInterface;
11
use CultuurNet\UDB3\Place\Events\PlaceCreated;
12
use CultuurNet\UDB3\Place\Events\PlaceImportedFromUDB2;
13
use CultuurNet\UDB3\EventHandling\DelegateEventHandlingToSpecificMethodTrait;
14
use CultuurNet\UDB3\Place\Events\PlaceImportedFromUDB2Event;
15
use ValueObjects\String\String;
16
17
class Projector implements EventListenerInterface
18
{
19
    use DelegateEventHandlingToSpecificMethodTrait;
20
21
    /**
22
     * @var CreatedByToUserIdResolverInterface
23
     */
24
    private $userIdResolver;
25
26
    /**
27
     * @var PermissionRepositoryInterface
28
     */
29
    private $permissionRepository;
30
31
    public function __construct(
32
        PermissionRepositoryInterface $permissionRepository,
33
        CreatedByToUserIdResolverInterface $createdByToUserIdResolver
34
    ) {
35
        $this->userIdResolver = $createdByToUserIdResolver;
36
        $this->permissionRepository = $permissionRepository;
37
    }
38
39 View Code Duplication
    protected function applyPlaceImportedFromUDB2(
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...
40
        PlaceImportedFromUDB2 $placeImportedFromUDB2
41
    ) {
42
        $cdbActor = ActorItemFactory::createActorFromCdbXml(
43
            $placeImportedFromUDB2->getCdbXmlNamespaceUri(),
44
            $placeImportedFromUDB2->getCdbXml()
45
        );
46
47
        $createdByIdentifier = $cdbActor->getCreatedBy();
48
49
        if ($createdByIdentifier) {
50
            $ownerId = $this->userIdResolver->resolveCreatedByToUserId(
51
                new String($createdByIdentifier)
52
            );
53
54
            if (!$ownerId) {
55
                return;
56
            }
57
58
            $this->permissionRepository->markOfferEditableByUser(
59
                new String($placeImportedFromUDB2->getActorId()),
60
                $ownerId
61
            );
62
        }
63
    }
64
65 View Code Duplication
    protected function applyPlaceImportedFromUDB2Event(
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...
66
        PlaceImportedFromUDB2Event $placeImportedFromUDB2
67
    ) {
68
        $cdbEvent = EventItemFactory::createEventFromCdbXml(
69
            $placeImportedFromUDB2->getCdbXmlNamespaceUri(),
70
            $placeImportedFromUDB2->getCdbXml()
71
        );
72
73
        $createdByIdentifier = $cdbEvent->getCreatedBy();
74
75
        if ($createdByIdentifier) {
76
            $ownerId = $this->userIdResolver->resolveCreatedByToUserId(
77
                new String($createdByIdentifier)
78
            );
79
80
            if (!$ownerId) {
81
                return;
82
            }
83
84
            $this->permissionRepository->markOfferEditableByUser(
85
                new String($placeImportedFromUDB2->getActorId()),
86
                $ownerId
87
            );
88
        }
89
    }
90
91 View Code Duplication
    protected function applyPlaceCreated(
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...
92
        PlaceCreated $placeCreated,
93
        DomainMessage $domainMessage
94
    ) {
95
        $metadata = $domainMessage->getMetadata()->serialize();
96
        $ownerId = new String($metadata['user_id']);
97
98
        $this->permissionRepository->markOfferEditableByUser(
99
            new String($placeCreated->getPlaceId()),
100
            $ownerId
101
        );
102
    }
103
}
104