Total Complexity | 42 |
Total Lines | 325 |
Duplicated Lines | 0 % |
Coverage | 42.37% |
Changes | 7 | ||
Bugs | 1 | Features | 4 |
Complex classes like AuthControllerVariablesTrait often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AuthControllerVariablesTrait, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
15 | 1 | trait AuthControllerVariablesTrait { |
|
16 | |||
17 | /** |
||
18 | * Override for modifying the noAccess message |
||
19 | * |
||
20 | * @param FlashMessage $fMessage |
||
21 | */ |
||
22 | protected function noAccessMessage(FlashMessage $fMessage) { |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * Override for modifying attempts message |
||
27 | * You can use {_timer} and {_attemptsCount} variables in message content |
||
28 | * |
||
29 | * @param FlashMessage $fMessage |
||
30 | * @param int $attempsCount |
||
31 | */ |
||
32 | 1 | protected function attemptsNumberMessage(FlashMessage $fMessage, $attempsCount) { |
|
33 | 1 | } |
|
34 | |||
35 | /** |
||
36 | * To override for modifying the bad login message |
||
37 | * |
||
38 | * @param FlashMessage $fMessage |
||
39 | */ |
||
40 | 1 | protected function badLoginMessage(FlashMessage $fMessage) { |
|
41 | 1 | } |
|
42 | |||
43 | /** |
||
44 | * To override for modifying the logout message |
||
45 | * |
||
46 | * @param FlashMessage $fMessage |
||
47 | */ |
||
48 | protected function terminateMessage(FlashMessage $fMessage) { |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * To override for modifying the disconnect message |
||
53 | * |
||
54 | * @param FlashMessage $fMessage |
||
55 | */ |
||
56 | protected function disconnectedMessage(FlashMessage $fMessage) { |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * To override for modifying the account creation message. |
||
61 | * |
||
62 | * @param FlashMessage $fMessage |
||
63 | */ |
||
64 | protected function createAccountMessage(FlashMessage $fMessage) { |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * To override for modifying the account creation message information. |
||
69 | * |
||
70 | * @param FlashMessage $fMessage |
||
71 | */ |
||
72 | protected function canCreateAccountMessage(FlashMessage $fMessage) { |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * To override for modifying the error for account creation. |
||
77 | * |
||
78 | * @param FlashMessage $fMessage |
||
79 | */ |
||
80 | protected function createAccountErrorMessage(FlashMessage $fMessage) { |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * To override for modifying the 2FA panel message. |
||
85 | * @param FlashMessage $fMessage |
||
86 | */ |
||
87 | protected function twoFAMessage(FlashMessage $fMessage){ |
||
88 | |||
89 | } |
||
90 | /** |
||
91 | * To override |
||
92 | * @param FlashMessage $fMessage |
||
93 | */ |
||
94 | protected function newTwoFACodeMessage(FlashMessage $fMessage){ |
||
95 | |||
96 | } |
||
97 | |||
98 | /** |
||
99 | * To override for modifying the message displayed if the 2FA code is bad. |
||
100 | * @param FlashMessage $fMessage |
||
101 | */ |
||
102 | protected function twoFABadCodeMessage(FlashMessage $fMessage){ |
||
103 | |||
104 | } |
||
105 | |||
106 | /** |
||
107 | * To override |
||
108 | * Displayed when email is valid. |
||
109 | * @param FlashMessage $fMessage |
||
110 | */ |
||
111 | protected function emailValidationSuccess(FlashMessage $fMessage){ |
||
112 | |||
113 | } |
||
114 | |||
115 | /** |
||
116 | * To override |
||
117 | * Displayed when email is invalid or if an error occurs. |
||
118 | * @param FlashMessage $fMessage |
||
119 | */ |
||
120 | 1 | protected function emailValidationError(FlashMessage $fMessage){ |
|
121 | 1 | ||
122 | } |
||
123 | |||
124 | /** |
||
125 | * To override |
||
126 | * Displayed when an account recovery operation is initiated. |
||
127 | * @param FlashMessage $fMessage |
||
128 | */ |
||
129 | protected function recoveryInitMessage(FlashMessage $fMessage){ |
||
1 ignored issue
–
show
|
|||
130 | |||
131 | } |
||
132 | |||
133 | /** |
||
134 | * To override |
||
135 | * Displayed when email is sent for a recovery account operation. |
||
136 | * @param FlashMessage $fMessage |
||
137 | */ |
||
138 | protected function recoveryEmailSendMessage(FlashMessage $fMessage){ |
||
1 ignored issue
–
show
|
|||
139 | 1 | ||
140 | 1 | } |
|
141 | |||
142 | /** |
||
143 | 1 | * To override |
|
144 | 1 | * Displayed when email is not associated with an existing account. |
|
145 | * @param FlashMessage $fMessage |
||
146 | */ |
||
147 | protected function recoveryEmailErrorMessage(FlashMessage $fMessage){ |
||
1 ignored issue
–
show
|
|||
148 | |||
149 | } |
||
150 | |||
151 | 1 | /** |
|
152 | 1 | * To override |
|
153 | * Displayed when a new password is set with recovery account. |
||
154 | * @param FlashMessage $fMessage |
||
155 | 1 | */ |
|
156 | 1 | protected function resetPasswordSuccessMessage(FlashMessage $fMessage){ |
|
1 ignored issue
–
show
|
|||
157 | |||
158 | } |
||
159 | 1 | ||
160 | 1 | /** |
|
161 | * To override |
||
162 | * Displayed when an error occurs when a new password is set with recovery account. |
||
163 | * @param FlashMessage $fMessage |
||
164 | */ |
||
165 | protected function resetPasswordErrorMessage(FlashMessage $fMessage){ |
||
1 ignored issue
–
show
|
|||
166 | |||
167 | } |
||
168 | |||
169 | /** |
||
170 | * To override |
||
171 | * Displayed when the account recovery link is valid. |
||
172 | * @param FlashMessage $fMessage |
||
173 | 1 | */ |
|
174 | 1 | protected function emailAccountRecoverySuccess(FlashMessage $fMessage){ |
|
1 ignored issue
–
show
|
|||
175 | |||
176 | } |
||
177 | 1 | ||
178 | 1 | /** |
|
179 | * To override |
||
180 | * Displayed when the account recovery link is not valid. |
||
181 | * @param FlashMessage $fMessage |
||
182 | */ |
||
183 | protected function emailAccountRecoveryError(FlashMessage $fMessage){ |
||
1 ignored issue
–
show
|
|||
184 | 1 | ||
185 | 1 | } |
|
186 | |||
187 | /** |
||
188 | * To override |
||
189 | * Returns the maximum number of allowed login attempts. |
||
190 | */ |
||
191 | protected function attemptsNumber() { |
||
192 | return; |
||
193 | } |
||
194 | |||
195 | /** |
||
196 | * To override |
||
197 | * Returns the time before trying to connect again |
||
198 | * Effective only if attemptsNumber return a number. |
||
199 | * |
||
200 | * @return number |
||
201 | */ |
||
202 | 1 | protected function attemptsTimeout() { |
|
203 | 1 | return 3 * 60; |
|
204 | } |
||
205 | |||
206 | /** |
||
207 | * Override to define if user info is displayed as string. |
||
208 | * If set to true, use {{ _infoUser| raw }} in views to display user info. |
||
209 | * Remember to use $this->jquery->renderView instead of $this->loadView for the javascript generation. |
||
210 | */ |
||
211 | public function _displayInfoAsString() { |
||
212 | return false; |
||
213 | } |
||
214 | |||
215 | public function _checkConnectionTimeout() { |
||
216 | return; |
||
217 | } |
||
218 | |||
219 | public function _getLoginInputName() { |
||
220 | return 'email'; |
||
221 | } |
||
222 | |||
223 | protected function loginLabel() { |
||
224 | return \ucfirst ( $this->_getLoginInputName () ); |
||
225 | } |
||
226 | |||
227 | public function _getPasswordInputName() { |
||
228 | return 'password'; |
||
229 | } |
||
230 | |||
231 | protected function passwordLabel() { |
||
232 | return \ucfirst ( $this->_getPasswordInputName () ); |
||
233 | } |
||
234 | |||
235 | protected function passwordConfLabel() { |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * Returns the body selector (jquery selector used for replacing the content of the page). |
||
241 | * default: main .container |
||
242 | * |
||
243 | * @return string |
||
244 | */ |
||
245 | public function _getBodySelector():string { |
||
246 | return 'main .container'; |
||
247 | } |
||
248 | |||
249 | protected function rememberCaption():string { |
||
250 | return 'Remember me'; |
||
251 | } |
||
252 | /** |
||
253 | * Returns true for account creation. |
||
254 | * @return boolean |
||
255 | */ |
||
256 | protected function hasAccountCreation():bool{ |
||
257 | return false; |
||
258 | } |
||
259 | |||
260 | /** |
||
261 | * |
||
262 | * @return bool |
||
263 | */ |
||
264 | protected function hasEmailValidation():bool{ |
||
265 | return false; |
||
266 | } |
||
267 | |||
268 | /** |
||
269 | * @return bool |
||
270 | */ |
||
271 | protected function hasAccountRecovery():bool{ |
||
273 | } |
||
274 | |||
275 | /** |
||
276 | * To override |
||
277 | * Returns true for a two factor authentification for this account. |
||
278 | * @param mixed $accountValue |
||
279 | * @return bool |
||
280 | */ |
||
281 | protected function has2FA($accountValue=null):bool{ |
||
282 | return false; |
||
283 | } |
||
284 | |||
285 | /** |
||
286 | * To override |
||
287 | * Returns the default size for generated tokens. |
||
288 | * @return int |
||
289 | */ |
||
290 | protected function getTokenSize():int{ |
||
291 | return 6; |
||
292 | } |
||
293 | |||
294 | /** |
||
295 | * Generates a new random 2FA code. |
||
296 | * You have to override this basic implementation. |
||
297 | * @return string |
||
298 | * @throws \Exception |
||
299 | */ |
||
300 | protected function generate2FACode():string{ |
||
301 | return \bin2hex ( \random_bytes ($this->getTokenSize())); |
||
302 | } |
||
303 | |||
304 | /** |
||
305 | * Returns the code prefix (which should not be entered by the user). |
||
306 | * @return string |
||
307 | */ |
||
308 | protected function towFACodePrefix():string{ |
||
310 | } |
||
311 | |||
312 | /** |
||
313 | * Returns the default validity duration of a mail validation link. |
||
314 | * @return \DateInterval |
||
315 | */ |
||
316 | protected function emailValidationDuration():\DateInterval{ |
||
317 | return new \DateInterval('PT24H'); |
||
318 | } |
||
319 | |||
320 | /** |
||
321 | * Returns the default validity duration of a generated 2FA code. |
||
322 | * @return \DateInterval |
||
323 | */ |
||
324 | protected function twoFACodeDuration():\DateInterval{ |
||
325 | return new \DateInterval('PT5M'); |
||
326 | } |
||
327 | |||
328 | /** |
||
329 | * @return bool |
||
330 | */ |
||
331 | public function hasRecoveryAccount():bool{ |
||
332 | return false; |
||
333 | } |
||
334 | /** |
||
335 | * Returns the default validity duration for an email account recovery. |
||
336 | * @return \DateInterval |
||
337 | */ |
||
338 | protected function accountRecoveryDuration():\DateInterval{ |
||
340 | } |
||
341 | |||
342 | } |
||
343 | |||
344 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.