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 |
||
44 | class VettingController extends Controller |
||
|
|||
45 | { |
||
46 | /** |
||
47 | * @Template |
||
48 | * @param Request $request |
||
49 | * @return array|Response |
||
50 | * |
||
51 | * @SuppressWarnings(PHPMD.CyclomaticComplexity) https://www.pivotaltracker.com/story/show/135045063 |
||
52 | * @SuppressWarnings(PHPMD.NPathComplexity) https://www.pivotaltracker.com/story/show/135045063 |
||
53 | */ |
||
54 | public function startProcedureAction(Request $request) |
||
55 | { |
||
56 | $this->denyAccessUnlessGranted(['ROLE_RA']); |
||
57 | $logger = $this->get('logger'); |
||
58 | $identity = $this->getIdentity(); |
||
59 | |||
60 | $logger->notice('Vetting Procedure Search started'); |
||
61 | |||
62 | $command = new StartVettingProcedureCommand(); |
||
63 | |||
64 | $form = $this->createForm(StartVettingProcedureType::class, $command)->handleRequest($request); |
||
65 | |||
66 | View Code Duplication | if (!$form->isSubmitted() || !$form->isValid()) { |
|
67 | $logger->notice('No search submitted, displaying search by registration code form'); |
||
68 | |||
69 | return ['form' => $form->createView()]; |
||
70 | } |
||
71 | |||
72 | $secondFactor = $this->getSecondFactorService() |
||
73 | ->findVerifiedSecondFactorByRegistrationCode($command->registrationCode, $identity->id); |
||
74 | |||
75 | if ($secondFactor === null) { |
||
76 | $this->addFlash('error', 'ra.form.start_vetting_procedure.unknown_registration_code'); |
||
77 | $logger->notice('Cannot start new vetting procedure, no second factor found'); |
||
78 | |||
79 | return ['form' => $form->createView()]; |
||
80 | } |
||
81 | |||
82 | $enabledSecondFactors = $this->container->getParameter('surfnet_stepup_ra.enabled_second_factors'); |
||
83 | if (!in_array($secondFactor->type, $enabledSecondFactors, true)) { |
||
84 | $logger->warning( |
||
85 | sprintf( |
||
86 | 'An RA attempted vetting of disabled second factor "%s" of type "%s"', |
||
87 | $secondFactor->id, |
||
88 | $secondFactor->type |
||
89 | ) |
||
90 | ); |
||
91 | |||
92 | return $this |
||
93 | ->render( |
||
94 | 'SurfnetStepupRaRaBundle:vetting:second_factor_type_disabled.html.twig', |
||
95 | ['secondFactorType' => $secondFactor->type] |
||
96 | ) |
||
97 | ->setStatusCode(Response::HTTP_BAD_REQUEST); |
||
98 | } |
||
99 | |||
100 | /** @var SamlToken $token */ |
||
101 | $token = $this->get('security.token_storage')->getToken(); |
||
102 | $command->authorityId = $this->getIdentity()->id; |
||
103 | $command->authorityLoa = $token->getLoa(); |
||
104 | $command->secondFactor = $secondFactor; |
||
105 | |||
106 | if ($this->getVettingService()->isExpiredRegistrationCode($command)) { |
||
107 | $this->addFlash( |
||
108 | 'error', |
||
109 | $this->getTranslator() |
||
110 | ->trans( |
||
111 | 'ra.verify_identity.registration_code_expired', |
||
112 | [ |
||
113 | '%self_service_url%' => $this->getParameter('surfnet_stepup_ra.self_service_url'), |
||
114 | ] |
||
115 | ) |
||
116 | ); |
||
117 | |||
118 | $logger->notice( |
||
119 | 'Second factor registration code is expired', |
||
120 | ['registration_requested_at' => $secondFactor->registrationRequestedAt->format('Y-m-d')] |
||
121 | ); |
||
122 | |||
123 | return ['form' => $form->createView()]; |
||
124 | } |
||
125 | |||
126 | if (!$this->getVettingService()->isLoaSufficientToStartProcedure($command)) { |
||
127 | $this->addFlash('error', 'ra.form.start_vetting_procedure.loa_insufficient'); |
||
128 | |||
129 | $logger->notice('Cannot start new vetting procedure, Authority LoA is insufficient'); |
||
130 | |||
131 | return ['form' => $form->createView()]; |
||
132 | } |
||
133 | |||
134 | $procedureId = $this->getVettingService()->startProcedure($command); |
||
135 | |||
136 | $this->get('ra.procedure_logger') |
||
137 | ->forProcedure($procedureId) |
||
138 | ->notice(sprintf('Starting new Vetting Procedure for second factor of type "%s"', $secondFactor->type)); |
||
139 | |||
140 | |||
141 | if ($this->getVettingService()->isProvePossessionSkippable($procedureId)) { |
||
142 | $this->get('ra.procedure_logger') |
||
143 | ->forProcedure($procedureId) |
||
144 | ->notice(sprintf('Vetting Procedure for second factor of type "%s" skips the possession proven step', $secondFactor->type)); |
||
145 | |||
146 | return $this->redirectToRoute('ra_vetting_verify_identity', ['procedureId' => $procedureId]); |
||
147 | } |
||
148 | |||
149 | $secondFactorType = new SecondFactorType($secondFactor->type); |
||
150 | if ($secondFactorType->isYubikey()) { |
||
151 | return $this->redirectToRoute('ra_vetting_yubikey_verify', ['procedureId' => $procedureId]); |
||
152 | } elseif ($secondFactorType->isSms()) { |
||
153 | return $this->redirectToRoute('ra_vetting_sms_send_challenge', ['procedureId' => $procedureId]); |
||
154 | } elseif ($this->getSecondFactorTypeService()->isGssf($secondFactorType)) { |
||
155 | return $this->redirectToRoute( |
||
156 | 'ra_vetting_gssf_initiate', |
||
157 | [ |
||
158 | 'procedureId' => $procedureId, |
||
159 | 'provider' => $secondFactor->type |
||
160 | ] |
||
161 | ); |
||
162 | } elseif ($secondFactorType->isU2f()) { |
||
163 | return $this->redirectToRoute('ra_vetting_u2f_start_authentication', ['procedureId' => $procedureId]); |
||
164 | } else { |
||
165 | throw new RuntimeException( |
||
166 | sprintf('RA does not support vetting procedure for second factor type "%s"', $secondFactor->type) |
||
167 | ); |
||
168 | } |
||
169 | } |
||
170 | |||
171 | public function cancelProcedureAction($procedureId) |
||
185 | |||
186 | /** |
||
187 | * @Template |
||
188 | * @param Request $request |
||
189 | * @param string $procedureId |
||
190 | * @return array|Response |
||
191 | * |
||
192 | * @SuppressWarnings(PHPMD.CyclomaticComplexity) |
||
193 | * @SuppressWarnings(PHPMD.NPathComplexity) |
||
194 | */ |
||
195 | public function verifyIdentityAction(Request $request, $procedureId) |
||
279 | |||
280 | /** |
||
281 | * @Template |
||
282 | */ |
||
283 | public function vettingCompletedAction() |
||
287 | |||
288 | /** |
||
289 | * @return SecondFactorService |
||
290 | */ |
||
291 | private function getSecondFactorService() |
||
295 | |||
296 | /** |
||
297 | * @return SecondFactorTypeService |
||
298 | */ |
||
299 | private function getSecondFactorTypeService() |
||
303 | |||
304 | /** |
||
305 | * @return VettingService |
||
306 | */ |
||
307 | private function getVettingService() |
||
311 | |||
312 | /** |
||
313 | * @return \Surfnet\StepupMiddlewareClientBundle\Identity\Dto\Identity |
||
314 | */ |
||
315 | private function getIdentity() |
||
319 | |||
320 | /** |
||
321 | * @return TranslatorInterface |
||
322 | */ |
||
323 | private function getTranslator() |
||
327 | } |
||
328 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.