Conditions | 5 |
Paths | 4 |
Total Lines | 55 |
Lines | 4 |
Ratio | 7.27 % |
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 |
||
43 | public function sendChallengeAction(Request $request, $procedureId) |
||
44 | { |
||
45 | $this->assertSecondFactorEnabled('sms'); |
||
46 | |||
47 | $this->denyAccessUnlessGranted(['ROLE_RA']); |
||
48 | |||
49 | $logger = $this->get('ra.procedure_logger')->forProcedure($procedureId); |
||
50 | $logger->notice('Received request for Send SMS Challenge page'); |
||
51 | |||
52 | View Code Duplication | if (!$this->getVettingService()->hasProcedure($procedureId)) { |
|
|
|||
53 | $logger->notice(sprintf('Vetting procedure "%s" not found', $procedureId)); |
||
54 | throw new NotFoundHttpException(sprintf('Vetting procedure "%s" not found', $procedureId)); |
||
55 | } |
||
56 | |||
57 | $command = new SendSmsChallengeCommand(); |
||
58 | $form = $this->createForm(SendSmsChallengeType::class, $command)->handleRequest($request); |
||
59 | |||
60 | $vettingService = $this->getVettingService(); |
||
61 | $phoneNumber = InternationalPhoneNumber::fromStringFormat( |
||
62 | $vettingService->getSecondFactorIdentifier($procedureId) |
||
63 | ); |
||
64 | |||
65 | $otpRequestsRemaining = $vettingService->getSmsOtpRequestsRemainingCount(); |
||
66 | $maximumOtpRequests = $vettingService->getSmsMaximumOtpRequestsCount(); |
||
67 | $viewVariables = ['otpRequestsRemaining' => $otpRequestsRemaining, 'maximumOtpRequests' => $maximumOtpRequests]; |
||
68 | |||
69 | if (!$form->isSubmitted() || !$form->isValid()) { |
||
70 | $logger->notice('Form has not been submitted, not sending SMS, rendering Send SMS Challenge page'); |
||
71 | |||
72 | return array_merge( |
||
73 | $viewVariables, |
||
74 | ['phoneNumber' => $phoneNumber, 'form' => $form->createView()] |
||
75 | ); |
||
76 | } |
||
77 | |||
78 | $logger->notice('Sending of SMS Challenge has been requested, sending OTP via SMS'); |
||
79 | if ($vettingService->sendSmsChallenge($procedureId, $command)) { |
||
80 | $logger->notice( |
||
81 | 'SMS Challenge successfully sent, redirecting to Proof of Possession page to verify challenge' |
||
82 | ); |
||
83 | |||
84 | return $this->redirectToRoute('ra_vetting_sms_prove_possession', ['procedureId' => $procedureId]); |
||
85 | } |
||
86 | |||
87 | $this->addFlash('error', 'ra.sms_send_challenge.send_sms_challenge_failed'); |
||
88 | |||
89 | $logger->notice( |
||
90 | 'SMS Challenge could not be sent, added error to page to notify user and re-rendering send challenge page' |
||
91 | ); |
||
92 | |||
93 | return array_merge( |
||
94 | $viewVariables, |
||
95 | ['phoneNumber' => $phoneNumber, 'form' => $form->createView()] |
||
96 | ); |
||
97 | } |
||
98 | |||
165 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.