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 |
||
15 | class ThreemaGateway_Tfa_Reversed extends ThreemaGateway_Tfa_AbstractProvider |
||
16 | { |
||
17 | /** |
||
18 | * Return a description of the 2FA methode. |
||
19 | */ |
||
20 | public function getDescription() |
||
31 | |||
32 | /** |
||
33 | * Called when verifying displaying the choose 2FA mode. |
||
34 | * |
||
35 | * @return bool |
||
36 | */ |
||
37 | View Code Duplication | public function canEnable() |
|
64 | |||
65 | /** |
||
66 | * Called when trying to verify user. Creates secret and registers callback |
||
67 | * request. |
||
68 | * |
||
69 | * @param string $context |
||
70 | * @param array $user |
||
71 | * @param string $userIp |
||
72 | * @param array $providerData |
||
73 | * @return array |
||
74 | */ |
||
75 | public function triggerVerification($context, array $user, $userIp, array &$providerData) |
||
113 | |||
114 | /** |
||
115 | * Called when trying to verify user. Shows code, so user can send it via |
||
116 | * Threema. |
||
117 | * |
||
118 | * @param XenForo_View $view |
||
119 | * @param string $context |
||
120 | * @param array $user |
||
121 | * @param array $providerData |
||
122 | * @param array $triggerData |
||
123 | * @return string HTML code |
||
124 | */ |
||
125 | public function renderVerification(XenForo_View $view, $context, array $user, |
||
150 | |||
151 | /** |
||
152 | * Called when trying to verify user. Checks whether the secret was received |
||
153 | * from the Threema Gateway callback. |
||
154 | * |
||
155 | * @param string $context |
||
156 | * @param array $input |
||
157 | * @param array $user |
||
158 | * @param array $providerData |
||
159 | * |
||
160 | * @return bool |
||
161 | */ |
||
162 | public function verifyFromInput($context, XenForo_Input $input, array $user, array &$providerData) |
||
204 | |||
205 | /** |
||
206 | * Verifies the Treema ID formally after it was entered/changed. |
||
207 | * |
||
208 | * @param XenForo_Input $input |
||
209 | * @param array $user |
||
210 | * @param array $error |
||
211 | * |
||
212 | * @return array |
||
213 | */ |
||
214 | public function verifySetupFromInput(XenForo_Input $input, array $user, &$error) |
||
229 | |||
230 | /** |
||
231 | * Called before the setup verification is shown. |
||
232 | * |
||
233 | * @param array $providerData |
||
234 | * @param array $triggerData |
||
235 | * |
||
236 | * @return bool |
||
237 | */ |
||
238 | protected function initiateSetupData(array &$providerData, array &$triggerData) |
||
242 | |||
243 | /** |
||
244 | * Generates the default provider options at setup time before it is |
||
245 | * displayed to the user. |
||
246 | * |
||
247 | * @return array |
||
248 | */ |
||
249 | protected function generateDefaultData() |
||
255 | |||
256 | /** |
||
257 | * Adjust the view params for managing the 2FA mode, e.g. add special |
||
258 | * params needed by your template. |
||
259 | * |
||
260 | * @param array $viewParams |
||
261 | * @param string $context |
||
262 | * @param array $user |
||
263 | * |
||
264 | * @return array |
||
265 | */ |
||
266 | protected function adjustViewParams(array $viewParams, $context, array $user) |
||
279 | |||
280 | /** |
||
281 | * Resets the provider options to make sure the current 2FA verification |
||
282 | * does not affect the next one. |
||
283 | * |
||
284 | * @param string $context |
||
285 | * @param array $providerData |
||
286 | */ |
||
287 | protected function resetProviderOptionsForTrigger($context, array &$providerData) |
||
293 | } |
||
294 |
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.