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