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 | class WysiwygController extends BackendController |
||
| 13 | { |
||
| 14 | public function behaviors() |
||
| 34 | |||
| 35 | |||
| 36 | /** |
||
| 37 | * Lists all Wysiwyg models. |
||
| 38 | * @return mixed |
||
| 39 | */ |
||
| 40 | View Code Duplication | public function actionIndex() |
|
| 50 | |||
| 51 | /** |
||
| 52 | * Displays a single Wysiwyg model. |
||
| 53 | * @param integer $id |
||
| 54 | * @return mixed |
||
| 55 | */ |
||
| 56 | public function actionView($id) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Creates a new Wysiwyg model. |
||
| 65 | * If creation is successful, the browser will be redirected to the 'view' page. |
||
| 66 | * @return mixed |
||
| 67 | */ |
||
| 68 | public function actionCreate() |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Updates an existing Wysiwyg model. |
||
| 83 | * If update is successful, the browser will be redirected to the 'view' page. |
||
| 84 | * @param integer $id |
||
| 85 | * @return mixed |
||
| 86 | */ |
||
| 87 | public function actionUpdate($id, $returnUrl = null) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Deletes an existing Wysiwyg model. |
||
| 105 | * If deletion is successful, the browser will be redirected to the 'index' page. |
||
| 106 | * @param integer $id |
||
| 107 | * @return mixed |
||
| 108 | */ |
||
| 109 | public function actionDelete($id) |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Finds the Wysiwyg model based on its primary key value. |
||
| 118 | * If the model is not found, a 404 HTTP exception will be thrown. |
||
| 119 | * @param integer $id |
||
| 120 | * @return Wysiwyg the loaded model |
||
| 121 | * @throws NotFoundHttpException if the model cannot be found |
||
| 122 | */ |
||
| 123 | protected function findModel($id) |
||
| 131 | } |
||
| 132 |
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.