Conditions | 9 |
Paths | 8 |
Total Lines | 54 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
93 | #[Template('registration/sms/prove_possession.html.twig')] |
||
94 | #[Route( |
||
95 | path: '/registration/sms/prove-possession', |
||
96 | name: 'ss_registration_sms_prove_possession', |
||
97 | methods: ['GET','POST'], |
||
98 | )] |
||
99 | public function provePossession(Request $request): RedirectResponse|array |
||
100 | { |
||
101 | $this->assertSecondFactorEnabled('sms'); |
||
102 | |||
103 | if (!$this->smsSecondFactorService->hasSmsVerificationState(SmsSecondFactorServiceInterface::REGISTRATION_SECOND_FACTOR_ID)) { |
||
104 | $this->addFlash('notice', 'ss.registration.sms.alert.no_verification_state'); |
||
105 | |||
106 | return $this->redirectToRoute('ss_registration_sms_send_challenge'); |
||
107 | } |
||
108 | |||
109 | $identity = $this->getIdentity(); |
||
110 | |||
111 | $command = new VerifySmsChallengeCommand(); |
||
112 | $command->identity = $identity->id; |
||
113 | |||
114 | $form = $this->createForm(VerifySmsChallengeType::class, $command)->handleRequest($request); |
||
115 | |||
116 | if ($form->isSubmitted() && $form->isValid()) { |
||
117 | $result = $this->smsSecondFactorService->provePossession($command); |
||
118 | |||
119 | if ($result->isSuccessful()) { |
||
120 | $this->smsSecondFactorService->clearSmsVerificationState(SmsSecondFactorServiceInterface::REGISTRATION_SECOND_FACTOR_ID); |
||
121 | |||
122 | if ($this->emailVerificationIsRequired()) { |
||
123 | return $this->redirectToRoute( |
||
124 | 'ss_registration_email_verification_email_sent', |
||
125 | ['secondFactorId' => $result->getSecondFactorId()] |
||
126 | ); |
||
127 | } else { |
||
128 | return $this->redirectToRoute( |
||
129 | 'ss_second_factor_vetting_types', |
||
130 | ['secondFactorId' => $result->getSecondFactorId()] |
||
131 | ); |
||
132 | } |
||
133 | } elseif ($result->wasIncorrectChallengeResponseGiven()) { |
||
134 | $this->addFlash('error', 'ss.prove_phone_possession.incorrect_challenge_response'); |
||
135 | } elseif ($result->hasChallengeExpired()) { |
||
136 | $this->addFlash('error', 'ss.prove_phone_possession.challenge_expired'); |
||
137 | } elseif ($result->wereTooManyAttemptsMade()) { |
||
138 | $this->addFlash('error', 'ss.prove_phone_possession.too_many_attempts'); |
||
139 | } else { |
||
140 | $this->addFlash('error', 'ss.prove_phone_possession.proof_of_possession_failed'); |
||
141 | } |
||
142 | } |
||
143 | |||
144 | return [ |
||
145 | 'form' => $form->createView(), |
||
146 | 'verifyEmail' => $this->emailVerificationIsRequired(), |
||
147 | ]; |
||
150 |