| Conditions | 4 |
| Paths | 8 |
| Total Lines | 91 |
| Code Lines | 44 |
| Lines | 18 |
| Ratio | 19.78 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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 | |||
| 294 | } |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: