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 |
||
18 | class Mustache extends \erdiko\core\Controller |
||
19 | { |
||
20 | public function getMustacheTest($name) |
||
24 | |||
25 | public function getMustacheTest2() |
||
29 | |||
30 | /** |
||
31 | * Example playing with mustache templates |
||
32 | * the $string variable would really be a view, but it's good to see here. |
||
33 | */ |
||
34 | public function getMustache() |
||
58 | |||
59 | /** |
||
60 | * Example playing with mustache templates |
||
61 | * the $string variable would really be a view, but it's good to see here. |
||
62 | */ |
||
63 | public function getMustacheview() |
||
76 | |||
77 | /** |
||
78 | * Example playing with mustache templates |
||
79 | * the $string variable would really be a view, but it's good to see here. |
||
80 | */ |
||
81 | View Code Duplication | public function getMustachelayout() |
|
93 | |||
94 | /** |
||
95 | * Homepage Action (index) |
||
96 | */ |
||
97 | public function getIndex() |
||
103 | } |
||
104 |
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.