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