Conditions | 4 |
Paths | 4 |
Total Lines | 62 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
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 |
||
120 | public function respondAction() |
||
121 | { |
||
122 | $responseContext = $this->getResponseContext(); |
||
123 | $originalRequestId = $responseContext->getInResponseTo(); |
||
124 | |||
125 | $logger = $this->get('surfnet_saml.logger')->forAuthentication($originalRequestId); |
||
126 | |||
127 | if (!$this->getParameter('second_factor_only')) { |
||
128 | $logger->notice(sprintf( |
||
129 | 'Access to %s denied, second_factor_only parameter set to false.', |
||
130 | __METHOD__ |
||
131 | )); |
||
132 | throw $this->createAccessDeniedException('Second Factor Only feature disabled'); |
||
133 | } |
||
134 | |||
135 | $logger->notice('Creating second-factor-only Response'); |
||
136 | |||
137 | $selectedSecondFactorUuid = $this->getResponseContext()->getSelectedSecondFactor(); |
||
138 | if (!$selectedSecondFactorUuid) { |
||
139 | $logger->error( |
||
140 | 'Cannot verify possession of an unknown second factor' |
||
141 | ); |
||
142 | |||
143 | throw new BadRequestHttpException('Cannot verify possession of an unknown second factor.'); |
||
144 | } |
||
145 | |||
146 | if (!$responseContext->isSecondFactorVerified()) { |
||
147 | $logger->error('Second factor was not verified'); |
||
148 | throw new BadRequestHttpException( |
||
149 | 'Cannot verify possession of an unknown second factor.' |
||
150 | ); |
||
151 | } |
||
152 | |||
153 | $secondFactor = $this->get('gateway.service.second_factor_service') |
||
154 | ->findByUuid($selectedSecondFactorUuid); |
||
155 | |||
156 | $grantedLoa = $this->get('surfnet_stepup.service.loa_resolution') |
||
157 | ->getLoaByLevel($secondFactor->getLoaLevel()); |
||
158 | |||
159 | /** @var LoaAliasLookupService $loaAliasLookup */ |
||
160 | $loaAliasLookup = $this->get('second_factor_only.loa_alias_lookup'); |
||
161 | $authnContextClassRef = $loaAliasLookup->findAliasByLoa($grantedLoa); |
||
162 | |||
163 | /** @var ResponseFactory $response_factory */ |
||
164 | $responseFactory = $this->get('second_factor_only.saml_response_factory'); |
||
165 | $response = $responseFactory->createSecondFactorOnlyResponse( |
||
166 | $responseContext->getIdentityNameId(), |
||
167 | $responseContext->getServiceProvider(), |
||
168 | $authnContextClassRef |
||
169 | ); |
||
170 | |||
171 | $responseContext->responseSent(); |
||
172 | |||
173 | $logger->notice(sprintf( |
||
174 | 'Responding to request "%s" with newly created response "%s"', |
||
175 | $responseContext->getInResponseTo(), |
||
176 | $response->getId() |
||
177 | )); |
||
178 | |||
179 | $responseRendering = $this->get('second_factor_only.response_rendering'); |
||
180 | return $responseRendering->renderResponse($responseContext, $response); |
||
181 | } |
||
182 | |||
191 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.