Code Duplication    Length = 18-19 lines in 2 locations

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

@@ 231-249 (lines=19) @@
228
     * @param string $verificationNonce
229
     * @return UnverifiedSecondFactor|null
230
     */
231
    public function findUnverifiedByVerificationNonce($identityId, $verificationNonce)
232
    {
233
        $secondFactors = $this->secondFactors->searchUnverified(
234
            (new UnverifiedSecondFactorSearchQuery())
235
                ->setIdentityId($identityId)
236
                ->setVerificationNonce($verificationNonce)
237
        );
238
239
        $elements = $secondFactors->getElements();
240
241
        switch (count($elements)) {
242
            case 0:
243
                return null;
244
            case 1:
245
                return reset($elements);
246
            default:
247
                throw new LogicException('There cannot be more than one unverified second factor with the same nonce');
248
        }
249
    }
250
251
    /**
252
     * @param string $secondFactorId
@@ 256-273 (lines=18) @@
253
     * @param string $identityId
254
     * @return null|string
255
     */
256
    public function getRegistrationCode($secondFactorId, $identityId)
257
    {
258
        $query = (new VerifiedSecondFactorSearchQuery())
259
            ->setIdentityId($identityId)
260
            ->setSecondFactorId($secondFactorId);
261
262
        /** @var VerifiedSecondFactor[] $verifiedSecondFactors */
263
        $verifiedSecondFactors = $this->secondFactors->searchVerified($query)->getElements();
264
265
        switch (count($verifiedSecondFactors)) {
266
            case 0:
267
                return null;
268
            case 1:
269
                return reset($verifiedSecondFactors)->registrationCode;
270
            default:
271
                throw new LogicException('Searching by second factor ID cannot result in multiple results.');
272
        }
273
    }
274
}
275