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 |
||
19 | class UserLockingModel extends Model |
||
20 | { |
||
21 | /** |
||
22 | * Get the number of failed login for the user. |
||
23 | * |
||
24 | * @param string $username |
||
25 | * |
||
26 | * @return int |
||
27 | */ |
||
28 | public function getFailedLogin($username) |
||
34 | |||
35 | /** |
||
36 | * Reset to 0 the counter of failed login. |
||
37 | * |
||
38 | * @param string $username |
||
39 | * |
||
40 | * @return bool |
||
41 | */ |
||
42 | View Code Duplication | public function resetFailedLogin($username) |
|
51 | |||
52 | /** |
||
53 | * Increment failed login counter. |
||
54 | * |
||
55 | * @param string $username |
||
56 | * |
||
57 | * @return bool |
||
58 | */ |
||
59 | public function incrementFailedLogin($username) |
||
65 | |||
66 | /** |
||
67 | * Check if the account is locked. |
||
68 | * |
||
69 | * @param string $username |
||
70 | * |
||
71 | * @return bool |
||
72 | */ |
||
73 | View Code Duplication | public function isLocked($username) |
|
81 | |||
82 | /** |
||
83 | * Lock the account for the specified duration. |
||
84 | * |
||
85 | * @param string $username Username |
||
86 | * @param int $duration Duration in minutes |
||
87 | * |
||
88 | * @return bool |
||
89 | */ |
||
90 | View Code Duplication | public function lock($username, $duration = 15) |
|
98 | |||
99 | /** |
||
100 | * Return true if the captcha must be shown. |
||
101 | * |
||
102 | * @param string $username |
||
103 | * @param int $tries |
||
104 | * |
||
105 | * @return bool |
||
106 | */ |
||
107 | public function hasCaptcha($username, $tries = BRUTEFORCE_CAPTCHA) |
||
111 | } |
||
112 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.