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 |
||
| 19 | class SkinModel extends Model |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * Get available skins. |
||
| 23 | * |
||
| 24 | * @param bool $prepend Prepend a default value |
||
| 25 | * |
||
| 26 | * @return array |
||
| 27 | */ |
||
| 28 | public function getSkins($prepend = false) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Get current skin. |
||
| 51 | * |
||
| 52 | * @return string |
||
| 53 | */ |
||
| 54 | View Code Duplication | public function getCurrentSkin() |
|
| 62 | |||
| 63 | /** |
||
| 64 | * Get available layouts. |
||
| 65 | * |
||
| 66 | * @param bool $prepend Prepend a default value |
||
| 67 | * |
||
| 68 | * @return array |
||
| 69 | */ |
||
| 70 | public function getLayouts($prepend = false) |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Get current layout. |
||
| 87 | * |
||
| 88 | * @return string |
||
| 89 | */ |
||
| 90 | View Code Duplication | public function getCurrentLayout() |
|
| 98 | |||
| 99 | /** |
||
| 100 | * Get available dashboards. |
||
| 101 | * |
||
| 102 | * @param bool $prepend Prepend a default value |
||
| 103 | * |
||
| 104 | * @return array |
||
| 105 | */ |
||
| 106 | public function getDashboards($prepend = false) |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Get current dashboard. |
||
| 126 | * |
||
| 127 | * @return string |
||
| 128 | */ |
||
| 129 | View Code Duplication | public function getCurrentDashboard() |
|
| 137 | } |
||
| 138 |
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.