Completed
Push — feature/ra-optional-vetting ( 241f76...b2f623 )
by
unknown
03:37 queued 12s
created

applySecondFactorVettedPossessionSkippedEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Importance

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