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 |
||
| 20 | class LocaliseViewLanguages extends JViewLegacy |
||
| 21 | { |
||
| 22 | protected $items; |
||
| 23 | |||
| 24 | protected $pagination; |
||
| 25 | |||
| 26 | protected $state; |
||
| 27 | |||
| 28 | protected $form; |
||
| 29 | |||
| 30 | protected $minCmsVersion = '3.8'; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Display the view |
||
| 34 | * |
||
| 35 | * @param string $tpl The name of the template file to parse; automatically searches through the template paths. |
||
| 36 | * |
||
| 37 | * @return void |
||
| 38 | */ |
||
| 39 | public function display($tpl = null) |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Add the page title and toolbar. |
||
| 74 | * |
||
| 75 | * @return void |
||
| 76 | * |
||
| 77 | * @since 1.6 |
||
| 78 | */ |
||
| 79 | protected function addToolbar() |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Returns an array of fields the table can be sorted by |
||
| 105 | * |
||
| 106 | * @return array Array containing the field name to sort by as the key and display text as value |
||
| 107 | * |
||
| 108 | * @since 3.0 |
||
| 109 | */ |
||
| 110 | protected function getSortFields() |
||
| 118 | } |
||
| 119 |
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.