Completed
Push — feature/verify-email-new-prove... ( 7083d2 )
by
unknown
08:05 queued 04:39
created

applyGssfPossessionProvenAndVerifiedEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
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\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
 */
52
class SecondFactorProjector extends Projector
53
{
54
    /**
55
     * @var \Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\UnverifiedSecondFactorRepository
56
     */
57
    private $unverifiedRepository;
58
59
    /**
60
     * @var \Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\VerifiedSecondFactorRepository
61
     */
62
    private $verifiedRepository;
63
64
    /**
65
     * @var \Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\VettedSecondFactorRepository
66
     */
67
    private $vettedRepository;
68
69
    /**
70
     * @var \Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\IdentityRepository
71
     */
72
    private $identityRepository;
73
74
    public function __construct(
75
        UnverifiedSecondFactorRepository $unverifiedRepository,
76
        VerifiedSecondFactorRepository $verifiedRepository,
77
        VettedSecondFactorRepository $vettedRepository,
78
        IdentityRepository $identityRepository
79
    ) {
80
        $this->unverifiedRepository = $unverifiedRepository;
81
        $this->verifiedRepository = $verifiedRepository;
82
        $this->vettedRepository = $vettedRepository;
83
        $this->identityRepository = $identityRepository;
84
    }
85
86 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...
87
    {
88
        $secondFactor = new VettedSecondFactor();
89
        $secondFactor->id = $event->secondFactorId->getSecondFactorId();
90
        $secondFactor->identityId = $event->identityId->getIdentityId();
91
        $secondFactor->type = 'yubikey';
92
        $secondFactor->secondFactorIdentifier = $event->yubikeyPublicId->getValue();
93
94
        $this->vettedRepository->save($secondFactor);
95
    }
96
97 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...
98
    {
99
        $secondFactor = new UnverifiedSecondFactor();
100
        $secondFactor->id = $event->secondFactorId->getSecondFactorId();
101
        $secondFactor->identityId = $event->identityId->getIdentityId();
102
        $secondFactor->type = 'yubikey';
103
        $secondFactor->secondFactorIdentifier = $event->yubikeyPublicId->getValue();
104
        $secondFactor->verificationNonce = $event->emailVerificationNonce;
105
106
        $this->unverifiedRepository->save($secondFactor);
107
    }
108
109 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...
110
    {
111
        $secondFactor = new VerifiedSecondFactor();
112
        $secondFactor->id = $event->secondFactorId->getSecondFactorId();
113
        $secondFactor->identityId = $event->identityId->getIdentityId();
114
        $secondFactor->institution = $event->identityInstitution->getInstitution();
115
        $secondFactor->type = 'yubikey';
116
        $secondFactor->secondFactorIdentifier = $event->yubikeyPublicId->getValue();
117
        $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...
118
        $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...
119
        $secondFactor->registrationCode = $event->registrationCode;
120
121
        $this->verifiedRepository->save($secondFactor);
122
    }
123
124 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...
125
    {
126
        $secondFactor = new UnverifiedSecondFactor();
127
        $secondFactor->id = $event->secondFactorId->getSecondFactorId();
128
        $secondFactor->identityId = $event->identityId->getIdentityId();
129
        $secondFactor->type = 'sms';
130
        $secondFactor->secondFactorIdentifier = $event->phoneNumber->getValue();
131
        $secondFactor->verificationNonce = $event->emailVerificationNonce;
132
133
        $this->unverifiedRepository->save($secondFactor);
134
    }
135
136 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...
137
    {
138
        $secondFactor = new VerifiedSecondFactor();
139
        $secondFactor->id = $event->secondFactorId->getSecondFactorId();
140
        $secondFactor->identityId = $event->identityId->getIdentityId();
141
        $secondFactor->institution = $event->identityInstitution->getInstitution();
142
        $secondFactor->type = 'sms';
143
        $secondFactor->secondFactorIdentifier = $event->phoneNumber->getValue();
144
        $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...
145
        $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...
146
        $secondFactor->registrationCode = $event->registrationCode;
147
148
        $this->verifiedRepository->save($secondFactor);
149
    }
150
151 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...
152
    {
153
        $secondFactor = new UnverifiedSecondFactor();
154
        $secondFactor->id = $event->secondFactorId->getSecondFactorId();
155
        $secondFactor->identityId = $event->identityId->getIdentityId();
156
        $secondFactor->type = $event->stepupProvider->getStepupProvider();
157
        $secondFactor->secondFactorIdentifier = $event->gssfId->getValue();
158
        $secondFactor->verificationNonce = $event->emailVerificationNonce;
159
160
        $this->unverifiedRepository->save($secondFactor);
161
    }
162
163 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...
164
    {
165
        $secondFactor = new VerifiedSecondFactor();
166
        $secondFactor->id = $event->secondFactorId->getSecondFactorId();
167
        $secondFactor->identityId = $event->identityId->getIdentityId();
168
        $secondFactor->institution = $event->identityInstitution->getInstitution();
169
        $secondFactor->type = $event->stepupProvider->getStepupProvider();
170
        $secondFactor->secondFactorIdentifier = $event->gssfId->getValue();
171
        $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...
172
        $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...
173
        $secondFactor->registrationCode = $event->registrationCode;
174
175
        $this->verifiedRepository->save($secondFactor);
176
    }
177
178 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...
179
    {
180
        $secondFactor = new UnverifiedSecondFactor();
181
        $secondFactor->id = $event->secondFactorId->getSecondFactorId();
182
        $secondFactor->identityId = $event->identityId->getIdentityId();
183
        $secondFactor->type = 'u2f';
184
        $secondFactor->secondFactorIdentifier = $event->keyHandle->getValue();
185
        $secondFactor->verificationNonce = $event->emailVerificationNonce;
186
187
        $this->unverifiedRepository->save($secondFactor);
188
    }
189
190 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...
191
    {
192
        $secondFactor = new VerifiedSecondFactor();
193
        $secondFactor->id = $event->secondFactorId->getSecondFactorId();
194
        $secondFactor->identityId = $event->identityId->getIdentityId();
195
        $secondFactor->institution = $event->identityInstitution->getInstitution();
196
        $secondFactor->type = 'u2f';
197
        $secondFactor->secondFactorIdentifier = $event->keyHandle->getValue();
198
        $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...
199
        $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...
200
        $secondFactor->registrationCode = $event->registrationCode;
201
202
        $this->verifiedRepository->save($secondFactor);
203
    }
204
205
    public function applyEmailVerifiedEvent(EmailVerifiedEvent $event)
206
    {
207
        $unverified = $this->unverifiedRepository->find($event->secondFactorId->getSecondFactorId());
208
209
        $verified = new VerifiedSecondFactor();
210
        $verified->id = $event->secondFactorId->getSecondFactorId();
211
        $verified->identityId = $event->identityId->getIdentityId();
212
        $verified->institution = $event->identityInstitution->getInstitution();
213
        $verified->commonName = $event->commonName->getCommonName();
214
        $verified->type = $event->secondFactorType->getSecondFactorType();
215
        $verified->secondFactorIdentifier = $unverified->secondFactorIdentifier;
216
        $verified->registrationCode = $event->registrationCode;
217
        $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...
218
219
        $this->verifiedRepository->save($verified);
220
        $this->unverifiedRepository->remove($unverified);
221
    }
222
223
    public function applySecondFactorVettedEvent(SecondFactorVettedEvent $event)
224
    {
225
        $verified = $this->verifiedRepository->find($event->secondFactorId->getSecondFactorId());
226
227
        $vetted = new VettedSecondFactor();
228
        $vetted->id = $event->secondFactorId->getSecondFactorId();
229
        $vetted->identityId = $event->identityId->getIdentityId();
230
        $vetted->type = $event->secondFactorType->getSecondFactorType();
231
        $vetted->secondFactorIdentifier = $event->secondFactorIdentifier->getValue();
232
233
        $this->vettedRepository->save($vetted);
234
        $this->verifiedRepository->remove($verified);
0 ignored issues
show
Bug introduced by
It seems like $verified defined by $this->verifiedRepositor...d->getSecondFactorId()) on line 225 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...
235
    }
236
237
    protected function applyUnverifiedSecondFactorRevokedEvent(UnverifiedSecondFactorRevokedEvent $event)
238
    {
239
        $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...
240
    }
241
242
    protected function applyCompliedWithUnverifiedSecondFactorRevocationEvent(
243
        CompliedWithUnverifiedSecondFactorRevocationEvent $event
244
    ) {
245
        $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...
246
    }
247
248
    protected function applyVerifiedSecondFactorRevokedEvent(VerifiedSecondFactorRevokedEvent $event)
249
    {
250
        $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...
251
    }
252
253
    protected function applyCompliedWithVerifiedSecondFactorRevocationEvent(
254
        CompliedWithVerifiedSecondFactorRevocationEvent $event
255
    ) {
256
        $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...
257
    }
258
259
    protected function applyVettedSecondFactorRevokedEvent(VettedSecondFactorRevokedEvent $event)
260
    {
261
        $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...
262
    }
263
264
    protected function applyCompliedWithVettedSecondFactorRevocationEvent(
265
        CompliedWithVettedSecondFactorRevocationEvent $event
266
    ) {
267
        $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...
268
    }
269
270
    protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event)
271
    {
272
        $this->unverifiedRepository->removeByIdentityId($event->identityId);
273
        $this->verifiedRepository->removeByIdentityId($event->identityId);
274
        $this->vettedRepository->removeByIdentityId($event->identityId);
275
    }
276
}
277