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