| Conditions | 7 | 
| Paths | 14 | 
| Total Lines | 88 | 
| Code Lines | 52 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| 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 | ||
| 38 | public function ssoAction(Request $httpRequest) | ||
| 39 |     { | ||
| 40 |         $logger = $this->get('logger'); | ||
| 41 | |||
| 42 |         if (!$this->getParameter('second_factor_only')) { | ||
| 43 |             $logger->notice('Access to ssoAction denied, second_factor_only parameter set to false.'); | ||
| 44 | |||
| 45 |             throw $this->createAccessDeniedException('Second Factor Only feature is disabled'); | ||
| 46 | } | ||
| 47 | |||
| 48 |         $logger->notice('Received AuthnRequest on second-factor-only endpoint, started processing'); | ||
| 49 | |||
| 50 | // ADFS support | ||
| 51 |         $adfsHelper = $this->get('second_factor_only.adfs.request_helper'); | ||
| 52 |         if ($adfsHelper->isAdfsRequest($httpRequest)) { | ||
| 53 |             $logger->notice('Received AuthnRequest from an ADFS'); | ||
| 54 |             try { | ||
| 55 | $httpRequest = $adfsHelper->transformRequest($httpRequest); | ||
| 56 |             } catch (Exception $e) { | ||
| 57 |                 $logger->critical(sprintf('Could not process ADFS Request, error: "%s"', $e->getMessage())); | ||
| 58 |                 return $this->render('SurfnetStepupGatewayGatewayBundle:Gateway:unrecoverableError.html.twig'); | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | /** @var \Surfnet\SamlBundle\Http\RedirectBinding $redirectBinding */ | ||
| 63 |         $bindingFactory = $this->get('second_factor_only.http.binding_factory'); | ||
| 64 | |||
| 65 |         try { | ||
| 66 |             $logger->notice('Determine what type of Binding is used in the Request'); | ||
| 67 | $binding = $bindingFactory->build($httpRequest); | ||
| 68 | $originalRequest = $binding->receiveSignedAuthnRequestFrom($httpRequest); | ||
| 69 |         } catch (Exception $e) { | ||
| 70 |             $logger->critical(sprintf('Could not process Request, error: "%s"', $e->getMessage())); | ||
| 71 | |||
| 72 |             return $this->render('SurfnetStepupGatewayGatewayBundle:Gateway:unrecoverableError.html.twig'); | ||
| 73 | } | ||
| 74 | |||
| 75 | $originalRequestId = $originalRequest->getRequestId(); | ||
| 76 |         $logger = $this->get('surfnet_saml.logger')->forAuthentication($originalRequestId); | ||
| 77 | $logger->notice(sprintf( | ||
| 78 | 'AuthnRequest processing complete, received AuthnRequest from "%s", request ID: "%s"', | ||
| 79 | $originalRequest->getServiceProvider(), | ||
| 80 | $originalRequest->getRequestId() | ||
| 81 | )); | ||
| 82 | |||
| 83 |         $stateHandler = $this->get('gateway.proxy.state_handler'); | ||
| 84 | $stateHandler | ||
| 85 | ->setRequestId($originalRequestId) | ||
| 86 | ->setRequestServiceProvider($originalRequest->getServiceProvider()) | ||
| 87 | ->setRelayState($httpRequest->get(AuthnRequest::PARAMETER_RELAY_STATE, '')) | ||
| 88 |             ->setResponseAction('SurfnetStepupGatewaySecondFactorOnlyBundle:SecondFactorOnly:respond') | ||
| 89 |             ->setResponseContextServiceId('second_factor_only.response_context'); | ||
| 90 | |||
| 91 | // Check if the NameID is provided and we may use it. | ||
| 92 | $nameId = $originalRequest->getNameId(); | ||
| 93 |         $secondFactorOnlyNameIdValidator = $this->get('second_factor_only.validate_nameid')->with($logger); | ||
|  | |||
| 94 | $serviceProviderMayUseSecondFactorOnly = $secondFactorOnlyNameIdValidator->validate( | ||
| 95 | $originalRequest->getServiceProvider(), | ||
| 96 | $nameId | ||
| 97 | ); | ||
| 98 | |||
| 99 |         if (!$serviceProviderMayUseSecondFactorOnly) { | ||
| 100 | /** @var \Surfnet\StepupGateway\GatewayBundle\Service\ResponseRenderingService $responseRendering */ | ||
| 101 |             $responseRendering = $this->get('second_factor_only.response_rendering'); | ||
| 102 | |||
| 103 | return $responseRendering->renderRequesterFailureResponse($this->getResponseContext()); | ||
| 104 | } | ||
| 105 | |||
| 106 | $stateHandler->saveIdentityNameId($nameId); | ||
| 107 | |||
| 108 | // Check if the requested Loa is provided and supported. | ||
| 109 |         $loaId = $this->get('second_factor_only.loa_resolution')->with($logger)->resolve( | ||
| 110 | $originalRequest->getAuthenticationContextClassRef() | ||
| 111 | ); | ||
| 112 | |||
| 113 |         if (empty($loaId)) { | ||
| 114 | /** @var \Surfnet\StepupGateway\GatewayBundle\Service\ResponseRenderingService $responseRendering */ | ||
| 115 |             $responseRendering = $this->get('second_factor_only.response_rendering'); | ||
| 116 | |||
| 117 | return $responseRendering->renderRequesterFailureResponse($this->getResponseContext()); | ||
| 118 | } | ||
| 119 | |||
| 120 | $stateHandler->setRequiredLoaIdentifier($loaId); | ||
| 121 | |||
| 122 |         $logger->notice('Forwarding to second factor controller for loa determination and handling'); | ||
| 123 | |||
| 124 |         return $this->forward('SurfnetStepupGatewayGatewayBundle:SecondFactor:selectSecondFactorForVerification'); | ||
| 125 | } | ||
| 126 | |||
| 224 | 
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.