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