Conditions | 5 |
Paths | 2 |
Total Lines | 54 |
Code Lines | 39 |
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 |
||
75 | public function grabEntries(\XoopsMySQLDatabase $xoopsDB): ?array |
||
76 | { |
||
77 | $ret = null; |
||
78 | $i = 0; |
||
79 | |||
80 | // read confgs to get timestamp format |
||
81 | $extcal = $this->module; |
||
82 | /** @var \XoopsConfigHandler $configHandler */ |
||
83 | $configHandler = \xoops_getHandler('config'); |
||
84 | $extcalConfig = $configHandler->getConfigsByCat(0, $extcal->getVar('mid')); |
||
85 | $dateLongForm = $extcalConfig['date_long']; |
||
86 | |||
87 | $eventHandler = PluginHelper::getInstance()->getHandler('Event'); |
||
88 | $catHandler = PluginHelper::getInstance()->getHandler('Category'); |
||
89 | $events = $eventHandler->getUpcomingEvent($this->grab,0); |
||
90 | |||
91 | if (\is_array($events)) { |
||
92 | $ret = []; |
||
93 | foreach ($events as $event) { |
||
94 | ++$i; |
||
95 | $cat = $catHandler->getCat($event->getVar('cat_id'), 0); |
||
96 | $category = $cat->getVar('cat_name'); |
||
97 | $link = XOOPS_URL . '/modules/extcal/event.php?event=' . $event->getVar('event_id'); |
||
98 | $eventStart = \formatTimestamp($event->getVar('event_start'), $dateLongForm); |
||
99 | $temp = \htmlspecialchars($event->getVar('event_title'), \ENT_QUOTES); |
||
100 | $title = \xoops_utf8_encode($temp); |
||
101 | $temp = \htmlspecialchars($event->getVar('event_desc'), \ENT_QUOTES); |
||
102 | $description = \xoops_utf8_encode($temp); |
||
103 | $address = $event->getVar('event_address'); |
||
104 | |||
105 | $eventUrl = $event->getVar('event_url'); |
||
106 | if ('' === $eventUrl) { |
||
107 | $eventUrl = $link; |
||
108 | } |
||
109 | $desc = "<a href=\"$eventUrl\"><b>$title</b></a><br>"; |
||
110 | $desc .= '<table>'; |
||
111 | $desc .= "<tr><td valign='top'>When:</td><td>$eventStart</td></tr>"; |
||
112 | if ('' !== $address) { |
||
113 | $desc .= "<tr><td valign='top'>Where:</td><td>$address</td></tr>"; |
||
114 | } |
||
115 | $desc .= "<tr><td valign='top'>What:</td><td>$description</td></tr>"; |
||
116 | $desc .= '</table>'; |
||
117 | |||
118 | $ret[$i]['title'] = $category . ': ' . $title; |
||
119 | $ret[$i]['link'] = $link; |
||
120 | $ret[$i]['description'] = $desc; |
||
121 | $ret[$i]['timestamp'] = $event->getVar('event_submitdate'); |
||
122 | // $ret[$i]['timestamp'] = time(); |
||
123 | $ret[$i]['guid'] = $link; |
||
124 | $ret[$i]['category'] = $category; |
||
125 | } |
||
126 | } |
||
127 | |||
128 | return $ret; |
||
129 | } |
||
131 |