| Conditions | 9 |
| Paths | 8 |
| Total Lines | 56 |
| Code Lines | 36 |
| 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 | #[Route( |
||
| 85 | path: '/registration/sms/prove-possession', |
||
| 86 | name: 'ss_registration_sms_prove_possession', |
||
| 87 | methods: ['GET','POST'], |
||
| 88 | )] |
||
| 89 | public function provePossession(Request $request): \Symfony\Component\HttpFoundation\RedirectResponse|array |
||
| 90 | { |
||
| 91 | $this->assertSecondFactorEnabled('sms'); |
||
| 92 | |||
| 93 | /** @var SmsSecondFactorService $service */ |
||
| 94 | $service = $this->get('surfnet_stepup_self_service_self_service.service.sms_second_factor'); |
||
| 95 | |||
| 96 | if (!$service->hasSmsVerificationState(SmsSecondFactorServiceInterface::REGISTRATION_SECOND_FACTOR_ID)) { |
||
| 97 | $this->get('session')->getFlashBag()->add('notice', 'ss.registration.sms.alert.no_verification_state'); |
||
| 98 | |||
| 99 | return $this->redirectToRoute('ss_registration_sms_send_challenge'); |
||
| 100 | } |
||
| 101 | |||
| 102 | $identity = $this->getIdentity(); |
||
| 103 | |||
| 104 | $command = new VerifySmsChallengeCommand(); |
||
| 105 | $command->identity = $identity->id; |
||
| 106 | |||
| 107 | $form = $this->createForm(VerifySmsChallengeType::class, $command)->handleRequest($request); |
||
| 108 | |||
| 109 | if ($form->isSubmitted() && $form->isValid()) { |
||
| 110 | $result = $service->provePossession($command); |
||
| 111 | |||
| 112 | if ($result->isSuccessful()) { |
||
| 113 | $service->clearSmsVerificationState(SmsSecondFactorServiceInterface::REGISTRATION_SECOND_FACTOR_ID); |
||
| 114 | |||
| 115 | if ($this->emailVerificationIsRequired()) { |
||
| 116 | return $this->redirectToRoute( |
||
| 117 | 'ss_registration_email_verification_email_sent', |
||
| 118 | ['secondFactorId' => $result->getSecondFactorId()] |
||
| 119 | ); |
||
| 120 | } else { |
||
| 121 | return $this->redirectToRoute( |
||
| 122 | 'ss_second_factor_vetting_types', |
||
| 123 | ['secondFactorId' => $result->getSecondFactorId()] |
||
| 124 | ); |
||
| 125 | } |
||
| 126 | } elseif ($result->wasIncorrectChallengeResponseGiven()) { |
||
| 127 | $this->addFlash('error', 'ss.prove_phone_possession.incorrect_challenge_response'); |
||
| 128 | } elseif ($result->hasChallengeExpired()) { |
||
| 129 | $this->addFlash('error', 'ss.prove_phone_possession.challenge_expired'); |
||
| 130 | } elseif ($result->wereTooManyAttemptsMade()) { |
||
| 131 | $this->addFlash('error', 'ss.prove_phone_possession.too_many_attempts'); |
||
| 132 | } else { |
||
| 133 | $this->addFlash('error', 'ss.prove_phone_possession.proof_of_possession_failed'); |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | return [ |
||
| 138 | 'form' => $form->createView(), |
||
| 139 | 'verifyEmail' => $this->emailVerificationIsRequired(), |
||
| 140 | ]; |
||
| 143 |