Completed
Pull Request — feature/test-php-7-2-in-travis (#309)
by
unknown
04:53 queued 02:32
created

applySecondFactorVettedPossessionSkippedEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * Copyright 2014 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupMiddleware\GatewayBundle\Projector;
20
21
use Broadway\ReadModel\Projector;
22
use Surfnet\Stepup\Identity\Event\CompliedWithVettedSecondFactorRevocationEvent;
23
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;
24
use Surfnet\Stepup\Identity\Event\LocalePreferenceExpressedEvent;
25
use Surfnet\Stepup\Identity\Event\SecondFactorVettedPossessionSkippedEvent;
26
use Surfnet\Stepup\Identity\Event\SecondFactorVettedEvent;
27
use Surfnet\Stepup\Identity\Event\VettedSecondFactorRevokedEvent;
28
use Surfnet\Stepup\Identity\Event\YubikeySecondFactorBootstrappedEvent;
29
use Surfnet\StepupMiddleware\GatewayBundle\Entity\SecondFactor;
30
use Surfnet\StepupMiddleware\GatewayBundle\Exception\RuntimeException;
31
use Surfnet\StepupMiddleware\GatewayBundle\Repository\SecondFactorRepository;
32
33
class SecondFactorProjector extends Projector
34
{
35
    /**
36
     * @var SecondFactorRepository
37
     */
38
    private $repository;
39
40
    /**
41
     * @param SecondFactorRepository $repository
42
     */
43
    public function __construct(SecondFactorRepository $repository)
44
    {
45
        $this->repository = $repository;
46
    }
47
48 View Code Duplication
    public function applyYubikeySecondFactorBootstrappedEvent(YubikeySecondFactorBootstrappedEvent $event)
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...
49
    {
50
        $this->repository->save(
51
            new SecondFactor(
52
                (string) $event->identityId,
53
                (string) $event->nameId,
54
                (string) $event->identityInstitution,
55
                (string) $event->preferredLocale,
56
                (string) $event->secondFactorId,
57
                (string) $event->yubikeyPublicId,
58
                'yubikey'
59
            )
60
        );
61
    }
62
63 View Code Duplication
    public function applySecondFactorVettedEvent(SecondFactorVettedEvent $event)
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
    {
65
        $this->repository->save(
66
            new SecondFactor(
67
                (string) $event->identityId,
68
                (string) $event->nameId,
69
                (string) $event->identityInstitution,
70
                (string) $event->preferredLocale,
71
                (string) $event->secondFactorId,
72
                $event->secondFactorIdentifier,
73
                $event->secondFactorType
74
            )
75
        );
76
    }
77
78 View Code Duplication
    public function applySecondFactorVettedPossessionSkippedEvent(SecondFactorVettedPossessionSkippedEvent $event)
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...
79
    {
80
        $this->repository->save(
81
            new SecondFactor(
82
                (string) $event->identityId,
83
                (string) $event->nameId,
84
                (string) $event->identityInstitution,
85
                (string) $event->preferredLocale,
86
                (string) $event->secondFactorId,
87
                $event->secondFactorIdentifier,
88
                $event->secondFactorType
89
            )
90
        );
91
    }
92
93 View Code Duplication
    protected function applyVettedSecondFactorRevokedEvent(VettedSecondFactorRevokedEvent $event)
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...
94
    {
95
        $secondFactor = $this->repository->findOneBySecondFactorId($event->secondFactorId);
96
97
        if ($secondFactor === null) {
98
            throw new RuntimeException(sprintf(
99
                'Expected to find a second factor having secondFactorId "%s", found none.',
100
                $event->secondFactorId
101
            ));
102
        }
103
104
        $this->repository->remove($secondFactor);
105
    }
106
107 View Code Duplication
    protected function applyCompliedWithVettedSecondFactorRevocationEvent(
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...
108
        CompliedWithVettedSecondFactorRevocationEvent $event
109
    ) {
110
        $secondFactor = $this->repository->findOneBySecondFactorId($event->secondFactorId);
111
112
        if ($secondFactor === null) {
113
            throw new RuntimeException(sprintf(
114
                'Expected to find a second factor having secondFactorId "%s", found none.',
115
                $event->secondFactorId
116
            ));
117
        }
118
119
        $this->repository->remove($secondFactor);
120
    }
121
122
    protected function applyLocalePreferenceExpressedEvent(LocalePreferenceExpressedEvent $event)
123
    {
124
        $secondFactors = $this->repository->findByIdentityId($event->identityId);
125
126
        foreach ($secondFactors as $secondFactor) {
127
            $secondFactor->displayLocale = (string) $event->preferredLocale;
128
            $this->repository->save($secondFactor);
129
        }
130
    }
131
132
    protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event)
133
    {
134
        $this->repository->removeByIdentityId($event->identityId);
135
    }
136
}
137