Conditions | 5 |
Paths | 5 |
Total Lines | 77 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
84 | public function consumeAssertionAction(Request $httpRequest, $provider) |
||
85 | { |
||
86 | $this->assertSecondFactorEnabled($provider); |
||
87 | |||
88 | $provider = $this->getProvider($provider); |
||
89 | |||
90 | $this->get('logger')->notice( |
||
91 | sprintf('Received GSSP "%s" SAMLResponse through Gateway, attempting to process', $provider->getName()) |
||
92 | ); |
||
93 | |||
94 | try { |
||
95 | /** @var \Surfnet\SamlBundle\Http\PostBinding $postBinding */ |
||
96 | $postBinding = $this->get('surfnet_saml.http.post_binding'); |
||
97 | $assertion = $postBinding->processResponse( |
||
98 | $httpRequest, |
||
99 | $provider->getRemoteIdentityProvider(), |
||
100 | $provider->getServiceProvider() |
||
101 | ); |
||
102 | } catch (Exception $exception) { |
||
103 | $provider->getStateHandler()->clear(); |
||
104 | |||
105 | $this->getLogger()->error( |
||
106 | sprintf('Could not process received Response, error: "%s"', $exception->getMessage()) |
||
107 | ); |
||
108 | |||
109 | return $this->renderInitiateForm( |
||
110 | $provider->getName(), |
||
111 | $httpRequest->getLocale(), |
||
112 | ['authenticationFailed' => true] |
||
113 | ); |
||
114 | } |
||
115 | |||
116 | $expectedResponseTo = $provider->getStateHandler()->getRequestId(); |
||
117 | $provider->getStateHandler()->clear(); |
||
118 | |||
119 | if (!InResponseTo::assertEquals($assertion, $expectedResponseTo)) { |
||
120 | $this->getLogger()->critical(sprintf( |
||
121 | 'Received Response with unexpected InResponseTo, %s', |
||
122 | ($expectedResponseTo ? 'expected "' . $expectedResponseTo . '"' : ' no response expected') |
||
123 | )); |
||
124 | |||
125 | return $this->renderInitiateForm( |
||
126 | $provider->getName(), |
||
127 | $httpRequest->getLocale(), |
||
128 | ['authenticationFailed' => true] |
||
129 | ); |
||
130 | } |
||
131 | |||
132 | $this->get('logger')->notice( |
||
133 | sprintf('Processed GSSP "%s" SAMLResponse received through Gateway successfully', $provider->getName()) |
||
134 | ); |
||
135 | |||
136 | /** @var \Surfnet\StepupSelfService\SelfServiceBundle\Service\GssfService $service */ |
||
137 | $service = $this->get('surfnet_stepup_self_service_self_service.service.gssf'); |
||
138 | /** @var \Surfnet\SamlBundle\SAML2\Attribute\AttributeDictionary $attributeDictionary */ |
||
139 | $attributeDictionary = $this->get('surfnet_saml.saml.attribute_dictionary'); |
||
140 | $gssfId = $attributeDictionary->translate($assertion)->getNameID(); |
||
141 | |||
142 | $secondFactorId = $service->provePossession($this->getIdentity()->id, $provider->getName(), $gssfId); |
||
143 | |||
144 | if ($secondFactorId) { |
||
145 | $this->getLogger()->notice('GSSF possession has been proven successfully'); |
||
146 | |||
147 | return $this->redirectToRoute( |
||
148 | 'ss_registration_email_verification_email_sent', |
||
149 | ['secondFactorId' => $secondFactorId] |
||
150 | ); |
||
151 | } |
||
152 | |||
153 | $this->getLogger()->error('Unable to prove GSSF possession'); |
||
154 | |||
155 | return $this->renderInitiateForm( |
||
156 | $provider->getName(), |
||
157 | $httpRequest->getLocale(), |
||
158 | ['proofOfPossessionFailed' => true] |
||
159 | ); |
||
160 | } |
||
161 | |||
237 |
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.