Completed
Pull Request — master (#394)
by
unknown
31:10 queued 09:32
created

Projector::applyConstraintAdded()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 9
Ratio 90 %

Importance

Changes 0
Metric Value
dl 9
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
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
    ) {
38
        $this->sapiVersion = $sapiVersion;
39
        $this->repository = $repository;
40
    }
41
42
    /**
43
     * @param RoleCreated $roleCreated
44
     * @param DomainMessage $domainMessage
45
     */
46
    public function applyRoleCreated(
47
        RoleCreated $roleCreated,
48
        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...
49
    ) {
50
        $this->repository->save(
51
            $roleCreated->getUuid()->toNative(),
52
            $roleCreated->getName()->toNative()
53
        );
54
    }
55
56
    /**
57
     * @param RoleRenamed $roleRenamed
58
     * @param DomainMessage $domainMessage
59
     */
60
    public function applyRoleRenamed(
61
        RoleRenamed $roleRenamed,
62
        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...
63
    ) {
64
        $this->repository->updateName(
65
            $roleRenamed->getUuid()->toNative(),
66
            $roleRenamed->getName()->toNative()
67
        );
68
    }
69
70
    /**
71
     * @param RoleDeleted $roleDeleted
72
     * @param DomainMessage $domainMessage
73
     */
74
    public function applyRoleDeleted(
75
        RoleDeleted $roleDeleted,
76
        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...
77
    ) {
78
        $this->repository->remove($roleDeleted->getUuid()->toNative());
79
    }
80
81
    /**
82
     * @param ConstraintAdded $constraintAdded
83
     */
84 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...
85
    {
86
        if ($constraintAdded->getSapiVersion()
87
                ->toNative() === $this->sapiVersion->toNative()) {
88
            $this->repository->updateConstraint(
89
                $constraintAdded->getUuid(),
90
                $constraintAdded->getQuery()
91
            );
92
        }
93
    }
94
95
    /**
96
     * @param ConstraintUpdated $constraintUpdated
97
     */
98 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...
99
    {
100
        if ($constraintUpdated->getSapiVersion()
101
                ->toNative() === $this->sapiVersion->toNative()) {
102
            $this->repository->updateConstraint(
103
                $constraintUpdated->getUuid(),
104
                $constraintUpdated->getQuery()
105
            );
106
        }
107
    }
108
109
    /**
110
     * @param ConstraintRemoved $constraintRemoved
111
     */
112
    protected function applyConstraintRemoved(ConstraintRemoved $constraintRemoved)
113
    {
114
        if ($constraintRemoved->getSapiVersion()
115
                ->toNative() === $this->sapiVersion->toNative()) {
116
            $this->repository->updateConstraint(
117
                $constraintRemoved->getUuid()
118
            );
119
        }
120
    }
121
}
122