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 |
||
21 | View Code Duplication | class Update extends BaseAction |
|
|
|||
22 | { |
||
23 | /** |
||
24 | * @var string the scenario to be assigned to the new model |
||
25 | */ |
||
26 | public $scenario = Model::SCENARIO_DEFAULT; |
||
27 | |||
28 | /** |
||
29 | * @var string name of the view |
||
30 | */ |
||
31 | public $view = 'update'; |
||
32 | |||
33 | /** |
||
34 | * @var string the name variable model in the view template |
||
35 | */ |
||
36 | public $nameVariableModel = 'model'; |
||
37 | |||
38 | /** |
||
39 | * Updates existing record. |
||
40 | * @param mixed $id ID of the model to be updated. |
||
41 | * @return mixed response |
||
42 | */ |
||
43 | 15 | public function run($id) |
|
64 | } |
||
65 |
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.