| Conditions | 5 |
| Paths | 5 |
| Total Lines | 77 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 40 | public function ssoAction(Request $httpRequest) |
||
| 41 | { |
||
| 42 | $logger = $this->get('logger'); |
||
| 43 | |||
| 44 | if (!$this->getParameter('second_factor_only')) { |
||
| 45 | $logger->notice(sprintf( |
||
| 46 | 'Access to %s denied, second_factor_only parameter set to false.', |
||
| 47 | __METHOD__ |
||
| 48 | )); |
||
| 49 | throw $this->createAccessDeniedException('Second Factor Only feature disabled'); |
||
| 50 | } |
||
| 51 | |||
| 52 | $logger->notice( |
||
| 53 | 'Received AuthnRequest on second-factor-only endpoint, started processing' |
||
| 54 | ); |
||
| 55 | |||
| 56 | /** @var \Surfnet\SamlBundle\Http\RedirectBinding $redirectBinding */ |
||
| 57 | $redirectBinding = $this->get('second_factor_only.http.redirect_binding'); |
||
| 58 | |||
| 59 | try { |
||
| 60 | $originalRequest = $redirectBinding->processSignedRequest($httpRequest); |
||
| 61 | } catch (Exception $e) { |
||
| 62 | $logger->critical(sprintf('Could not process Request, error: "%s"', $e->getMessage())); |
||
| 63 | |||
| 64 | return $this->render( |
||
| 65 | 'SurfnetStepupGatewayGatewayBundle:Gateway:unrecoverableError.html.twig' |
||
| 66 | ); |
||
| 67 | } |
||
| 68 | |||
| 69 | $originalRequestId = $originalRequest->getRequestId(); |
||
| 70 | $logger = $this->get('surfnet_saml.logger')->forAuthentication($originalRequestId); |
||
| 71 | $logger->notice(sprintf( |
||
| 72 | 'AuthnRequest processing complete, received AuthnRequest from "%s", request ID: "%s"', |
||
| 73 | $originalRequest->getServiceProvider(), |
||
| 74 | $originalRequest->getRequestId() |
||
| 75 | )); |
||
| 76 | |||
| 77 | $stateHandler = $this->get('gateway.proxy.state_handler'); |
||
| 78 | |||
| 79 | $stateHandler |
||
| 80 | ->setRequestId($originalRequestId) |
||
| 81 | ->setRequestServiceProvider($originalRequest->getServiceProvider()) |
||
| 82 | ->setRelayState($httpRequest->get(AuthnRequest::PARAMETER_RELAY_STATE, '')) |
||
| 83 | ->setResponseAction('SurfnetStepupGatewaySecondFactorOnlyBundle:SecondFactorOnly:respond') |
||
| 84 | ->setResponseContextServiceId(static::RESPONSE_CONTEXT_SERVICE_ID); |
||
| 85 | |||
| 86 | // Check if the NameID is provided and we may use it. |
||
| 87 | $nameId = $originalRequest->getNameId(); |
||
| 88 | if (!$this->get('second_factor_only.validate_nameid')->with($logger)->validate($originalRequest->getServiceProvider(), $nameId)) { |
||
|
|
|||
| 89 | /** @var \Surfnet\StepupGateway\GatewayBundle\Service\ResponseRenderingService $responseRendering */ |
||
| 90 | $responseRendering = $this->get('second_factor_only.response_rendering'); |
||
| 91 | return $responseRendering->renderRequesterFailureResponse( |
||
| 92 | $this->getResponseContext() |
||
| 93 | ); |
||
| 94 | } |
||
| 95 | $stateHandler->saveIdentityNameId($nameId); |
||
| 96 | |||
| 97 | // Check if the requested Loa is provided and supported. |
||
| 98 | $loaId = $this->get('second_factor_only.loa_resolution')->with($logger)->resolve( |
||
| 99 | $originalRequest->getAuthenticationContextClassRef() |
||
| 100 | ); |
||
| 101 | if (empty($loaId)) { |
||
| 102 | /** @var \Surfnet\StepupGateway\GatewayBundle\Service\ResponseRenderingService $responseRendering */ |
||
| 103 | $responseRendering = $this->get('second_factor_only.response_rendering'); |
||
| 104 | return $responseRendering->renderRequesterFailureResponse( |
||
| 105 | $this->getResponseContext() |
||
| 106 | ); |
||
| 107 | } |
||
| 108 | $stateHandler->setRequiredLoaIdentifier($loaId); |
||
| 109 | |||
| 110 | $logger->notice( |
||
| 111 | 'Forwarding to second factor controller for loa determination and handling' |
||
| 112 | ); |
||
| 113 | return $this->forward( |
||
| 114 | 'SurfnetStepupGatewayGatewayBundle:SecondFactor:selectSecondFactorForVerification' |
||
| 115 | ); |
||
| 116 | } |
||
| 117 | |||
| 192 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.