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