| Conditions | 6 |
| Paths | 9 |
| Total Lines | 59 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 114 | #[Route( |
||
| 115 | path: '/authentication/consume-assertion', |
||
| 116 | name: 'selfservice_serviceprovider_consume_assertion', |
||
| 117 | methods: ['POST'], |
||
| 118 | )] |
||
| 119 | public function consumeAssertion(Request $httpRequest): Response |
||
| 120 | { |
||
| 121 | $session = $this->requestStack->getSession(); |
||
| 122 | if ($session->has(SelfVetController::SELF_VET_SESSION_ID)) { |
||
| 123 | // The test authentication IdP is also used for self vetting, a different session id is |
||
| 124 | // used to mark a self vet command |
||
| 125 | /** @var SelfVetRequestId $selfVetRequestId */ |
||
| 126 | $selfVetRequestId = $session->get(SelfVetController::SELF_VET_SESSION_ID); |
||
| 127 | $secondFactorId = $selfVetRequestId->vettingSecondFactorId(); |
||
| 128 | return $this->forward( |
||
| 129 | 'Surfnet\StepupSelfService\SelfServiceBundle\Controller\SelfVetController::consumeSelfVetAssertion', |
||
| 130 | ['secondFactorId' => $secondFactorId], |
||
| 131 | ); |
||
| 132 | } |
||
| 133 | if ($session->has(RecoveryTokenState::RECOVERY_TOKEN_STEP_UP_REQUEST_ID_IDENTIFIER)) { |
||
| 134 | // The test authentication IdP is also used for self-asserted recovery token |
||
| 135 | // verification a different session id is used to mark the authentication. |
||
| 136 | return $this->forward('Surfnet\StepupSelfService\SelfServiceBundle\Controller\RecoveryTokenController::stepUpConsumeAssertion'); |
||
| 137 | } |
||
| 138 | if (!$session->has('second_factor_test_request_id')) { |
||
| 139 | $this->logger->error( |
||
| 140 | 'Received an authentication response for testing a second factor, but no second factor test response was expected', |
||
| 141 | ); |
||
| 142 | |||
| 143 | throw new AccessDeniedHttpException('Did not expect an authentication response'); |
||
| 144 | } |
||
| 145 | $this->logger->notice('Received an authentication response for testing a second factor'); |
||
| 146 | $initiatedRequestId = $session->get('second_factor_test_request_id'); |
||
| 147 | $samlLogger = $this->samlAuthenticationLogger->forAuthentication($initiatedRequestId); |
||
| 148 | $session->remove('second_factor_test_request_id'); |
||
| 149 | try { |
||
| 150 | $assertion = $this->postBinding->processResponse( |
||
| 151 | $httpRequest, |
||
| 152 | $this->testIdentityProvider, |
||
| 153 | $this->serviceProvider, |
||
| 154 | ); |
||
| 155 | |||
| 156 | if (!InResponseTo::assertEquals($assertion, $initiatedRequestId)) { |
||
| 157 | $samlLogger->error( |
||
| 158 | sprintf( |
||
| 159 | 'Expected a response to the request with ID "%s", but the SAMLResponse was a response to a different request', |
||
| 160 | $initiatedRequestId, |
||
| 161 | ), |
||
| 162 | ); |
||
| 163 | |||
| 164 | throw new AuthenticationException('Unexpected InResponseTo in SAMLResponse'); |
||
| 165 | } |
||
| 166 | |||
| 167 | $this->addFlash('success', 'ss.test_second_factor.verification_successful'); |
||
| 168 | } catch (Exception $e) { |
||
| 169 | $this->logger->info('Receiving the test second factor assertion failed, see context for details', ['context' => $e->getMessage()]); |
||
| 170 | $this->addFlash('error', 'ss.test_second_factor.verification_failed'); |
||
| 171 | } |
||
| 172 | return $this->redirectToRoute('ss_second_factor_list'); |
||
| 173 | } |
||
| 185 |