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