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 TemplateBackgroundController extends Controller |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * {@inheritdoc} |
||
| 21 | */ |
||
| 22 | public function behaviors() |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Lists all TemplateBackground models. |
||
| 36 | * |
||
| 37 | * @return string render |
||
| 38 | */ |
||
| 39 | public function actionIndex() |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Creates a new TemplateBackground model. |
||
| 58 | * If creation is successful, the browser will be redirected to the 'view' page. |
||
| 59 | * |
||
| 60 | * @return \yii\web\Response|string redirect or render |
||
| 61 | */ |
||
| 62 | public function actionCreate() |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Deletes an existing TemplateBackground model. |
||
| 86 | * If deletion is successful, the browser will be redirected to the 'index' page. |
||
| 87 | * |
||
| 88 | * @param int $id |
||
| 89 | * |
||
| 90 | * @return \yii\web\Response|string |
||
| 91 | */ |
||
| 92 | public function actionDelete($id) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Finds the TemplateBackground model based on its primary key value. |
||
| 105 | * If the model is not found, a 404 HTTP exception will be thrown. |
||
| 106 | * |
||
| 107 | * @param int $id |
||
| 108 | * |
||
| 109 | * @return TemplateBackground the loaded model |
||
| 110 | * |
||
| 111 | * @throws NotFoundHttpException if the model cannot be found |
||
| 112 | */ |
||
| 113 | View Code Duplication | protected function findModel($id) |
|
| 121 | } |
||
| 122 |