| Conditions | 6 |
| Paths | 9 |
| Total Lines | 61 |
| Code Lines | 38 |
| 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 |
||
| 86 | #[Route( |
||
| 87 | path: '/authentication/consume-assertion', |
||
| 88 | name: 'selfservice_serviceprovider_consume_assertion', |
||
| 89 | methods: ['POST'], |
||
| 90 | )] |
||
| 91 | public function consumeAssertion(Request $httpRequest): Response |
||
| 92 | { |
||
| 93 | $logger = $this->get('logger'); |
||
| 94 | |||
| 95 | $session = $this->get('session'); |
||
| 96 | if ($session->has(SelfVetController::SELF_VET_SESSION_ID)) { |
||
| 97 | // The test authentication IdP is also used for self vetting, a different session id is |
||
| 98 | // used to mark a self vet command |
||
| 99 | /** @var SelfVetRequestId $selfVetRequestId */ |
||
| 100 | $selfVetRequestId = $session->get(SelfVetController::SELF_VET_SESSION_ID); |
||
| 101 | $secondFactorId = $selfVetRequestId->vettingSecondFactorId(); |
||
| 102 | return $this->forward( |
||
| 103 | 'SurfnetStepupSelfServiceSelfServiceBundle:SelfVet:consumeSelfVetAssertion', |
||
| 104 | ['secondFactorId' => $secondFactorId] |
||
| 105 | ); |
||
| 106 | } |
||
| 107 | if ($session->has(RecoveryTokenState::RECOVERY_TOKEN_STEP_UP_REQUEST_ID_IDENTIFIER)) { |
||
| 108 | // The test authentication IdP is also used for self-asserted recovery token |
||
| 109 | // verification a different session id is used to mark the authentication. |
||
| 110 | return $this->forward('SurfnetStepupSelfServiceSelfServiceBundle:RecoveryToken:stepUpConsumeAssertion'); |
||
| 111 | } |
||
| 112 | if (!$session->has('second_factor_test_request_id')) { |
||
| 113 | $logger->error( |
||
| 114 | 'Received an authentication response for testing a second factor, but no second factor test response was expected' |
||
| 115 | ); |
||
| 116 | |||
| 117 | throw new AccessDeniedHttpException('Did not expect an authentication response'); |
||
| 118 | } |
||
| 119 | $logger->notice('Received an authentication response for testing a second factor'); |
||
| 120 | $initiatedRequestId = $session->get('second_factor_test_request_id'); |
||
| 121 | $samlLogger = $this->get('surfnet_saml.logger')->forAuthentication($initiatedRequestId); |
||
| 122 | $session->remove('second_factor_test_request_id'); |
||
| 123 | $postBinding = $this->get('surfnet_saml.http.post_binding'); |
||
| 124 | try { |
||
| 125 | $assertion = $postBinding->processResponse( |
||
| 126 | $httpRequest, |
||
| 127 | $this->get('self_service.second_factor_test_idp'), |
||
| 128 | $this->get('surfnet_saml.hosted.service_provider') |
||
| 129 | ); |
||
| 130 | |||
| 131 | if (!InResponseTo::assertEquals($assertion, $initiatedRequestId)) { |
||
| 132 | $samlLogger->error( |
||
| 133 | sprintf( |
||
| 134 | 'Expected a response to the request with ID "%s", but the SAMLResponse was a response to a different request', |
||
| 135 | $initiatedRequestId |
||
| 136 | ) |
||
| 137 | ); |
||
| 138 | |||
| 139 | throw new AuthenticationException('Unexpected InResponseTo in SAMLResponse'); |
||
| 140 | } |
||
| 141 | |||
| 142 | $session->getFlashBag()->add('success', 'ss.test_second_factor.verification_successful'); |
||
| 143 | } catch (Exception) { |
||
| 144 | $session->getFlashBag()->add('error', 'ss.test_second_factor.verification_failed'); |
||
| 145 | } |
||
| 146 | return $this->redirectToRoute('ss_second_factor_list'); |
||
| 147 | } |
||
| 162 |