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