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 |
||
16 | class TwoFactorAuthenticationController extends Controller implements TwoFactorAuthenticationInterface |
||
17 | { |
||
18 | use AuthenticatesUsersWith2FA; |
||
19 | |||
20 | /** |
||
21 | * User Model |
||
22 | */ |
||
23 | protected $userModel; |
||
24 | |||
25 | /** |
||
26 | * Assigns $usersModel Property a Model instance. |
||
27 | */ |
||
28 | public function __construct() |
||
32 | /** |
||
33 | * Setup two factor authentication. |
||
34 | * |
||
35 | * @param \Illuminate\Http\Request |
||
36 | * @param \Illuminate\Http\Response |
||
37 | * @throws \Thecodework\TwoFactorAuthentications\Exceptions\TwoFactorAuthenticationExceptions |
||
38 | */ |
||
39 | public function setupTwoFactorAuthentication(Request $request) |
||
66 | |||
67 | /** |
||
68 | * Disable 2FA. |
||
69 | * |
||
70 | * @param \Illuminate\Http\Request |
||
71 | * |
||
72 | * @return mixed |
||
73 | */ |
||
74 | View Code Duplication | public function enableTwoFactorAuthentication(Request $request) |
|
91 | |||
92 | /** |
||
93 | * Enable 2FA. |
||
94 | * |
||
95 | * @param \Illuminate\Http\Request |
||
96 | * |
||
97 | * @return mixed |
||
98 | */ |
||
99 | View Code Duplication | public function disableTwoFactorAuthentication(Request $request) |
|
117 | |||
118 | /** |
||
119 | * Verify Two Factor Authentication. |
||
120 | * |
||
121 | * @param \Illuminate\Http\Request $request |
||
122 | */ |
||
123 | public function verifyTwoFactorAuthentication(Request $request) |
||
138 | |||
139 | /** |
||
140 | * Encode Random String to 32 Base Transfer Encoding. |
||
141 | * |
||
142 | * @param int $length Length of the encoded string. |
||
143 | * |
||
144 | * @return string |
||
145 | */ |
||
146 | private function base32EncodedString($length = 30): |
||
150 | |||
151 | /** |
||
152 | * Generate a more truly "random" alpha-numeric string. |
||
153 | * |
||
154 | * @param int $length |
||
155 | * |
||
156 | * @return string |
||
157 | */ |
||
158 | private function strRandom($length = 30): |
||
172 | } |
||
173 |