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 |
||
14 | class TwoFactorAuthenticationController extends Controller implements TwoFactorAuthenticationInterface |
||
15 | { |
||
16 | use AuthenticatesUsersWith2FA; |
||
17 | |||
18 | /** |
||
19 | * User Model. |
||
20 | */ |
||
21 | protected $TwoFAModel; |
||
22 | |||
23 | /** |
||
24 | * Assigns $usersModel Property a Model instance. |
||
25 | * Set authenticated users data to $user Property. |
||
26 | */ |
||
27 | public function __construct() |
||
37 | |||
38 | /** |
||
39 | * Setup two factor authentication. |
||
40 | * |
||
41 | * @param \Illuminate\Http\Request |
||
42 | * @param \Illuminate\Http\Response |
||
43 | * |
||
44 | * @throws \Thecodework\TwoFactorAuthentications\Exceptions\TwoFactorAuthenticationExceptions |
||
45 | * |
||
46 | * @return mixed |
||
47 | */ |
||
48 | public function setupTwoFactorAuthentication(Request $request) |
||
68 | |||
69 | /** |
||
70 | * Disable 2FA. |
||
71 | * |
||
72 | * @param \Illuminate\Http\Request |
||
73 | * |
||
74 | * @return mixed |
||
75 | */ |
||
76 | View Code Duplication | public function enableTwoFactorAuthentication(Request $request) |
|
93 | |||
94 | /** |
||
95 | * Enable 2FA. |
||
96 | * |
||
97 | * @param \Illuminate\Http\Request |
||
98 | * |
||
99 | * @return mixed |
||
100 | */ |
||
101 | View Code Duplication | public function disableTwoFactorAuthentication(Request $request) |
|
119 | |||
120 | /** |
||
121 | * Verify Two Factor Authentication. |
||
122 | * |
||
123 | * @param \Illuminate\Http\Request $request |
||
124 | */ |
||
125 | public function verifyTwoFactorAuthentication(Request $request) |
||
140 | |||
141 | /** |
||
142 | * Encode Random String to 32 Base Transfer Encoding. |
||
143 | * |
||
144 | * @param int $length Length of the encoded string. |
||
145 | * |
||
146 | * @return string |
||
147 | */ |
||
148 | private function base32EncodedString(): |
||
153 | |||
154 | /** |
||
155 | * Update User data with 2FA generated Key. |
||
156 | * |
||
157 | * @return void |
||
158 | */ |
||
159 | private function updateUserWithProvisionedUri($twoFactorProvisionedUri) |
||
169 | } |
||
170 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.