Conditions | 7 |
Paths | 6 |
Total Lines | 51 |
Lines | 13 |
Ratio | 25.49 % |
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 |
||
105 | public function provePossessionAction(Request $request, $procedureId) |
||
106 | { |
||
107 | $this->assertSecondFactorEnabled('sms'); |
||
108 | $this->denyAccessUnlessGranted(['ROLE_RA']); |
||
109 | $logger = $this->get('ra.procedure_logger')->forProcedure($procedureId); |
||
110 | |||
111 | $logger->notice('Received request for Proof of Possession of SMS Second Factor page'); |
||
112 | |||
113 | $command = new VerifyPossessionOfPhoneCommand(); |
||
114 | $form = $this |
||
115 | ->createForm(VerifyPhoneNumberType::class, $command, ['procedureId' => $procedureId]) |
||
116 | ->handleRequest($request); |
||
117 | |||
118 | /** @var SubmitButton $cancelButton */ |
||
119 | $cancelButton = $form->get('cancel'); |
||
120 | View Code Duplication | if ($cancelButton->isClicked()) { |
|
121 | $this->getVettingService()->cancelProcedure($procedureId); |
||
122 | $this->addFlash('info', $this->get('translator')->trans('ra.vetting.flash.cancelled')); |
||
123 | |||
124 | return $this->redirectToRoute('ra_vetting_search'); |
||
125 | } |
||
126 | |||
127 | View Code Duplication | if (!$form->isSubmitted() || !$form->isValid()) { |
|
128 | $logger->notice( |
||
129 | 'SMS OTP was not submitted through form, rendering Proof of Possession of SMS Second Factor page' |
||
130 | ); |
||
131 | |||
132 | return ['form' => $form->createView()]; |
||
133 | } |
||
134 | |||
135 | $logger->notice('SMS OTP has been entered, attempting to verify Proof of Possession'); |
||
136 | $verification = $this->getVettingService()->verifyPhoneNumber($procedureId, $command); |
||
137 | if ($verification->wasSuccessful()) { |
||
138 | $logger->notice('SMS OTP was valid, Proof of Possession given, redirecting to Identity Vetting page'); |
||
139 | |||
140 | return $this->redirectToRoute( |
||
141 | 'ra_vetting_verify_identity', |
||
142 | ['procedureId' => $procedureId] |
||
143 | ); |
||
144 | } elseif ($verification->didOtpExpire()) { |
||
145 | $this->addFlash('error', 'ra.prove_phone_possession.challenge_expired'); |
||
146 | } elseif ($verification->wasAttemptedTooManyTimes()) { |
||
147 | $this->addFlash('error', 'ra.prove_phone_possession.too_many_attempts'); |
||
148 | } else { |
||
149 | $this->addFlash('error', 'ra.prove_phone_possession.challenge_response_incorrect'); |
||
150 | } |
||
151 | |||
152 | $logger->notice('SMS OTP verification failed - Proof of Possession denied, added error to form'); |
||
153 | |||
154 | return ['form' => $form->createView()]; |
||
155 | } |
||
156 | |||
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.