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