Completed
Push — master ( a3c457...aab356 )
by
unknown
03:38
created

SecondFactorProjector   C

Complexity

Total Complexity 19

Size/Duplication

Total Lines 225
Duplicated Lines 48.89 %

Coupling/Cohesion

Components 1
Dependencies 36

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 19
lcom 1
cbo 36
dl 110
loc 225
rs 5
c 1
b 0
f 0

19 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A applyYubikeySecondFactorBootstrappedEvent() 10 10 1
A applyYubikeyPossessionProvenEvent() 11 11 1
A applyYubikeyPossessionProvenAndVerifiedEvent() 14 14 1
A applyPhonePossessionProvenEvent() 11 11 1
A applyPhonePossessionProvenAndVerifiedEvent() 14 14 1
A applyGssfPossessionProvenEvent() 11 11 1
A applyGssfPossessionProvenAndVerifiedEvent() 14 14 1
A applyU2fDevicePossessionProvenEvent() 11 11 1
A applyU2fDevicePossessionProvenAndVerifiedEvent() 14 14 1
A applyEmailVerifiedEvent() 0 17 1
A applySecondFactorVettedEvent() 0 13 1
A applyUnverifiedSecondFactorRevokedEvent() 0 4 1
A applyCompliedWithUnverifiedSecondFactorRevocationEvent() 0 5 1
A applyVerifiedSecondFactorRevokedEvent() 0 4 1
A applyCompliedWithVerifiedSecondFactorRevocationEvent() 0 5 1
A applyVettedSecondFactorRevokedEvent() 0 4 1
A applyCompliedWithVettedSecondFactorRevocationEvent() 0 5 1
A applyIdentityForgottenEvent() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\ApiBundle\Identity\Projector;
20
21
use Broadway\ReadModel\Projector;
22
use Surfnet\Stepup\Identity\Event\CompliedWithUnverifiedSecondFactorRevocationEvent;
23
use Surfnet\Stepup\Identity\Event\CompliedWithVerifiedSecondFactorRevocationEvent;
24
use Surfnet\Stepup\Identity\Event\CompliedWithVettedSecondFactorRevocationEvent;
25
use Surfnet\Stepup\Identity\Event\EmailVerifiedEvent;
26
use Surfnet\Stepup\Identity\Event\GssfPossessionProvenAndVerifiedEvent;
27
use Surfnet\Stepup\Identity\Event\GssfPossessionProvenEvent;
28
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;
29
use Surfnet\Stepup\Identity\Event\PhonePossessionProvenAndVerifiedEvent;
30
use Surfnet\Stepup\Identity\Event\PhonePossessionProvenEvent;
31
use Surfnet\Stepup\Identity\Event\SecondFactorVettedEvent;
32
use Surfnet\Stepup\Identity\Event\U2fDevicePossessionProvenAndVerifiedEvent;
33
use Surfnet\Stepup\Identity\Event\U2fDevicePossessionProvenEvent;
34
use Surfnet\Stepup\Identity\Event\UnverifiedSecondFactorRevokedEvent;
35
use Surfnet\Stepup\Identity\Event\VerifiedSecondFactorRevokedEvent;
36
use Surfnet\Stepup\Identity\Event\VettedSecondFactorRevokedEvent;
37
use Surfnet\Stepup\Identity\Event\YubikeyPossessionProvenAndVerifiedEvent;
38
use Surfnet\Stepup\Identity\Event\YubikeyPossessionProvenEvent;
39
use Surfnet\Stepup\Identity\Event\YubikeySecondFactorBootstrappedEvent;
40
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\UnverifiedSecondFactor;
41
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\VerifiedSecondFactor;
42
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\VettedSecondFactor;
43
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\IdentityRepository;
44
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\UnverifiedSecondFactorRepository;
45
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\VerifiedSecondFactorRepository;
46
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\VettedSecondFactorRepository;
47
48
/**
49
 * @SuppressWarnings(PHPMD.TooManyMethods)
50
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
51
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
52
 */
53
class SecondFactorProjector extends Projector
54
{
55
    /**
56
     * @var \Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\UnverifiedSecondFactorRepository
57
     */
58
    private $unverifiedRepository;
59
60
    /**
61
     * @var \Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\VerifiedSecondFactorRepository
62
     */
63
    private $verifiedRepository;
64
65
    /**
66
     * @var \Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\VettedSecondFactorRepository
67
     */
68
    private $vettedRepository;
69
70
    /**
71
     * @var \Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\IdentityRepository
72
     */
73
    private $identityRepository;
74
75
    public function __construct(
76
        UnverifiedSecondFactorRepository $unverifiedRepository,
77
        VerifiedSecondFactorRepository $verifiedRepository,
78
        VettedSecondFactorRepository $vettedRepository,
79
        IdentityRepository $identityRepository
80
    ) {
81
        $this->unverifiedRepository = $unverifiedRepository;
82
        $this->verifiedRepository = $verifiedRepository;
83
        $this->vettedRepository = $vettedRepository;
84
        $this->identityRepository = $identityRepository;
85
    }
86
87 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...
88
    {
89
        $secondFactor = new VettedSecondFactor();
90
        $secondFactor->id = $event->secondFactorId->getSecondFactorId();
91
        $secondFactor->identityId = $event->identityId->getIdentityId();
92
        $secondFactor->type = 'yubikey';
93
        $secondFactor->secondFactorIdentifier = $event->yubikeyPublicId->getValue();
94
95
        $this->vettedRepository->save($secondFactor);
96
    }
97
98 View Code Duplication
    public function applyYubikeyPossessionProvenEvent(YubikeyPossessionProvenEvent $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...
99
    {
100
        $secondFactor = new UnverifiedSecondFactor();
101
        $secondFactor->id = $event->secondFactorId->getSecondFactorId();
102
        $secondFactor->identityId = $event->identityId->getIdentityId();
103
        $secondFactor->type = 'yubikey';
104
        $secondFactor->secondFactorIdentifier = $event->yubikeyPublicId->getValue();
105
        $secondFactor->verificationNonce = $event->emailVerificationNonce;
106
107
        $this->unverifiedRepository->save($secondFactor);
108
    }
109
110 View Code Duplication
    public function applyYubikeyPossessionProvenAndVerifiedEvent(YubikeyPossessionProvenAndVerifiedEvent $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...
111
    {
112
        $secondFactor = new VerifiedSecondFactor();
113
        $secondFactor->id = $event->secondFactorId->getSecondFactorId();
114
        $secondFactor->identityId = $event->identityId->getIdentityId();
115
        $secondFactor->institution = $event->identityInstitution->getInstitution();
116
        $secondFactor->type = 'yubikey';
117
        $secondFactor->secondFactorIdentifier = $event->yubikeyPublicId->getValue();
118
        $secondFactor->commonName = $event->commonName;
0 ignored issues
show
Documentation Bug introduced by
It seems like $event->commonName of type object<Surfnet\Stepup\Identity\Value\CommonName> is incompatible with the declared type string of property $commonName.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
119
        $secondFactor->registrationRequestedAt = $event->registrationRequestedAt;
0 ignored issues
show
Documentation Bug introduced by
It seems like $event->registrationRequestedAt of type object<Surfnet\Stepup\DateTime\DateTime> is incompatible with the declared type object<DateTime> of property $registrationRequestedAt.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
120
        $secondFactor->registrationCode = $event->registrationCode;
121
122
        $this->verifiedRepository->save($secondFactor);
123
    }
124
125 View Code Duplication
    public function applyPhonePossessionProvenEvent(PhonePossessionProvenEvent $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...
126
    {
127
        $secondFactor = new UnverifiedSecondFactor();
128
        $secondFactor->id = $event->secondFactorId->getSecondFactorId();
129
        $secondFactor->identityId = $event->identityId->getIdentityId();
130
        $secondFactor->type = 'sms';
131
        $secondFactor->secondFactorIdentifier = $event->phoneNumber->getValue();
132
        $secondFactor->verificationNonce = $event->emailVerificationNonce;
133
134
        $this->unverifiedRepository->save($secondFactor);
135
    }
136
137 View Code Duplication
    public function applyPhonePossessionProvenAndVerifiedEvent(PhonePossessionProvenAndVerifiedEvent $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...
138
    {
139
        $secondFactor = new VerifiedSecondFactor();
140
        $secondFactor->id = $event->secondFactorId->getSecondFactorId();
141
        $secondFactor->identityId = $event->identityId->getIdentityId();
142
        $secondFactor->institution = $event->identityInstitution->getInstitution();
143
        $secondFactor->type = 'sms';
144
        $secondFactor->secondFactorIdentifier = $event->phoneNumber->getValue();
145
        $secondFactor->commonName = $event->commonName;
0 ignored issues
show
Documentation Bug introduced by
It seems like $event->commonName of type object<Surfnet\Stepup\Identity\Value\CommonName> is incompatible with the declared type string of property $commonName.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
146
        $secondFactor->registrationRequestedAt = $event->registrationRequestedAt;
0 ignored issues
show
Documentation Bug introduced by
It seems like $event->registrationRequestedAt of type object<Surfnet\Stepup\DateTime\DateTime> is incompatible with the declared type object<DateTime> of property $registrationRequestedAt.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
147
        $secondFactor->registrationCode = $event->registrationCode;
148
149
        $this->verifiedRepository->save($secondFactor);
150
    }
151
152 View Code Duplication
    public function applyGssfPossessionProvenEvent(GssfPossessionProvenEvent $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...
153
    {
154
        $secondFactor = new UnverifiedSecondFactor();
155
        $secondFactor->id = $event->secondFactorId->getSecondFactorId();
156
        $secondFactor->identityId = $event->identityId->getIdentityId();
157
        $secondFactor->type = $event->stepupProvider->getStepupProvider();
158
        $secondFactor->secondFactorIdentifier = $event->gssfId->getValue();
159
        $secondFactor->verificationNonce = $event->emailVerificationNonce;
160
161
        $this->unverifiedRepository->save($secondFactor);
162
    }
163
164 View Code Duplication
    public function applyGssfPossessionProvenAndVerifiedEvent(GssfPossessionProvenAndVerifiedEvent $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...
165
    {
166
        $secondFactor = new VerifiedSecondFactor();
167
        $secondFactor->id = $event->secondFactorId->getSecondFactorId();
168
        $secondFactor->identityId = $event->identityId->getIdentityId();
169
        $secondFactor->institution = $event->identityInstitution->getInstitution();
170
        $secondFactor->type = $event->stepupProvider->getStepupProvider();
171
        $secondFactor->secondFactorIdentifier = $event->gssfId->getValue();
172
        $secondFactor->commonName = $event->commonName;
0 ignored issues
show
Documentation Bug introduced by
It seems like $event->commonName of type object<Surfnet\Stepup\Identity\Value\CommonName> is incompatible with the declared type string of property $commonName.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
173
        $secondFactor->registrationRequestedAt = $event->registrationRequestedAt;
0 ignored issues
show
Documentation Bug introduced by
It seems like $event->registrationRequestedAt of type object<Surfnet\Stepup\DateTime\DateTime> is incompatible with the declared type object<DateTime> of property $registrationRequestedAt.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
174
        $secondFactor->registrationCode = $event->registrationCode;
175
176
        $this->verifiedRepository->save($secondFactor);
177
    }
178
179 View Code Duplication
    public function applyU2fDevicePossessionProvenEvent(U2fDevicePossessionProvenEvent $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...
180
    {
181
        $secondFactor = new UnverifiedSecondFactor();
182
        $secondFactor->id = $event->secondFactorId->getSecondFactorId();
183
        $secondFactor->identityId = $event->identityId->getIdentityId();
184
        $secondFactor->type = 'u2f';
185
        $secondFactor->secondFactorIdentifier = $event->keyHandle->getValue();
186
        $secondFactor->verificationNonce = $event->emailVerificationNonce;
187
188
        $this->unverifiedRepository->save($secondFactor);
189
    }
190
191 View Code Duplication
    public function applyU2fDevicePossessionProvenAndVerifiedEvent(U2fDevicePossessionProvenAndVerifiedEvent $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...
192
    {
193
        $secondFactor = new VerifiedSecondFactor();
194
        $secondFactor->id = $event->secondFactorId->getSecondFactorId();
195
        $secondFactor->identityId = $event->identityId->getIdentityId();
196
        $secondFactor->institution = $event->identityInstitution->getInstitution();
197
        $secondFactor->type = 'u2f';
198
        $secondFactor->secondFactorIdentifier = $event->keyHandle->getValue();
199
        $secondFactor->commonName = $event->commonName;
0 ignored issues
show
Documentation Bug introduced by
It seems like $event->commonName of type object<Surfnet\Stepup\Identity\Value\CommonName> is incompatible with the declared type string of property $commonName.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
200
        $secondFactor->registrationRequestedAt = $event->registrationRequestedAt;
0 ignored issues
show
Documentation Bug introduced by
It seems like $event->registrationRequestedAt of type object<Surfnet\Stepup\DateTime\DateTime> is incompatible with the declared type object<DateTime> of property $registrationRequestedAt.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
201
        $secondFactor->registrationCode = $event->registrationCode;
202
203
        $this->verifiedRepository->save($secondFactor);
204
    }
205
206
    public function applyEmailVerifiedEvent(EmailVerifiedEvent $event)
207
    {
208
        $unverified = $this->unverifiedRepository->find($event->secondFactorId->getSecondFactorId());
209
210
        $verified = new VerifiedSecondFactor();
211
        $verified->id = $event->secondFactorId->getSecondFactorId();
212
        $verified->identityId = $event->identityId->getIdentityId();
213
        $verified->institution = $event->identityInstitution->getInstitution();
214
        $verified->commonName = $event->commonName->getCommonName();
215
        $verified->type = $event->secondFactorType->getSecondFactorType();
216
        $verified->secondFactorIdentifier = $unverified->secondFactorIdentifier;
217
        $verified->registrationCode = $event->registrationCode;
218
        $verified->registrationRequestedAt = $event->registrationRequestedAt;
0 ignored issues
show
Documentation Bug introduced by
It seems like $event->registrationRequestedAt of type object<Surfnet\Stepup\DateTime\DateTime> is incompatible with the declared type object<DateTime> of property $registrationRequestedAt.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
219
220
        $this->verifiedRepository->save($verified);
221
        $this->unverifiedRepository->remove($unverified);
222
    }
223
224
    public function applySecondFactorVettedEvent(SecondFactorVettedEvent $event)
225
    {
226
        $verified = $this->verifiedRepository->find($event->secondFactorId->getSecondFactorId());
227
228
        $vetted = new VettedSecondFactor();
229
        $vetted->id = $event->secondFactorId->getSecondFactorId();
230
        $vetted->identityId = $event->identityId->getIdentityId();
231
        $vetted->type = $event->secondFactorType->getSecondFactorType();
232
        $vetted->secondFactorIdentifier = $event->secondFactorIdentifier->getValue();
233
234
        $this->vettedRepository->save($vetted);
235
        $this->verifiedRepository->remove($verified);
0 ignored issues
show
Bug introduced by
It seems like $verified defined by $this->verifiedRepositor...d->getSecondFactorId()) on line 226 can be null; however, Surfnet\StepupMiddleware...torRepository::remove() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
236
    }
237
238
    protected function applyUnverifiedSecondFactorRevokedEvent(UnverifiedSecondFactorRevokedEvent $event)
239
    {
240
        $this->unverifiedRepository->remove($this->unverifiedRepository->find($event->secondFactorId->getSecondFactorId()));
0 ignored issues
show
Bug introduced by
It seems like $this->unverifiedReposit...d->getSecondFactorId()) can be null; however, remove() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 124 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
241
    }
242
243
    protected function applyCompliedWithUnverifiedSecondFactorRevocationEvent(
244
        CompliedWithUnverifiedSecondFactorRevocationEvent $event
245
    ) {
246
        $this->unverifiedRepository->remove($this->unverifiedRepository->find($event->secondFactorId->getSecondFactorId()));
0 ignored issues
show
Bug introduced by
It seems like $this->unverifiedReposit...d->getSecondFactorId()) can be null; however, remove() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 124 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
247
    }
248
249
    protected function applyVerifiedSecondFactorRevokedEvent(VerifiedSecondFactorRevokedEvent $event)
250
    {
251
        $this->verifiedRepository->remove($this->verifiedRepository->find($event->secondFactorId->getSecondFactorId()));
0 ignored issues
show
Bug introduced by
It seems like $this->verifiedRepositor...d->getSecondFactorId()) can be null; however, remove() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
252
    }
253
254
    protected function applyCompliedWithVerifiedSecondFactorRevocationEvent(
255
        CompliedWithVerifiedSecondFactorRevocationEvent $event
256
    ) {
257
        $this->verifiedRepository->remove($this->verifiedRepository->find($event->secondFactorId->getSecondFactorId()));
0 ignored issues
show
Bug introduced by
It seems like $this->verifiedRepositor...d->getSecondFactorId()) can be null; however, remove() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
258
    }
259
260
    protected function applyVettedSecondFactorRevokedEvent(VettedSecondFactorRevokedEvent $event)
261
    {
262
        $this->vettedRepository->remove($this->vettedRepository->find($event->secondFactorId->getSecondFactorId()));
0 ignored issues
show
Bug introduced by
It seems like $this->vettedRepository-...d->getSecondFactorId()) can be null; however, remove() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
263
    }
264
265
    protected function applyCompliedWithVettedSecondFactorRevocationEvent(
266
        CompliedWithVettedSecondFactorRevocationEvent $event
267
    ) {
268
        $this->vettedRepository->remove($this->vettedRepository->find($event->secondFactorId->getSecondFactorId()));
0 ignored issues
show
Bug introduced by
It seems like $this->vettedRepository-...d->getSecondFactorId()) can be null; however, remove() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
269
    }
270
271
    protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event)
272
    {
273
        $this->unverifiedRepository->removeByIdentityId($event->identityId);
274
        $this->verifiedRepository->removeByIdentityId($event->identityId);
275
        $this->vettedRepository->removeByIdentityId($event->identityId);
276
    }
277
}
278