Completed
Push — master ( 70b047...5c79cc )
by Kristof
03:34
created

Projector::applyConstraintAdded()   A

Complexity

Conditions 2
Paths 2

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 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
    protected function applyConstraintAdded(ConstraintAdded $constraintAdded)
85
    {
86
        if ($constraintAdded->getSapiVersion()->sameValueAs($this->sapiVersion)) {
87
            $this->repository->updateConstraint(
88
                $constraintAdded->getUuid(),
89
                $constraintAdded->getQuery()
90
            );
91
        }
92
    }
93
94
    /**
95
     * @param ConstraintUpdated $constraintUpdated
96
     */
97
    protected function applyConstraintUpdated(ConstraintUpdated $constraintUpdated)
98
    {
99
        if ($constraintUpdated->getSapiVersion()->sameValueAs($this->sapiVersion)) {
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()->sameValueAs($this->sapiVersion)) {
113
            $this->repository->updateConstraint(
114
                $constraintRemoved->getUuid()
115
            );
116
        }
117
    }
118
}
119