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 |
||
8 | abstract class ResetPassword extends \yii\base\model |
||
9 | { |
||
10 | const SCENARIO_INIT = 'init'; |
||
11 | const SCENARIO_RESET = 'reset'; |
||
12 | |||
13 | const EXPIRY_TIME = '+4 hours'; |
||
14 | |||
15 | /** |
||
16 | * The email |
||
17 | * @var string $email |
||
18 | */ |
||
19 | public $email; |
||
20 | |||
21 | /** |
||
22 | * The reset token |
||
23 | * @var string $reset_token |
||
24 | */ |
||
25 | public $reset_token; |
||
26 | |||
27 | /** |
||
28 | * The new password |
||
29 | * @var string $password |
||
30 | */ |
||
31 | public $password; |
||
32 | |||
33 | /** |
||
34 | * The new password (again) |
||
35 | * @var string $password_verify |
||
36 | */ |
||
37 | public $password_verify; |
||
38 | |||
39 | /** |
||
40 | * The user's current password |
||
41 | * @var string $password_current |
||
42 | */ |
||
43 | public $password_current; |
||
44 | |||
45 | /** |
||
46 | * The user associated to the email |
||
47 | * @var User $user |
||
48 | */ |
||
49 | private $user = null; |
||
50 | |||
51 | /** |
||
52 | * Validation scenarios |
||
53 | * @return array |
||
54 | */ |
||
55 | public function scenarios() |
||
62 | |||
63 | /** |
||
64 | * Validation rules |
||
65 | * @return array |
||
66 | */ |
||
67 | public function rules() |
||
81 | |||
82 | /** |
||
83 | * Validates the user's current password |
||
84 | * @inheritdoc |
||
85 | */ |
||
86 | public function validatePassword($attributes, $params) |
||
94 | |||
95 | /** |
||
96 | * Validates the users email |
||
97 | * @inheritdoc |
||
98 | */ |
||
99 | public function validateUser($attributes, $params) |
||
109 | |||
110 | /** |
||
111 | * Reset token validator |
||
112 | * @inheritdoc |
||
113 | */ |
||
114 | View Code Duplication | public function validateResetToken($attributes, $params) |
|
134 | |||
135 | /** |
||
136 | * Sets the user object |
||
137 | * @param User $user |
||
138 | */ |
||
139 | public function setUser($user) |
||
144 | |||
145 | /** |
||
146 | * Changes the password for the user |
||
147 | * @return boolean |
||
148 | */ |
||
149 | public function reset() |
||
172 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.