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 |
||
| 29 | class absences_StatisticsEditor extends Widget_Form |
||
| 30 | {
|
||
| 31 | |||
| 32 | public function __construct() |
||
| 53 | |||
| 54 | |||
| 55 | |||
| 56 | View Code Duplication | protected function addFields() |
|
|
|
|||
| 57 | {
|
||
| 58 | global $babDB; |
||
| 59 | $W = bab_Widgets(); |
||
| 60 | |||
| 61 | require_once dirname(__FILE__).'/organization.class.php'; |
||
| 62 | $resOrganization = new absences_OrganizationIterator(); |
||
| 63 | |||
| 64 | $orgaSelect = $W->Select(); |
||
| 65 | $orgaSelect->addOption('','');
|
||
| 66 | |||
| 67 | foreach ($resOrganization as $organization) {
|
||
| 68 | $orgaSelect->addOption($organization->id, $organization->name); |
||
| 69 | } |
||
| 70 | |||
| 71 | $this->addItem( |
||
| 72 | $W->LabelledWidget( |
||
| 73 | absences_translate('Organization'),
|
||
| 74 | $orgaSelect, |
||
| 75 | 'organization' |
||
| 76 | ) |
||
| 77 | ); |
||
| 78 | |||
| 79 | |||
| 80 | } |
||
| 81 | |||
| 82 | View Code Duplication | protected function addButtons() |
|
| 92 | } |
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.