Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 30 | class U2fController extends SecondFactorController |
||
| 31 | { |
||
| 32 | /** |
||
| 33 | * @Template |
||
| 34 | * @param Request $request |
||
| 35 | * @param string $procedureId |
||
| 36 | * @return array|Response |
||
| 37 | */ |
||
| 38 | public function startAuthenticationAction(Request $request, $procedureId) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @Template |
||
| 57 | * @param Request $request |
||
| 58 | * @param string $procedureId |
||
| 59 | * @return array|Response |
||
| 60 | */ |
||
| 61 | public function authenticationAction(Request $request, $procedureId) |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @Template |
||
| 103 | */ |
||
| 104 | public function provePossessionAction(Request $request, $procedureId) |
||
| 105 | { |
||
| 106 | $this->assertSecondFactorEnabled('u2f'); |
||
| 107 | |||
| 108 | $session = $this->get('ra.session.u2f'); |
||
| 109 | |||
| 110 | /** @var RegisterRequest $signRequest */ |
||
| 111 | $signRequest = $session->get('request'); |
||
| 112 | $signResponse = new SignResponse(); |
||
| 113 | |||
| 114 | $formAction = $this->generateUrl('ra_vetting_u2f_prove_possession', ['procedureId' => $procedureId]); |
||
| 115 | $form = $this |
||
| 116 | ->createForm( |
||
| 117 | VerifyDeviceAuthenticationType::class, |
||
| 118 | $signResponse, |
||
| 119 | ['sign_request' => $signRequest, 'action' => $formAction] |
||
| 120 | ) |
||
| 121 | ->handleRequest($request); |
||
| 122 | |||
| 123 | if (!$form->isSubmitted() || !$form->isValid()) { |
||
| 124 | return $this->render('SurfnetStepupRaRaBundle:Vetting/U2f:authentication.html.twig', [ |
||
| 125 | 'authenticationFailed' => true, |
||
| 126 | 'procedureId' => $procedureId, |
||
| 127 | ]); |
||
| 128 | } |
||
| 129 | |||
| 130 | $service = $this->getVettingService(); |
||
| 131 | $result = $service->verifyU2fAuthentication($procedureId, $signRequest, $signResponse); |
||
| 132 | |||
| 133 | if ($result->wasSuccessful()) { |
||
| 134 | return $this->redirectToRoute('ra_vetting_verify_identity', ['procedureId' => $procedureId]); |
||
| 135 | } elseif ($result->didDeviceReportAnyError()) { |
||
| 136 | $this->addFlash('error', 'ra.vetting.u2f.alert.device_reported_an_error'); |
||
| 137 | return ['authenticationFailed' => true, 'procedureId' => $procedureId]; |
||
| 138 | } else { |
||
| 139 | $this->addFlash('error', 'ra.vetting.u2f.alert.error'); |
||
| 140 | return ['authenticationFailed' => true, 'procedureId' => $procedureId]; |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @return VettingService |
||
| 146 | */ |
||
| 147 | private function getVettingService() |
||
| 151 | } |
||
| 152 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.