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 |
||
9 | class ScaffoldController extends AdminController |
||
10 | { |
||
11 | /** @var string Carpeta en views/_shared/scaffolds/ */ |
||
12 | public $scaffold = 'kumbia'; |
||
13 | /** @var string Nombre del modelo en CamelCase */ |
||
14 | public $model = ''; |
||
15 | |||
16 | /** |
||
17 | * Resultados paginados |
||
18 | */ |
||
19 | public function index($page = 1) |
||
23 | |||
24 | /** |
||
25 | * Crea un Registro |
||
26 | */ |
||
27 | public function crear() |
||
44 | |||
45 | /** |
||
46 | * Edita un Registro |
||
47 | */ |
||
48 | public function editar($id) |
||
67 | |||
68 | /** |
||
69 | * Borra un Registro |
||
70 | */ |
||
71 | public function borrar($id) |
||
79 | |||
80 | /** |
||
81 | * Ver un Registro |
||
82 | */ |
||
83 | public function ver($id) |
||
87 | } |
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.