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