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