Conditions | 6 |
Paths | 6 |
Total Lines | 84 |
Code Lines | 53 |
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 |
||
134 | public function respondAction() |
||
135 | { |
||
136 | $responseContext = $this->getResponseContext(); |
||
137 | $originalRequestId = $responseContext->getInResponseTo(); |
||
138 | |||
139 | $logger = $this->get('surfnet_saml.logger')->forAuthentication($originalRequestId); |
||
140 | |||
141 | if (!$this->getParameter('second_factor_only')) { |
||
142 | $logger->notice(sprintf( |
||
143 | 'Access to %s denied, second_factor_only parameter set to false.', |
||
144 | __METHOD__ |
||
145 | )); |
||
146 | throw $this->createAccessDeniedException('Second Factor Only feature disabled'); |
||
147 | } |
||
148 | |||
149 | $logger->notice('Creating second-factor-only Response'); |
||
150 | |||
151 | $selectedSecondFactorUuid = $this->getResponseContext()->getSelectedSecondFactor(); |
||
152 | if (!$selectedSecondFactorUuid) { |
||
153 | $logger->error( |
||
154 | 'Cannot verify possession of an unknown second factor' |
||
155 | ); |
||
156 | |||
157 | throw new BadRequestHttpException('Cannot verify possession of an unknown second factor.'); |
||
158 | } |
||
159 | |||
160 | if (!$responseContext->isSecondFactorVerified()) { |
||
161 | $logger->error('Second factor was not verified'); |
||
162 | throw new BadRequestHttpException( |
||
163 | 'Cannot verify possession of an unknown second factor.' |
||
164 | ); |
||
165 | } |
||
166 | |||
167 | $secondFactor = $this->get('gateway.service.second_factor_service') |
||
168 | ->findByUuid($selectedSecondFactorUuid); |
||
169 | $secondFactorTypeService = $this->get('surfnet_stepup.service.second_factor_type'); |
||
170 | $grantedLoa = $this->get('surfnet_stepup.service.loa_resolution') |
||
171 | ->getLoaByLevel($secondFactor->getLoaLevel($secondFactorTypeService)); |
||
172 | |||
173 | /** @var LoaAliasLookupService $loaAliasLookup */ |
||
174 | $loaAliasLookup = $this->get('second_factor_only.loa_alias_lookup'); |
||
175 | $authnContextClassRef = $loaAliasLookup->findAliasByLoa($grantedLoa); |
||
176 | |||
177 | /** @var ResponseFactory $response_factory */ |
||
178 | $responseFactory = $this->get('second_factor_only.saml_response_factory'); |
||
179 | $response = $responseFactory->createSecondFactorOnlyResponse( |
||
180 | $responseContext->getIdentityNameId(), |
||
181 | $responseContext->getServiceProvider(), |
||
182 | $authnContextClassRef |
||
183 | ); |
||
184 | |||
185 | $responseContext->responseSent(); |
||
186 | |||
187 | $logger->notice(sprintf( |
||
188 | 'Responding to request "%s" with newly created response "%s"', |
||
189 | $responseContext->getInResponseTo(), |
||
190 | $response->getId() |
||
191 | )); |
||
192 | |||
193 | $responseRendering = $this->get('second_factor_only.response_rendering'); |
||
194 | |||
195 | $adfsHelper = $this->get('second_factor_only.adfs.response_helper'); |
||
196 | if ($adfsHelper->isAdfsResponse($originalRequestId)) { |
||
197 | $xmlResponse = $responseRendering->getResponseAsXML($response); |
||
198 | try { |
||
199 | $adfsParameters = $adfsHelper->retrieveAdfsParameters(); |
||
200 | } catch (Exception $e) { |
||
201 | $logger->critical(sprintf('Could not process ADFS Response parameters, error: "%s"', $e->getMessage())); |
||
202 | return $this->render('SurfnetStepupGatewayGatewayBundle:Gateway:unrecoverableError.html.twig'); |
||
203 | } |
||
204 | |||
205 | $logger->notice('Sending ACS Response to ADFS plugin'); |
||
206 | return $this->render( |
||
207 | '@SurfnetStepupGatewaySecondFactorOnly/Adfs/consumeAssertion.html.twig', |
||
208 | [ |
||
209 | 'acu' => $adfsParameters->getAssertionConsumerServiceUrl(), |
||
210 | 'samlResponse' => $xmlResponse, |
||
211 | 'context' => $adfsParameters->getContext(), |
||
212 | 'authMethod' => $adfsParameters->getAuthMethod(), |
||
213 | ] |
||
214 | ); |
||
215 | } |
||
216 | return $responseRendering->renderResponse($responseContext, $response); |
||
217 | } |
||
218 | |||
227 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.