Conditions | 6 |
Paths | 5 |
Total Lines | 76 |
Code Lines | 37 |
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 |
||
33 | function bExtcalUpcomingShow($options) |
||
34 | { |
||
35 | /** @var Helper $helper */ |
||
36 | if (!class_exists(Helper::class)) { |
||
37 | return false; |
||
38 | } |
||
39 | |||
40 | $helper = Helper::getInstance(); |
||
41 | $helper->loadLanguage('main'); |
||
42 | $helper->loadLanguage('blocks'); |
||
43 | /** @var EventHandler $eventHandler */ |
||
44 | $eventHandler = $helper->getHandler(_EXTCAL_CLN_EVENT); |
||
45 | |||
46 | $nbEvent = $options[0]; |
||
47 | $titleLenght = $options[1]; |
||
|
|||
48 | $nbDays = $options[2]; |
||
49 | |||
50 | array_shift($options); |
||
51 | array_shift($options); |
||
52 | array_shift($options); |
||
53 | |||
54 | // Checking if no cat is selected |
||
55 | if (isset($options[0]) && 0 == $options[0] && 1 == count($options)) { |
||
56 | $options = 0; |
||
57 | } |
||
58 | |||
59 | //------------------- |
||
60 | /* ========================================================================== */ |
||
61 | $year = Request::getInt('year', date('Y'), 'GET'); |
||
62 | $month = Request::getInt('month', date('n'), 'GET'); |
||
63 | $day = Request::getInt('day', date('j'), 'GET'); |
||
64 | $cat = Request::getInt('cat', 0, 'GET'); |
||
65 | /* ========================================================================== */ |
||
66 | |||
67 | // Validate the date (day, month and year) |
||
68 | $dayTS = mktime(0, 0, 0, $month, $day, $year); |
||
69 | |||
70 | //$offset = $helper->getConfig('week_start_day') - date('w', $dayTS); |
||
71 | |||
72 | //------- mb -------------- |
||
73 | // let's make sure that the upcoming events start tomorrow |
||
74 | // $offset = date('w', $dayTS) + 7-$helper->getConfig('week_start_day')<7 ? date('w', $dayTS) + 7-$helper->getConfig('week_start_day') : 0; |
||
75 | // $dayTS = $dayTS - ($offset * _EXTCAL_TS_DAY); |
||
76 | |||
77 | $dayTS += _EXTCAL_TS_DAY; |
||
78 | //------- mb ----------------- |
||
79 | |||
80 | $year = date('Y', $dayTS); |
||
81 | $month = date('n', $dayTS); |
||
82 | $day = date('j', $dayTS); |
||
83 | |||
84 | // Retriving events and formatting them |
||
85 | //$events = $eventHandler->objectToArray($eventHandler->getEventWeek($day, $month, $year, $cat), array('cat_id')); |
||
86 | $criteres = [ |
||
87 | 'periode' => _EXTCAL_EVENTS_UPCOMING, |
||
88 | // 'periode' => _EXTCAL_EVENTS_CALENDAR_WEEK, |
||
89 | 'day' => $day, |
||
90 | 'month' => $month, |
||
91 | 'year' => $year, |
||
92 | 'cat' => $cat, |
||
93 | 'externalKeys' => 'cat_id', |
||
94 | 'nbEvent' => $nbEvent, |
||
95 | 'nbDays' => $nbDays, |
||
96 | ]; |
||
97 | $events = $eventHandler->getEventsOnPeriode($criteres); |
||
98 | |||
99 | //---------------------------- |
||
100 | |||
101 | //$eventHandler->serverTimeToUserTimes($events); |
||
102 | $eventHandler->formatEventsDate($events, $helper->getConfig('event_date_month')); |
||
103 | |||
104 | if (count($events) > $nbEvent) { |
||
105 | $events = array_slice($events, 0, $nbEvent); |
||
106 | } |
||
107 | |||
108 | return $events; |
||
109 | } |
||
160 |