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