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