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 |
||
| 27 | class absences_ManagerMenu |
||
| 28 | { |
||
| 29 | protected function category($name) |
||
| 40 | |||
| 41 | protected function category_settings() |
||
| 42 | { |
||
| 43 | $W = bab_Widgets(); |
||
| 44 | $cat = $this->category(absences_translate('Settings')); |
||
| 45 | |||
| 46 | $cat->addItem( |
||
| 47 | $W->Link( |
||
| 48 | $W->Icon(absences_translate("Vacations types"), Func_Icons::ACTIONS_VIEW_LIST_TEXT), |
||
| 49 | absences_addon()->getUrl()."vacadm&idx=lvt" |
||
| 50 | ) |
||
| 51 | ); |
||
| 52 | |||
| 53 | |||
| 54 | $cat->addItem( |
||
| 55 | $W->Link( |
||
| 56 | $W->Icon(absences_translate("Collections"), Func_Icons::ACTIONS_VIEW_LIST_TEXT), |
||
| 57 | absences_addon()->getUrl()."vacadm&idx=lcol" |
||
| 58 | ) |
||
| 59 | ); |
||
| 60 | |||
| 61 | |||
| 62 | $cat->addItem( |
||
| 63 | $W->Link( |
||
| 64 | $W->Icon(absences_translate("Personnel members"), Func_Icons::ACTIONS_USER_GROUP_PROPERTIES), |
||
| 65 | absences_addon()->getUrl()."vacadm&idx=lper" |
||
| 66 | ) |
||
| 67 | ); |
||
| 68 | |||
| 69 | |||
| 70 | $cat->addItem( |
||
| 71 | $W->Link( |
||
| 72 | $W->Icon(absences_translate("Workdays types entitling recovery"), Func_Icons::APPS_PREFERENCES_DATE_TIME_FORMAT), |
||
| 73 | absences_addon()->getUrl()."workperiod_type" |
||
| 74 | ) |
||
| 75 | ); |
||
| 76 | |||
| 77 | |||
| 78 | View Code Duplication | if (absences_getVacationOption('sync_server')) |
|
|
|
|||
| 79 | { |
||
| 80 | $cat->addItem( |
||
| 81 | $W->Link( |
||
| 82 | $W->Icon(absences_translate("Configure the shared vacation rights"), Func_Icons::APPS_PREFERENCES_WEBSERVICES), |
||
| 83 | absences_addon()->getUrl()."sync_server" |
||
| 84 | ) |
||
| 85 | ); |
||
| 86 | } |
||
| 87 | |||
| 88 | View Code Duplication | if (absences_getVacationOption('sync_url')) |
|
| 89 | { |
||
| 90 | $cat->addItem( |
||
| 91 | $W->Link( |
||
| 92 | $W->Icon(absences_translate("Configure the synchronized rights"), Func_Icons::APPS_PREFERENCES_WEBSERVICES), |
||
| 93 | absences_addon()->getUrl()."sync_client" |
||
| 94 | ) |
||
| 95 | ); |
||
| 96 | } |
||
| 97 | |||
| 98 | |||
| 99 | $WorkingHours = bab_functionality::get('WorkingHours'); |
||
| 100 | if ($WorkingHours instanceof Func_WorkingHours_Workschedules) |
||
| 101 | { |
||
| 102 | $cat->addItem( |
||
| 103 | $W->Link( |
||
| 104 | $W->Icon(absences_translate("Configure the works schedules"), Func_Icons::APPS_PREFERENCES_CALENDAR), |
||
| 105 | $WorkingHours->getProfileListUrl() |
||
| 106 | ) |
||
| 107 | ); |
||
| 108 | } |
||
| 109 | |||
| 110 | |||
| 111 | |||
| 112 | $cat->addItem( |
||
| 113 | $W->Link( |
||
| 114 | $W->Icon(absences_translate("Plannings"), Func_Icons::APPS_CALENDAR), |
||
| 115 | absences_addon()->getUrl()."planning&idx=list" |
||
| 116 | ) |
||
| 117 | ); |
||
| 118 | |||
| 119 | |||
| 120 | |||
| 121 | |||
| 122 | $cat->addItem( |
||
| 123 | $W->Link( |
||
| 124 | $W->Icon(absences_translate("Organizations"), Func_Icons::APPS_GROUPS), |
||
| 125 | absences_addon()->getUrl()."organizations" |
||
| 126 | ) |
||
| 127 | ); |
||
| 128 | |||
| 129 | |||
| 130 | return $cat; |
||
| 131 | } |
||
| 132 | |||
| 133 | |||
| 134 | View Code Duplication | protected function category_rights() |
|
| 178 | |||
| 179 | View Code Duplication | protected function category_requests() |
|
| 223 | |||
| 224 | |||
| 225 | |||
| 226 | |||
| 227 | |||
| 228 | View Code Duplication | protected function category_export() |
|
| 275 | |||
| 276 | |||
| 277 | public function getFrame() |
||
| 294 | } |
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.