| Conditions | 9 |
| Paths | 16 |
| Total Lines | 84 |
| Code Lines | 48 |
| Lines | 10 |
| Ratio | 11.9 % |
| 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 |
||
| 156 | public function verifyIdentityAction(Request $request, $procedureId) |
||
| 157 | { |
||
| 158 | $this->denyAccessUnlessGranted(['ROLE_RA']); |
||
| 159 | |||
| 160 | $logger = $this->get('ra.procedure_logger')->forProcedure($procedureId); |
||
| 161 | $logger->notice('Verify Identity Form requested'); |
||
| 162 | |||
| 163 | View Code Duplication | if (!$this->getVettingService()->hasProcedure($procedureId)) { |
|
| 164 | $logger->notice(sprintf('Vetting procedure "%s" not found', $procedureId)); |
||
| 165 | throw new NotFoundHttpException(sprintf('Vetting procedure "%s" not found', $procedureId)); |
||
| 166 | } |
||
| 167 | |||
| 168 | $command = new VerifyIdentityCommand(); |
||
| 169 | $form = $this->createForm('ra_verify_identity', $command)->handleRequest($request); |
||
| 170 | |||
| 171 | /** @var SubmitButton $cancelButton */ |
||
| 172 | $cancelButton = $form->get('cancel'); |
||
| 173 | View Code Duplication | if ($cancelButton->isClicked()) { |
|
| 174 | $this->getVettingService()->cancelProcedure($procedureId); |
||
| 175 | $this->addFlash('info', $this->get('translator')->trans('ra.vetting.flash.cancelled')); |
||
| 176 | |||
| 177 | return $this->redirectToRoute('ra_vetting_search'); |
||
| 178 | } |
||
| 179 | |||
| 180 | $vettingService = $this->getVettingService(); |
||
| 181 | $commonName = $vettingService->getIdentityCommonName($procedureId); |
||
| 182 | |||
| 183 | $showForm = function ($error = null) use ($form, $commonName) { |
||
| 184 | if ($error) { |
||
| 185 | $form->addError(new FormError($error)); |
||
| 186 | } |
||
| 187 | |||
| 188 | return ['commonName' => $commonName, 'form' => $form->createView()]; |
||
| 189 | }; |
||
| 190 | |||
| 191 | if (!$form->isValid()) { |
||
| 192 | $logger->notice('Verify Identity Form not submitted, displaying form'); |
||
| 193 | |||
| 194 | return $showForm(); |
||
| 195 | } |
||
| 196 | |||
| 197 | try { |
||
| 198 | $vettingService->verifyIdentity($procedureId, $command); |
||
| 199 | } catch (DomainException $e) { |
||
| 200 | $this->get('logger')->error( |
||
| 201 | "RA attempted to verify identity, but the vetting procedure does not allow it", |
||
| 202 | ['exception' => $e, 'procedure' => $procedureId] |
||
| 203 | ); |
||
| 204 | |||
| 205 | return $showForm('ra.verify_identity.identity_verification_failed'); |
||
| 206 | } |
||
| 207 | |||
| 208 | try { |
||
| 209 | $vetting = $vettingService->vet($procedureId); |
||
| 210 | if ($vetting->isSuccessful()) { |
||
| 211 | $logger->notice('Identity Verified, vetting completed'); |
||
| 212 | |||
| 213 | return $this->redirectToRoute('ra_vetting_completed', ['procedureId' => $procedureId]); |
||
| 214 | } |
||
| 215 | |||
| 216 | $logger->error('RA attempted to vet second factor, but the command failed'); |
||
| 217 | |||
| 218 | if (in_array(VettingService::REGISTRATION_CODE_EXPIRED_ERROR, $vetting->getErrors())) { |
||
| 219 | $registrationCodeExpiredError = $this->getTranslator() |
||
| 220 | ->trans( |
||
| 221 | 'ra.verify_identity.registration_code_expired', |
||
| 222 | [ |
||
| 223 | '%self_service_url%' => $this->getParameter('surfnet_stepup_ra.self_service_url'), |
||
| 224 | ] |
||
| 225 | ); |
||
| 226 | |||
| 227 | return $showForm($registrationCodeExpiredError); |
||
| 228 | } |
||
| 229 | |||
| 230 | return $showForm('ra.verify_identity.second_factor_vetting_failed'); |
||
| 231 | } catch (DomainException $e) { |
||
| 232 | $logger->error( |
||
| 233 | "RA attempted to vet second factor, but the vetting procedure didn't allow it", |
||
| 234 | ['exception' => $e] |
||
| 235 | ); |
||
| 236 | |||
| 237 | return $showForm('ra.verify_identity.second_factor_vetting_failed'); |
||
| 238 | } |
||
| 239 | } |
||
| 240 | |||
| 281 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.