Code Duplication    Length = 22-23 lines in 3 locations

src/Surfnet/StepupMiddleware/CommandHandlingBundle/Identity/CommandHandler/IdentityCommandHandler.php 3 locations

@@ 204-225 (lines=22) @@
201
        $this->eventSourcedRepository->save($identity);
202
    }
203
204
    public function handleProveYubikeyPossessionCommand(ProveYubikeyPossessionCommand $command)
205
    {
206
        /** @var IdentityApi $identity */
207
        $identity = $this->eventSourcedRepository->load(new IdentityId($command->identityId));
208
209
        $this->assertSecondFactorIsAllowedFor(new SecondFactorType('yubikey'), $identity->getInstitution());
210
211
        $configurationInstitution = new ConfigurationInstitution(
212
            (string) $identity->getInstitution()
213
        );
214
        $tokenCount = $this->institutionConfigurationOptionsService->getMaxNumberOfTokensFor($configurationInstitution);
215
        $identity->setMaxNumberOfTokens($tokenCount);
216
217
        $identity->provePossessionOfYubikey(
218
            new SecondFactorId($command->secondFactorId),
219
            new YubikeyPublicId($command->yubikeyPublicId),
220
            $this->emailVerificationIsRequired($identity),
221
            $this->configurableSettings->createNewEmailVerificationWindow()
222
        );
223
224
        $this->eventSourcedRepository->save($identity);
225
    }
226
227
    /**
228
     * @param ProvePhonePossessionCommand $command
@@ 230-252 (lines=23) @@
227
    /**
228
     * @param ProvePhonePossessionCommand $command
229
     */
230
    public function handleProvePhonePossessionCommand(ProvePhonePossessionCommand $command)
231
    {
232
        /** @var IdentityApi $identity */
233
        $identity = $this->eventSourcedRepository->load(new IdentityId($command->identityId));
234
235
        $this->assertSecondFactorIsAllowedFor(new SecondFactorType('sms'), $identity->getInstitution());
236
237
        $configurationInstitution = new ConfigurationInstitution(
238
            (string) $identity->getInstitution()
239
        );
240
241
        $tokenCount = $this->institutionConfigurationOptionsService->getMaxNumberOfTokensFor($configurationInstitution);
242
        $identity->setMaxNumberOfTokens($tokenCount);
243
244
        $identity->provePossessionOfPhone(
245
            new SecondFactorId($command->secondFactorId),
246
            new PhoneNumber($command->phoneNumber),
247
            $this->emailVerificationIsRequired($identity),
248
            $this->configurableSettings->createNewEmailVerificationWindow()
249
        );
250
251
        $this->eventSourcedRepository->save($identity);
252
    }
253
254
    /**
255
     * @param ProveGssfPossessionCommand $command
@@ 284-306 (lines=23) @@
281
        $this->eventSourcedRepository->save($identity);
282
    }
283
284
    public function handleProveU2fDevicePossessionCommand(ProveU2fDevicePossessionCommand $command)
285
    {
286
        /** @var IdentityApi $identity */
287
        $identity = $this->eventSourcedRepository->load(new IdentityId($command->identityId));
288
289
        $this->assertSecondFactorIsAllowedFor(new SecondFactorType('u2f'), $identity->getInstitution());
290
291
        $configurationInstitution = new ConfigurationInstitution(
292
            (string) $identity->getInstitution()
293
        );
294
295
        $tokenCount = $this->institutionConfigurationOptionsService->getMaxNumberOfTokensFor($configurationInstitution);
296
        $identity->setMaxNumberOfTokens($tokenCount);
297
298
        $identity->provePossessionOfU2fDevice(
299
            new SecondFactorId($command->secondFactorId),
300
            new U2fKeyHandle($command->keyHandle),
301
            $this->emailVerificationIsRequired($identity),
302
            $this->configurableSettings->createNewEmailVerificationWindow()
303
        );
304
305
        $this->eventSourcedRepository->save($identity);
306
    }
307
308
    /**
309
     * @param VerifyEmailCommand $command