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