Conditions | 6 |
Paths | 8 |
Total Lines | 95 |
Code Lines | 52 |
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 |
||
53 | public function ssoAction(Request $httpRequest) |
||
54 | { |
||
55 | $logger = $this->get('logger'); |
||
56 | |||
57 | if (!$this->getParameter('second_factor_only')) { |
||
58 | $logger->notice('Access to ssoAction denied, second_factor_only parameter set to false.'); |
||
59 | |||
60 | throw $this->createAccessDeniedException('Second Factor Only feature is disabled'); |
||
61 | } |
||
62 | |||
63 | $logger->notice('Received AuthnRequest on second-factor-only endpoint, started processing'); |
||
64 | |||
65 | /** @var \Surfnet\SamlBundle\Http\RedirectBinding $redirectBinding */ |
||
66 | $bindingFactory = $this->get('second_factor_only.http.binding_factory'); |
||
67 | |||
68 | $logger->notice('Determine what type of Binding is used in the Request'); |
||
69 | $binding = $bindingFactory->build($httpRequest); |
||
70 | |||
71 | /** @var \Surfnet\SamlBundle\SAML2\ReceivedAuthnRequest $originalRequest */ |
||
72 | $originalRequest = $binding->receiveSignedAuthnRequestFrom($httpRequest); |
||
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 | // ADFS support |
||
83 | $adfsHelper = $this->get('second_factor_only.adfs.request_helper'); |
||
84 | if ($adfsHelper->isAdfsRequest($httpRequest)) { |
||
85 | $logger->notice('Received AuthnRequest from an ADFS'); |
||
86 | try { |
||
87 | $httpRequest = $adfsHelper->transformRequest( |
||
88 | $httpRequest, |
||
89 | $originalRequest->getRequestId() |
||
90 | ); |
||
91 | } catch (Exception $e) { |
||
92 | throw new InvalidAdfsRequestException( |
||
93 | sprintf('Could not process ADFS Request, error: "%s"', $e->getMessage()) |
||
94 | ); |
||
95 | } |
||
96 | } |
||
97 | |||
98 | /** @var \Surfnet\StepupGateway\GatewayBundle\Saml\Proxy\ProxyStateHandler $stateHandler */ |
||
99 | $stateHandler = $this->get('gateway.proxy.state_handler'); |
||
100 | |||
101 | // Clear the state of the previous SSO action. Request data of previous |
||
102 | // SSO actions should not have any effect in subsequent SSO actions. |
||
103 | $stateHandler->clear(); |
||
104 | |||
105 | $stateHandler |
||
106 | ->setRequestId($originalRequestId) |
||
107 | ->setRequestServiceProvider($originalRequest->getServiceProvider()) |
||
|
|||
108 | ->setRequestAssertionConsumerServiceUrl($originalRequest->getAssertionConsumerServiceURL()) |
||
109 | ->setRelayState($httpRequest->get(AuthnRequest::PARAMETER_RELAY_STATE, '')) |
||
110 | ->setResponseAction('SurfnetStepupGatewaySecondFactorOnlyBundle:SecondFactorOnly:respond') |
||
111 | ->setResponseContextServiceId('second_factor_only.response_context'); |
||
112 | |||
113 | // Check if the NameID is provided and we may use it. |
||
114 | $nameId = $originalRequest->getNameId(); |
||
115 | $secondFactorOnlyNameIdValidator = $this->get('second_factor_only.validate_nameid')->with($logger); |
||
116 | $serviceProviderMayUseSecondFactorOnly = $secondFactorOnlyNameIdValidator->validate( |
||
117 | $originalRequest->getServiceProvider(), |
||
118 | $nameId |
||
119 | ); |
||
120 | |||
121 | if (!$serviceProviderMayUseSecondFactorOnly) { |
||
122 | /** @var \Surfnet\StepupGateway\GatewayBundle\Service\ResponseRenderingService $responseRendering */ |
||
123 | $responseRendering = $this->get('second_factor_only.response_rendering'); |
||
124 | |||
125 | return $responseRendering->renderRequesterFailureResponse($this->getResponseContext()); |
||
126 | } |
||
127 | |||
128 | $stateHandler->saveIdentityNameId($nameId); |
||
129 | |||
130 | // Check if the requested Loa is provided and supported. |
||
131 | $loaId = $this->get('second_factor_only.loa_resolution')->with($logger)->resolve( |
||
132 | $originalRequest->getAuthenticationContextClassRef() |
||
133 | ); |
||
134 | |||
135 | if (empty($loaId)) { |
||
136 | /** @var \Surfnet\StepupGateway\GatewayBundle\Service\ResponseRenderingService $responseRendering */ |
||
137 | $responseRendering = $this->get('second_factor_only.response_rendering'); |
||
138 | |||
139 | return $responseRendering->renderRequesterFailureResponse($this->getResponseContext()); |
||
140 | } |
||
141 | |||
142 | $stateHandler->setRequiredLoaIdentifier($loaId); |
||
143 | |||
144 | $logger->notice('Forwarding to second factor controller for loa determination and handling'); |
||
145 | |||
146 | return $this->forward('SurfnetStepupGatewayGatewayBundle:SecondFactor:selectSecondFactorForVerification'); |
||
147 | } |
||
148 | |||
250 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.