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 |
||
17 | class SiteController extends Controller |
||
18 | { |
||
19 | public $layout = '@vendor/zacksleo/yii2-backend/src/views/layouts/layout'; |
||
20 | public $_viewPath = '@vendor/zacksleo/yii2-backend/src/views/site/'; |
||
21 | |||
22 | 4 | View Code Duplication | public function behaviors() |
43 | |||
44 | /** |
||
45 | * @inheritdoc |
||
46 | */ |
||
47 | 4 | public function actions() |
|
56 | |||
57 | 2 | public function actionLogin() |
|
62 | |||
63 | /** |
||
64 | * User logout |
||
65 | */ |
||
66 | public function actionLogout() |
||
67 | { |
||
68 | return Yii::$app->user->logout(); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Requests password reset. |
||
73 | * |
||
74 | * @return mixed |
||
75 | */ |
||
76 | 1 | public function actionRequestpasswordreset() |
|
81 | |||
82 | /** |
||
83 | * Resets password. |
||
84 | * |
||
85 | * @param string $token |
||
86 | * @return mixed |
||
87 | * @throws BadRequestHttpException |
||
88 | */ |
||
89 | 1 | public function actionResetpassword($token) |
|
99 | } |
||
100 |
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.