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 |
||
15 | class PasswordResetAction extends Action |
||
16 | { |
||
17 | use EventTrait; |
||
18 | |||
19 | /** |
||
20 | * Event is triggered before resetting password. |
||
21 | * Triggered with \yii2mod\user\events\FormEvent. |
||
22 | */ |
||
23 | const EVENT_BEFORE_RESET = 'beforeReset'; |
||
24 | |||
25 | /** |
||
26 | * Event is triggered after resetting password. |
||
27 | * Triggered with \yii2mod\user\events\FormEvent. |
||
28 | */ |
||
29 | const EVENT_AFTER_RESET = 'afterReset'; |
||
30 | |||
31 | /** |
||
32 | * @var string name of the view, which should be rendered |
||
33 | */ |
||
34 | public $view = '@vendor/yii2mod/yii2-user/views/resetPassword'; |
||
35 | |||
36 | /** |
||
37 | * @var string reset password model class |
||
38 | */ |
||
39 | public $modelClass = 'yii2mod\user\models\ResetPasswordForm'; |
||
40 | |||
41 | /** |
||
42 | * @var string message to be set on success |
||
43 | */ |
||
44 | public $successMessage = 'New password was saved.'; |
||
45 | |||
46 | /** |
||
47 | * Reset password for a user. |
||
48 | * |
||
49 | * @param $token |
||
50 | * |
||
51 | * @return string|\yii\web\Response |
||
52 | * |
||
53 | * @throws \yii\web\BadRequestHttpException |
||
54 | */ |
||
55 | public function run($token) |
||
76 | } |
||
77 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.