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 |
||
12 | abstract class ChangeEmail extends \yii\base\model |
||
13 | { |
||
14 | /** |
||
15 | * The new email to be changed |
||
16 | * @var string $email |
||
17 | */ |
||
18 | public $email; |
||
19 | |||
20 | /** |
||
21 | * The user's current password |
||
22 | * @var string $password |
||
23 | */ |
||
24 | public $password; |
||
25 | |||
26 | /** |
||
27 | * The user whose information we want to change |
||
28 | * @var User $user |
||
29 | */ |
||
30 | private $user; |
||
31 | |||
32 | /** |
||
33 | * Sets the user object |
||
34 | * @param User $user |
||
35 | */ |
||
36 | public function setUser($user) |
||
40 | |||
41 | /** |
||
42 | * Validation rules |
||
43 | * @return array |
||
44 | */ |
||
45 | public function rules() |
||
53 | |||
54 | /** |
||
55 | * Validates the user's current password |
||
56 | * @inheritdoc |
||
57 | */ |
||
58 | View Code Duplication | public function validatePassword($attributes, $params) |
|
66 | |||
67 | /** |
||
68 | * Changes the user's email address |
||
69 | * @return boolean |
||
70 | */ |
||
71 | public function change() |
||
102 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.