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