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