Conditions | 4 |
Paths | 4 |
Total Lines | 69 |
Code Lines | 42 |
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 |
||
49 | public function ssoAction(Request $httpRequest) |
||
50 | { |
||
51 | $logger = $this->get('logger'); |
||
52 | $logger->notice('Received AuthnRequest, started processing'); |
||
53 | |||
54 | $redirectBinding = $this->get('second_factor_only.http.redirect_binding'); |
||
55 | |||
56 | try { |
||
57 | $originalRequest = $redirectBinding->processRequest($httpRequest); |
||
58 | } catch (Exception $e) { |
||
59 | $logger->critical(sprintf('Could not process Request, error: "%s"', $e->getMessage())); |
||
60 | |||
61 | return $this->render( |
||
62 | 'SurfnetStepupGatewayGatewayBundle:Gateway:unrecoverableError.html.twig' |
||
63 | ); |
||
64 | } |
||
65 | |||
66 | $originalRequestId = $originalRequest->getRequestId(); |
||
67 | $logger = $this->get('surfnet_saml.logger')->forAuthentication($originalRequestId); |
||
68 | $logger->notice(sprintf( |
||
69 | 'AuthnRequest processing complete, received AuthnRequest from "%s", request ID: "%s"', |
||
70 | $originalRequest->getServiceProvider(), |
||
71 | $originalRequest->getRequestId() |
||
72 | )); |
||
73 | |||
74 | $stateHandler = $this->get('gateway.proxy.state_handler'); |
||
75 | |||
76 | $stateHandler |
||
77 | ->setRequestId($originalRequestId) |
||
78 | ->setRequestServiceProvider($originalRequest->getServiceProvider()) |
||
79 | ->setRelayState($httpRequest->get(AuthnRequest::PARAMETER_RELAY_STATE, '')) |
||
80 | ->setResponseAction('SurfnetStepupGatewaySecondFactorOnlyBundle:SecondFactorOnly:respond') |
||
81 | ->setResponseContextServiceId(static::RESPONSE_CONTEXT_SERVICE_ID); |
||
82 | |||
83 | if (!$originalRequest->getNameId()) { |
||
84 | $logger->info( |
||
85 | 'No NameID provided, sending response with status Requester Error' |
||
86 | ); |
||
87 | $responseRendering = $this->get('gateway.service.saml_response'); |
||
88 | return $responseRendering->renderRequesterFailureResponse( |
||
89 | $this->get(static::RESPONSE_CONTEXT_SERVICE_ID) |
||
90 | ); |
||
91 | } |
||
92 | |||
93 | $stateHandler->saveIdentityNameId($originalRequest->getNameId()); |
||
94 | |||
95 | // check if the requested Loa is supported |
||
96 | $authnContextClassRef = $originalRequest->getAuthenticationContextClassRef(); |
||
97 | $failureResponse = $this->verifyAuthnContextClassRef( |
||
98 | $authnContextClassRef, |
||
99 | $logger |
||
100 | ); |
||
101 | |||
102 | if ($failureResponse) { |
||
103 | return $failureResponse; |
||
104 | } |
||
105 | |||
106 | $stateHandler->setRequestAuthnContextClassRef( |
||
107 | $originalRequest->getAuthenticationContextClassRef() |
||
108 | ); |
||
109 | |||
110 | $logger->notice( |
||
111 | 'Forwarding to second factor controller for loa determination and handling' |
||
112 | ); |
||
113 | |||
114 | return $this->forward( |
||
115 | 'SurfnetStepupGatewayGatewayBundle:Selection:selectSecondFactorForVerification' |
||
116 | ); |
||
117 | } |
||
118 | |||
222 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.