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 namespace XoopsModules\Smartobject; |
||
| 27 | class MlObject extends Smartobject\BaseSmartObject |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * SmartMlObject constructor. |
||
| 31 | */ |
||
| 32 | public function __construct() |
||
| 37 | |||
| 38 | /** |
||
| 39 | * If object is not new, change the control of the not-multilanguage fields |
||
| 40 | * |
||
| 41 | * We need to intercept this function from SmartObject because if the object is not new... |
||
| 42 | */ |
||
| 43 | // function getForm() { |
||
| 44 | |||
| 45 | //} |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Strip Multilanguage Fields |
||
| 49 | * |
||
| 50 | * Get rid of all the multilanguage fields to have an object with only global fields. |
||
| 51 | * This will be usefull when creating the ML object for the first time. Then we will be able |
||
| 52 | * to create translations. |
||
| 53 | */ |
||
| 54 | View Code Duplication | public function stripMultilanguageFields() |
|
| 65 | |||
| 66 | View Code Duplication | public function stripNonMultilanguageFields() |
|
| 77 | |||
| 78 | /** |
||
| 79 | * Make non multilanguage fields read only |
||
| 80 | * |
||
| 81 | * This is used when we are creating/editing a translation. |
||
| 82 | * We only want to edit the multilanguag fields, not the global one. |
||
| 83 | */ |
||
| 84 | public function makeNonMLFieldReadOnly() |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @param bool $onlyUrl |
||
| 96 | * @param bool $withimage |
||
| 97 | * @return string |
||
| 98 | */ |
||
| 99 | public function getEditLanguageLink($onlyUrl = false, $withimage = true) |
||
| 105 | } |
||
| 106 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.