/**
  * @param string $registrationCode
  * @return null|VerifiedSecondFactor
  */
 public function findVerifiedSecondFactorByRegistrationCode($registrationCode)
 {
     $query = new VerifiedSecondFactorSearchQuery();
     $query->setRegistrationCode($registrationCode);
     try {
         $result = $this->apiSecondFactorService->searchVerified($query);
     } catch (StepupMiddlewareClientException $e) {
         $message = sprintf('Exception when searching verified second factors: "%s"', $e->getMessage());
         $this->logger->critical($message);
         throw new RuntimeException($message, 0, $e);
     }
     /** @var VerifiedSecondFactor[] $elements */
     $elements = $result->getElements();
     $elementCount = count($elements);
     if ($elementCount === 1) {
         return reset($elements);
     }
     if ($elementCount === 0) {
         return null;
     }
     throw new RuntimeException(sprintf('Got an unexpected amount of identities, expected 0 or 1, got "%d"', $elementCount));
 }
 /**
  * @param string $secondFactorId
  * @param string $identityId
  * @return null|string
  */
 public function getRegistrationCode($secondFactorId, $identityId)
 {
     $query = (new VerifiedSecondFactorSearchQuery())->setIdentityId($identityId)->setSecondFactorId($secondFactorId);
     /** @var VerifiedSecondFactor[] $verifiedSecondFactors */
     $verifiedSecondFactors = $this->secondFactors->searchVerified($query)->getElements();
     switch (count($verifiedSecondFactors)) {
         case 0:
             return null;
         case 1:
             return reset($verifiedSecondFactors)->registrationCode;
         default:
             throw new \LogicException('Searching by second factor ID cannot result in multiple results.');
     }
 }