Completed
Pull Request — master (#394)
by
unknown
13:07
created

Projector::applyRoleRenamed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace CultuurNet\UDB3\Role\ReadModel\Search;
4
5
use Broadway\EventHandling\EventListenerInterface;
6
use Broadway\Domain\DomainMessage;
7
use CultuurNet\UDB3\EventHandling\DelegateEventHandlingToSpecificMethodTrait;
8
use CultuurNet\UDB3\Role\Events\ConstraintAdded;
9
use CultuurNet\UDB3\Role\Events\ConstraintRemoved;
10
use CultuurNet\UDB3\Role\Events\ConstraintUpdated;
11
use CultuurNet\UDB3\Role\Events\RoleCreated;
12
use CultuurNet\UDB3\Role\Events\RoleRenamed;
13
use CultuurNet\UDB3\Role\Events\RoleDeleted;
14
use CultuurNet\UDB3\ValueObject\SapiVersion;
15
16
class Projector implements EventListenerInterface
17
{
18
    use DelegateEventHandlingToSpecificMethodTrait;
19
20
    /**
21
     * @var RepositoryInterface
22
     */
23
    private $repository;
24
25
    /**
26
     * @var SapiVersion
27
     */
28
    private $sapiVersion;
29
30
    /**
31
     * @param RepositoryInterface $repository
32
     * @param SapiVersion $sapiVersion
33
     */
34
    public function __construct(
35
        RepositoryInterface $repository,
36
        SapiVersion $sapiVersion) {
37
        $this->sapiVersion = $sapiVersion;
38
        $this->repository = $repository;
39
    }
40
41
    /**
42
     * @param RoleCreated $roleCreated
43
     * @param DomainMessage $domainMessage
44
     */
45
    public function applyRoleCreated(
46
        RoleCreated $roleCreated,
47
        DomainMessage $domainMessage
0 ignored issues
show
Unused Code introduced by
The parameter $domainMessage 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...
48
    ) {
49
        $this->repository->save(
50
            $roleCreated->getUuid()->toNative(),
51
            $roleCreated->getName()->toNative()
52
        );
53
    }
54
55
    /**
56
     * @param RoleRenamed $roleRenamed
57
     * @param DomainMessage $domainMessage
58
     */
59
    public function applyRoleRenamed(
60
        RoleRenamed $roleRenamed,
61
        DomainMessage $domainMessage
0 ignored issues
show
Unused Code introduced by
The parameter $domainMessage 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...
62
    ) {
63
        $this->repository->updateName(
64
            $roleRenamed->getUuid()->toNative(),
65
            $roleRenamed->getName()->toNative()
66
        );
67
    }
68
69
    /**
70
     * @param RoleDeleted $roleDeleted
71
     * @param DomainMessage $domainMessage
72
     */
73
    public function applyRoleDeleted(
74
        RoleDeleted $roleDeleted,
75
        DomainMessage $domainMessage
0 ignored issues
show
Unused Code introduced by
The parameter $domainMessage 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...
76
    ) {
77
        $this->repository->remove($roleDeleted->getUuid()->toNative());
78
    }
79
80
    /**
81
     * @param ConstraintAdded $constraintAdded
82
     */
83 View Code Duplication
    protected function applyConstraintAdded(ConstraintAdded $constraintAdded) {
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...
84
        if ($constraintAdded->getSapiVersion()
85
                ->toNative() === $this->sapiVersion->toNative()) {
86
            $this->repository->updateConstraint(
87
                $constraintAdded->getUuid(),
88
                $constraintAdded->getQuery()
89
            );
90
        }
91
    }
92
93
    /**
94
     * @param ConstraintUpdated $constraintUpdated
95
     */
96 View Code Duplication
    protected function applyConstraintUpdated(ConstraintUpdated $constraintUpdated)
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...
97
    {
98
        if ($constraintUpdated->getSapiVersion()
99
                ->toNative() === $this->sapiVersion->toNative()) {
100
            $this->repository->updateConstraint(
101
                $constraintUpdated->getUuid(),
102
                $constraintUpdated->getQuery()
103
            );
104
        }
105
    }
106
107
    /**
108
     * @param ConstraintRemoved $constraintRemoved
109
     */
110
    protected function applyConstraintRemoved(ConstraintRemoved $constraintRemoved)
111
    {
112
        if ($constraintRemoved->getSapiVersion()
113
                ->toNative() === $this->sapiVersion->toNative()) {
114
            $this->repository->updateConstraint(
115
                $constraintRemoved->getUuid()
116
            );
117
        }
118
    }
119
}
120