Code Duplication    Length = 18-19 lines in 2 locations

src/Surfnet/StepupSelfService/SelfServiceBundle/Service/SecondFactorService.php 2 locations

@@ 280-298 (lines=19) @@
277
     * @param string $verificationNonce
278
     * @return UnverifiedSecondFactor|null
279
     */
280
    public function findUnverifiedByVerificationNonce($identityId, $verificationNonce)
281
    {
282
        $secondFactors = $this->secondFactors->searchUnverified(
283
            (new UnverifiedSecondFactorSearchQuery())
284
                ->setIdentityId($identityId)
285
                ->setVerificationNonce($verificationNonce)
286
        );
287
288
        $elements = $secondFactors->getElements();
289
290
        switch (count($elements)) {
291
            case 0:
292
                return null;
293
            case 1:
294
                return reset($elements);
295
            default:
296
                throw new LogicException('There cannot be more than one unverified second factor with the same nonce');
297
        }
298
    }
299
300
    /**
301
     * @param string $secondFactorId
@@ 305-322 (lines=18) @@
302
     * @param string $identityId
303
     * @return null|string
304
     */
305
    public function getRegistrationCode($secondFactorId, $identityId)
306
    {
307
        $query = (new VerifiedSecondFactorSearchQuery())
308
            ->setIdentityId($identityId)
309
            ->setSecondFactorId($secondFactorId);
310
311
        /** @var VerifiedSecondFactor[] $verifiedSecondFactors */
312
        $verifiedSecondFactors = $this->secondFactors->searchVerified($query)->getElements();
313
314
        switch (count($verifiedSecondFactors)) {
315
            case 0:
316
                return null;
317
            case 1:
318
                return reset($verifiedSecondFactors)->registrationCode;
319
            default:
320
                throw new LogicException('Searching by second factor ID cannot result in multiple results.');
321
        }
322
    }
323
324
    /**
325
     * @param array $allSecondFactors