| Conditions | 20 |
| Paths | 326 |
| Total Lines | 98 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 51 | public function setup($parameters, $id) |
||
| 52 | { |
||
| 53 | global $txt; |
||
| 54 | |||
| 55 | $show_event = !empty($parameters['events']); |
||
| 56 | $event_future = !empty($parameters['future']) ? (int) $parameters['future'] : 0; |
||
| 57 | $event_future = abs($event_future); |
||
| 58 | $show_birthday = !empty($parameters['birthdays']); |
||
| 59 | $show_holiday = !empty($parameters['holidays']); |
||
| 60 | $this->data['show_titles'] = false; |
||
| 61 | |||
| 62 | // If they are not showing anything, not much to do ! |
||
| 63 | if (!$show_event && !$show_birthday && !$show_holiday) |
||
| 64 | { |
||
| 65 | $this->data['error_msg'] = $txt['sp_calendar_noEventsFound']; |
||
| 66 | $this->setTemplate('template_sp_calendarInformation_error'); |
||
| 67 | |||
| 68 | return; |
||
| 69 | } |
||
| 70 | |||
| 71 | $now = forum_time(); |
||
| 72 | $today_date = date("Y-m-d", $now); |
||
| 73 | $this->data['calendar'] = array( |
||
| 74 | 'todayEvents' => array(), |
||
| 75 | 'futureEvents' => array(), |
||
| 76 | 'todayBirthdays' => array(), |
||
| 77 | 'todayHolidays' => array() |
||
| 78 | ); |
||
| 79 | |||
| 80 | // Load calendar events |
||
| 81 | if ($show_event) |
||
| 82 | { |
||
| 83 | // Just today's events or looking forward a few days? |
||
| 84 | if (!empty($event_future)) |
||
| 85 | { |
||
| 86 | $event_future_date = date("Y-m-d", ($now + $event_future * 86400)); |
||
|
|
|||
| 87 | } |
||
| 88 | else |
||
| 89 | { |
||
| 90 | $event_future_date = $today_date; |
||
| 91 | } |
||
| 92 | |||
| 93 | // Load them in |
||
| 94 | $events = sp_loadCalendarData('getEvents', $today_date, $event_future_date); |
||
| 95 | ksort($events); |
||
| 96 | |||
| 97 | $displayed = array(); |
||
| 98 | foreach ($events as $day => $day_events) |
||
| 99 | { |
||
| 100 | foreach ($day_events as $event_key => $event) |
||
| 101 | { |
||
| 102 | if (in_array($event['id'], $displayed)) |
||
| 103 | { |
||
| 104 | unset($events[$day][$event_key]); |
||
| 105 | } |
||
| 106 | else |
||
| 107 | { |
||
| 108 | $displayed[] = $event['id']; |
||
| 109 | } |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | if (!empty($events[$today_date])) |
||
| 114 | { |
||
| 115 | $this->data['calendar']['todayEvents'] = $events[$today_date]; |
||
| 116 | unset($events[$today_date]); |
||
| 117 | } |
||
| 118 | |||
| 119 | if (!empty($events)) |
||
| 120 | { |
||
| 121 | ksort($events); |
||
| 122 | $this->data['calendar']['futureEvents'] = $events; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | // Load in today's birthdays |
||
| 127 | if ($show_birthday) |
||
| 128 | { |
||
| 129 | $this->data['calendar']['todayBirthdays'] = current(sp_loadCalendarData('getBirthdays', $today_date)); |
||
| 130 | $this->data['show_titles'] = !empty($show_event) || !empty($show_holiday); |
||
| 131 | } |
||
| 132 | |||
| 133 | // Load in any holidays |
||
| 134 | if ($show_holiday) |
||
| 135 | { |
||
| 136 | $this->data['calendar']['todayHolidays'] = current(sp_loadCalendarData('getHolidays', $today_date)); |
||
| 137 | $this->data['show_titles'] = !empty($show_event) || !empty($show_birthday); |
||
| 138 | } |
||
| 139 | |||
| 140 | // Done collecting information, show what we found |
||
| 141 | if (empty($this->data['calendar']['todayEvents']) && empty($this->data['calendar']['futureEvents']) && empty($this->data['calendar']['todayBirthdays']) && empty($this->data['calendar']['todayHolidays'])) |
||
| 142 | { |
||
| 143 | $this->data['error_msg'] = $txt['sp_calendar_noEventsFound']; |
||
| 144 | $this->setTemplate('template_sp_calendarInformation_error'); |
||
| 145 | |||
| 146 | return; |
||
| 147 | } |
||
| 148 | $this->setTemplate('template_sp_calendarInformation'); |
||
| 149 | } |
||
| 248 |