Conditions | 6 |
Paths | 8 |
Total Lines | 94 |
Code Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 | /** @var \Surfnet\SamlBundle\Http\RedirectBinding $redirectBinding */ |
||
51 | $bindingFactory = $this->get('second_factor_only.http.binding_factory'); |
||
52 | |||
53 | $logger->notice('Determine what type of Binding is used in the Request'); |
||
54 | $binding = $bindingFactory->build($httpRequest); |
||
55 | |||
56 | /** @var \Surfnet\SamlBundle\SAML2\ReceivedAuthnRequest $originalRequest */ |
||
57 | $originalRequest = $binding->receiveSignedAuthnRequestFrom($httpRequest); |
||
58 | |||
59 | $originalRequestId = $originalRequest->getRequestId(); |
||
60 | $logger = $this->get('surfnet_saml.logger')->forAuthentication($originalRequestId); |
||
61 | $logger->notice(sprintf( |
||
62 | 'AuthnRequest processing complete, received AuthnRequest from "%s", request ID: "%s"', |
||
63 | $originalRequest->getServiceProvider(), |
||
64 | $originalRequest->getRequestId() |
||
65 | )); |
||
66 | |||
67 | // ADFS support |
||
68 | $adfsHelper = $this->get('second_factor_only.adfs.request_helper'); |
||
69 | if ($adfsHelper->isAdfsRequest($httpRequest)) { |
||
70 | $logger->notice('Received AuthnRequest from an ADFS'); |
||
71 | try { |
||
72 | $httpRequest = $adfsHelper->transformRequest( |
||
73 | $httpRequest, |
||
74 | $originalRequest->getRequestId(), |
||
75 | $originalRequest->getAssertionConsumerServiceURL() |
||
76 | ); |
||
77 | } catch (Exception $e) { |
||
78 | throw new InvalidAdfsRequestException( |
||
79 | sprintf('Could not process ADFS Request, error: "%s"', $e->getMessage()) |
||
80 | ); |
||
81 | } |
||
82 | } |
||
83 | |||
84 | $stateHandler = $this->get('gateway.proxy.state_handler'); |
||
85 | |||
86 | // Clear the state of the previous SSO action. Request data of previous |
||
87 | // SSO actions should not have any effect in subsequent SSO actions. |
||
88 | $stateHandler->clear(); |
||
89 | |||
90 | $stateHandler |
||
91 | ->setRequestId($originalRequestId) |
||
92 | ->setRequestServiceProvider($originalRequest->getServiceProvider()) |
||
93 | ->setRelayState($httpRequest->get(AuthnRequest::PARAMETER_RELAY_STATE, '')) |
||
94 | ->setResponseAction('SurfnetStepupGatewaySecondFactorOnlyBundle:SecondFactorOnly:respond') |
||
95 | ->setResponseContextServiceId('second_factor_only.response_context'); |
||
96 | |||
97 | // Check if the NameID is provided and we may use it. |
||
98 | $nameId = $originalRequest->getNameId(); |
||
99 | $secondFactorOnlyNameIdValidator = $this->get('second_factor_only.validate_nameid')->with($logger); |
||
|
|||
100 | $serviceProviderMayUseSecondFactorOnly = $secondFactorOnlyNameIdValidator->validate( |
||
101 | $originalRequest->getServiceProvider(), |
||
102 | $nameId |
||
103 | ); |
||
104 | |||
105 | if (!$serviceProviderMayUseSecondFactorOnly) { |
||
106 | /** @var \Surfnet\StepupGateway\GatewayBundle\Service\ResponseRenderingService $responseRendering */ |
||
107 | $responseRendering = $this->get('second_factor_only.response_rendering'); |
||
108 | |||
109 | return $responseRendering->renderRequesterFailureResponse($this->getResponseContext()); |
||
110 | } |
||
111 | |||
112 | $stateHandler->saveIdentityNameId($nameId); |
||
113 | |||
114 | // Check if the requested Loa is provided and supported. |
||
115 | $loaId = $this->get('second_factor_only.loa_resolution')->with($logger)->resolve( |
||
116 | $originalRequest->getAuthenticationContextClassRef() |
||
117 | ); |
||
118 | |||
119 | if (empty($loaId)) { |
||
120 | /** @var \Surfnet\StepupGateway\GatewayBundle\Service\ResponseRenderingService $responseRendering */ |
||
121 | $responseRendering = $this->get('second_factor_only.response_rendering'); |
||
122 | |||
123 | return $responseRendering->renderRequesterFailureResponse($this->getResponseContext()); |
||
124 | } |
||
125 | |||
126 | $stateHandler->setRequiredLoaIdentifier($loaId); |
||
127 | |||
128 | $logger->notice('Forwarding to second factor controller for loa determination and handling'); |
||
129 | |||
130 | return $this->forward('SurfnetStepupGatewayGatewayBundle:SecondFactor:selectSecondFactorForVerification'); |
||
131 | } |
||
132 | |||
225 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.