Conditions | 14 |
Paths | 61 |
Total Lines | 65 |
Lines | 0 |
Ratio | 0 % |
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 |
||
93 | function caldav_onCollectCalendarsBeforeDisplay(bab_eventCollectCalendarsBeforeDisplay $event) |
||
94 | { |
||
95 | global $babBody; |
||
96 | |||
97 | /* @var $backend Func_CalendarBackend_Caldav */ |
||
98 | $backend = bab_functionality::get('CalendarBackend/Caldav'); |
||
99 | if (!isset($backend) || $backend === false) { |
||
100 | return; |
||
101 | } |
||
102 | |||
103 | $personal_calendar = null; |
||
104 | $access_user = $event->getAccessUser(); |
||
105 | $calendar_backend = $event->getBackendName(); // bab_getICalendars()->calendar_backend; |
||
106 | |||
107 | if (!empty($access_user) && 'Caldav' === $calendar_backend) { |
||
108 | |||
109 | try { |
||
110 | $personal_calendar = $backend->PersonalCalendar($access_user); |
||
111 | } |
||
112 | catch(Exception $e) |
||
113 | { |
||
114 | bab_debug($e->getMessage()); |
||
115 | } |
||
116 | |||
117 | if ($personal_calendar) { |
||
118 | $personal_calendar->setName(bab_getUserName($access_user, true) . ' (CalDAV)'); |
||
119 | $personal_calendar->setAccessUser($access_user); |
||
120 | $event->addCalendar($personal_calendar); |
||
121 | } |
||
122 | } |
||
123 | |||
124 | |||
125 | if ('Caldav' !== $calendar_backend || $personal_calendar || $babBody->babsite['iPersonalCalendarAccess'] == 'Y') { |
||
126 | $arr = $backend->getAccessiblePersonalCalendars($access_user, 'caldav_personal'); |
||
127 | |||
128 | foreach ($arr as $id_user) { |
||
129 | $calendar = $backend->PersonalCalendar($id_user); |
||
130 | $calendar->setName(bab_getUserName($id_user, true) . ' (CalDAV)'); |
||
131 | $calendar->setAccessUser($access_user); |
||
132 | $event->addCalendar($calendar); |
||
133 | } |
||
134 | } |
||
135 | |||
136 | // add resources calendars |
||
137 | |||
138 | if (isset($GLOBALS['BAB_SESS_USERID'])) |
||
139 | { |
||
140 | $_idu = $GLOBALS['BAB_SESS_USERID']; |
||
141 | } else { |
||
142 | // new addon controller |
||
143 | $_idu = bab_getUserId(); |
||
144 | } |
||
145 | |||
146 | |||
147 | if ($access_user == $_idu) |
||
148 | { |
||
149 | $arr = $backend->getAccessibleResourceCalendars(); |
||
150 | |||
151 | foreach ($arr as $uid => $resource) { |
||
152 | $calendar = $backend->ResourceCalendar($uid, $resource); |
||
153 | $calendar->setName($resource['name'] . ' (CalDAV)'); |
||
154 | $event->addCalendar($calendar); |
||
155 | } |
||
156 | } |
||
157 | } |
||
158 | |||
160 |