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 |
||
11 | class MyController extends Controller |
||
12 | { |
||
13 | public $layout = '@vendor/zacksleo/yii2-backend/src/views/my/layouts'; |
||
14 | |||
15 | public function behaviors() |
||
30 | |||
31 | /** |
||
32 | * 设置头像 |
||
33 | * @return string|yii\web\Response |
||
34 | */ |
||
35 | View Code Duplication | public function actionAvatar() |
|
47 | |||
48 | /** |
||
49 | * 修改密码 |
||
50 | * @return string|yii\web\Response |
||
51 | */ |
||
52 | public function actionChangePassword() |
||
64 | |||
65 | /** |
||
66 | * 设置个人信息 |
||
67 | * @return string|yii\web\Response |
||
68 | */ |
||
69 | View Code Duplication | public function actionProfile() |
|
81 | } |
||
82 |
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.