| Conditions | 6 |
| Paths | 15 |
| Total Lines | 60 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 62 | #[Route( |
||
| 63 | path: '/second-factor/{secondFactorId}/self-vet-consume-assertion', |
||
| 64 | name: 'ss_second_factor_self_vet_consume_assertion', |
||
| 65 | methods: ['POST'], |
||
| 66 | )] |
||
| 67 | public function consumeSelfVetAssertion(Request $httpRequest, string $secondFactorId): RedirectResponse |
||
| 68 | { |
||
| 69 | $identity = $this->getUser()->getIdentity(); |
||
| 70 | if (!$this->selfVetMarshaller->isAllowed($identity, $secondFactorId)) { |
||
| 71 | throw $this->createNotFoundException(); |
||
| 72 | } |
||
| 73 | |||
| 74 | if (!$this->requestStack->getSession()->has(self::SELF_VET_SESSION_ID)) { |
||
| 75 | $this->logger->error( |
||
| 76 | 'Received an authentication response for self vetting a second factor, but no response was expected' |
||
| 77 | ); |
||
| 78 | throw new AccessDeniedHttpException('Did not expect an authentication response'); |
||
| 79 | } |
||
| 80 | |||
| 81 | $this->logger->notice('Received an authentication response for self vetting a second factor'); |
||
| 82 | |||
| 83 | /** @var SelfVetRequestId $initiatedRequestId */ |
||
| 84 | $initiatedRequestId = $this->requestStack->getSession()->get(self::SELF_VET_SESSION_ID); |
||
| 85 | |||
| 86 | $samlLogger = $this->samlAuthenticationLogger->forAuthentication($initiatedRequestId->requestId()); |
||
| 87 | |||
| 88 | $this->requestStack->getSession()->remove(self::SELF_VET_SESSION_ID); |
||
| 89 | |||
| 90 | try { |
||
| 91 | $assertion = $this->postBinding->processResponse( |
||
| 92 | $httpRequest, |
||
| 93 | $this->identityProvider, |
||
| 94 | $this->serviceProvider |
||
| 95 | ); |
||
| 96 | |||
| 97 | if (!InResponseTo::assertEquals($assertion, $initiatedRequestId->requestId())) { |
||
| 98 | $samlLogger->error( |
||
| 99 | sprintf( |
||
| 100 | 'Expected a response to the request with ID "%s", but the SAMLResponse was a response to a different request', |
||
| 101 | $initiatedRequestId |
||
| 102 | ) |
||
| 103 | ); |
||
| 104 | throw new AuthenticationException('Unexpected InResponseTo in SAMLResponse'); |
||
| 105 | } |
||
| 106 | $candidateSecondFactor = $this->secondFactorService->findOneVerified($secondFactorId); |
||
| 107 | // Proof of possession of higher/equal LoA was successful, now apply the self vet command on Middleware |
||
| 108 | $command = new SelfVetCommand(); |
||
| 109 | $command->identity = $this->getUser()->getIdentity(); |
||
| 110 | $command->secondFactor = $candidateSecondFactor; |
||
| 111 | $command->authoringLoa = $assertion->getAuthnContextClassRef(); |
||
| 112 | |||
| 113 | if ($this->secondFactorService->selfVet($command)) { |
||
| 114 | $this->addFlash('success', 'ss.self_vet.second_factor.alert.successful'); |
||
| 115 | } else { |
||
| 116 | $this->addFlash('error', 'ss.self_vet.second_factor.alert.failed'); |
||
| 117 | } |
||
| 118 | } catch (Exception) { |
||
| 119 | $this->addFlash('error', 'ss.self_vet.second_factor.verification_failed'); |
||
| 120 | } |
||
| 121 | return $this->redirectToRoute('ss_second_factor_list'); |
||
| 122 | } |
||
| 124 |