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