Conditions | 6 |
Paths | 8 |
Total Lines | 89 |
Code Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 | $stateHandler |
||
86 | ->setRequestId($originalRequestId) |
||
87 | ->setRequestServiceProvider($originalRequest->getServiceProvider()) |
||
88 | ->setRelayState($httpRequest->get(AuthnRequest::PARAMETER_RELAY_STATE, '')) |
||
89 | ->setResponseAction('SurfnetStepupGatewaySecondFactorOnlyBundle:SecondFactorOnly:respond') |
||
90 | ->setResponseContextServiceId('second_factor_only.response_context'); |
||
91 | |||
92 | // Check if the NameID is provided and we may use it. |
||
93 | $nameId = $originalRequest->getNameId(); |
||
94 | $secondFactorOnlyNameIdValidator = $this->get('second_factor_only.validate_nameid')->with($logger); |
||
|
|||
95 | $serviceProviderMayUseSecondFactorOnly = $secondFactorOnlyNameIdValidator->validate( |
||
96 | $originalRequest->getServiceProvider(), |
||
97 | $nameId |
||
98 | ); |
||
99 | |||
100 | if (!$serviceProviderMayUseSecondFactorOnly) { |
||
101 | /** @var \Surfnet\StepupGateway\GatewayBundle\Service\ResponseRenderingService $responseRendering */ |
||
102 | $responseRendering = $this->get('second_factor_only.response_rendering'); |
||
103 | |||
104 | return $responseRendering->renderRequesterFailureResponse($this->getResponseContext()); |
||
105 | } |
||
106 | |||
107 | $stateHandler->saveIdentityNameId($nameId); |
||
108 | |||
109 | // Check if the requested Loa is provided and supported. |
||
110 | $loaId = $this->get('second_factor_only.loa_resolution')->with($logger)->resolve( |
||
111 | $originalRequest->getAuthenticationContextClassRef() |
||
112 | ); |
||
113 | |||
114 | if (empty($loaId)) { |
||
115 | /** @var \Surfnet\StepupGateway\GatewayBundle\Service\ResponseRenderingService $responseRendering */ |
||
116 | $responseRendering = $this->get('second_factor_only.response_rendering'); |
||
117 | |||
118 | return $responseRendering->renderRequesterFailureResponse($this->getResponseContext()); |
||
119 | } |
||
120 | |||
121 | $stateHandler->setRequiredLoaIdentifier($loaId); |
||
122 | |||
123 | $logger->notice('Forwarding to second factor controller for loa determination and handling'); |
||
124 | |||
125 | return $this->forward('SurfnetStepupGatewayGatewayBundle:SecondFactor:selectSecondFactorForVerification'); |
||
126 | } |
||
127 | |||
220 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.