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 |
||
26 | View Code Duplication | class LifespansChartModule extends AbstractModule implements ModuleChartInterface { |
|
|
|||
27 | /** |
||
28 | * How should this module be labelled on tabs, menus, etc.? |
||
29 | * |
||
30 | * @return string |
||
31 | */ |
||
32 | public function getTitle() { |
||
35 | |||
36 | /** |
||
37 | * A sentence describing what this module does. |
||
38 | * |
||
39 | * @return string |
||
40 | */ |
||
41 | public function getDescription() { |
||
44 | |||
45 | /** |
||
46 | * What is the default access level for this module? |
||
47 | * |
||
48 | * Some modules are aimed at admins or managers, and are not generally shown to users. |
||
49 | * |
||
50 | * @return int |
||
51 | */ |
||
52 | public function defaultAccessLevel() { |
||
55 | |||
56 | /** |
||
57 | * Return a menu item for this chart. |
||
58 | * |
||
59 | * @return Menu|null |
||
60 | */ |
||
61 | public function getChartMenu(Individual $individual) { |
||
69 | |||
70 | /** |
||
71 | * Return a menu item for this chart - for use in individual boxes. |
||
72 | * |
||
73 | * @return Menu|null |
||
74 | */ |
||
75 | public function getBoxChartMenu(Individual $individual) { |
||
78 | } |
||
79 |
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.