Total Complexity | 57 |
Total Lines | 492 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like EventHandler often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use EventHandler, and based on these observations, apply Extract Interface, too.
1 | <?php declare(strict_types=1); |
||
34 | class EventHandler extends \XoopsPersistableObjectHandler |
||
35 | { |
||
36 | /** |
||
37 | * Constructor |
||
38 | * |
||
39 | * @param \XoopsDatabase $db |
||
40 | */ |
||
41 | public function __construct(\XoopsDatabase $db) |
||
42 | { |
||
43 | parent::__construct($db, 'wgevents_event', Event::class, 'id', 'name'); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @param bool $isNew |
||
48 | * |
||
49 | * @return object |
||
50 | */ |
||
51 | public function create($isNew = true) |
||
52 | { |
||
53 | return parent::create($isNew); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * retrieve a field |
||
58 | * |
||
59 | * @param int $id field id |
||
60 | * @param null fields |
||
|
|||
61 | * @return \XoopsObject|null reference to the {@link Get} object |
||
62 | */ |
||
63 | public function get($id = null, $fields = null) |
||
64 | { |
||
65 | return parent::get($id, $fields); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * get inserted id |
||
70 | * |
||
71 | * @param null |
||
72 | * @return int reference to the {@link Get} object |
||
73 | */ |
||
74 | public function getInsertId() |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * Get Count Event in the database |
||
81 | * @param int $start |
||
82 | * @param int $limit |
||
83 | * @param string $sort |
||
84 | * @param string $order |
||
85 | * @return int |
||
86 | */ |
||
87 | public function getCountEvents($start = 0, $limit = 0, $sort = 'id', $order = 'DESC') |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Get All Event in the database |
||
96 | * @param int $start |
||
97 | * @param int $limit |
||
98 | * @param string $sort |
||
99 | * @param string $order |
||
100 | * @return array |
||
101 | */ |
||
102 | public function getAllEvents($start = 0, $limit = 0, $sort = 'id', $order = 'DESC') |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * Get Criteria Event |
||
111 | * @param $crEvent |
||
112 | * @param int $start |
||
113 | * @param int $limit |
||
114 | * @param string $sort |
||
115 | * @param string $order |
||
116 | * @return int |
||
117 | */ |
||
118 | private function getEventsCriteria($crEvent, int $start, int $limit, string $sort, string $order) |
||
119 | { |
||
120 | $crEvent->setStart($start); |
||
121 | $crEvent->setLimit($limit); |
||
122 | $crEvent->setSort($sort); |
||
123 | $crEvent->setOrder($order); |
||
124 | return $crEvent; |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * @public function getForm |
||
129 | * @param bool $action |
||
130 | * @return \XoopsThemeForm |
||
131 | */ |
||
132 | public function getFormEventSelect($action = false) |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * TODO: not in use currently |
||
157 | * @public function getForm |
||
158 | * @param array $params |
||
159 | * @param string $action |
||
160 | * @return \XoopsThemeForm |
||
161 | */ |
||
162 | public function getFormPageNavCounter($params = [], $action = '') |
||
163 | { |
||
164 | if (!$action) { |
||
165 | $action = $_SERVER['REQUEST_URI']; |
||
166 | } |
||
167 | // Get Theme Form |
||
168 | \xoops_load('XoopsFormLoader'); |
||
169 | $form = new Forms\FormInline('', 'formPageNavCounter', $action, 'post', true); |
||
170 | $form->setExtra('enctype="multipart/form-data"'); |
||
171 | // Form Table categories |
||
172 | $pageNavTray = new Forms\FormElementTray('', ''); |
||
173 | $evidSelect = new \XoopsFormSelect(\_MA_WGEVENTS_EVENT_ID, 'limit', $params['limit']); |
||
174 | $evidSelect->addOption(10); |
||
175 | $evidSelect->addOption(20); |
||
176 | $evidSelect->addOption(30); |
||
177 | $evidSelect->addOption(40); |
||
178 | $evidSelect->addOption(50); |
||
179 | $evidSelect->addOption(100); |
||
180 | $evidSelect->addOption(0, _ALL); |
||
181 | $evidSelect->setExtra("onchange='submit()'"); |
||
182 | $pageNavTray->addElement($evidSelect); |
||
183 | $form->addElement($pageNavTray); |
||
184 | // To list |
||
185 | $form->addElement(new \XoopsFormHidden('op', $params['op'])); |
||
186 | $form->addElement(new \XoopsFormHidden('start', 0)); |
||
187 | $form->addElement(new \XoopsFormHidden('cat_id', $params['cat_id'])); |
||
188 | $form->addElement(new \XoopsFormHidden('filterCats', $params['filterCats'])); |
||
189 | |||
190 | return $form; |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * @public function to get events for given params |
||
195 | * |
||
196 | * @param int $start |
||
197 | * @param int $limit |
||
198 | * @param int $dateFrom // filter date created from (timestamp) |
||
199 | * @param int $dateTo // filter date created to (timestamp) |
||
200 | * @param string $sortBy |
||
201 | * @param string $orderBy |
||
202 | * @param string $op |
||
203 | * @param int $evId |
||
204 | * @param string $filter |
||
205 | * @param array $filterCats |
||
206 | * @param int $dateCreated |
||
207 | * @return array |
||
208 | */ |
||
209 | public function getEvents($start = 0, $limit = 0, $dateFrom = 0, $dateTo = 0, $sortBy = 'datefrom', $orderBy = 'ASC', $op = 'list', $evId = 0, $filter = '', $filterCats = [], $dateCreated = 0) |
||
210 | { |
||
211 | $helper = Helper::getInstance(); |
||
212 | |||
213 | /* |
||
214 | echo '<br>start:'.$start; |
||
215 | echo '<br>limit:'.$limit; |
||
216 | echo '<br>datefrom:'.\formatTimestamp($dateFrom, 'm').'('.$dateFrom.')'; |
||
217 | echo '<br>dateto:'.\formatTimestamp($dateTo, 'm').'('.$dateTo.')'; |
||
218 | echo '<br>sortBy:'.$sortBy; |
||
219 | echo '<br>orderBy:'.$orderBy; |
||
220 | echo '<br>op:'.$op; |
||
221 | echo '<br>evId:'.$evId; |
||
222 | echo '<br>filter:'.$filter; |
||
223 | foreach ($filterCats as $filterCat) { |
||
224 | echo '<br>filterCat:'.$filterCat; |
||
225 | } |
||
226 | */ |
||
227 | |||
228 | $showItem = ($evId > 0); |
||
229 | $uidCurrent = 0; |
||
230 | $userIsAdmin = false; |
||
231 | if (\is_object($GLOBALS['xoopsUser'])) { |
||
232 | $uidCurrent = $GLOBALS['xoopsUser']->uid(); |
||
233 | $userIsAdmin = $GLOBALS['xoopsUser']->isAdmin(); |
||
234 | } |
||
235 | $useGroups = (bool)$helper->getConfig('use_groups'); |
||
236 | |||
237 | //apply criteria for events |
||
238 | $crEvent = new \CriteriaCompo(); |
||
239 | if ($showItem) { |
||
240 | $crEvent->add(new \Criteria('id', $evId)); |
||
241 | } else { |
||
242 | if ('me' == $filter && $uidCurrent > 0) { |
||
243 | $crEvent->add(new \Criteria('submitter', $uidCurrent)); |
||
244 | } |
||
245 | } |
||
246 | //get only events which are online or from me |
||
247 | $crEventOnline = new \CriteriaCompo(); |
||
248 | $crEventOnline->add(new \Criteria('status', Constants::STATUS_OFFLINE, '>')); |
||
249 | $crEventOnline->add(new \Criteria('submitter', $uidCurrent), 'OR'); |
||
250 | $crEvent->add($crEventOnline); |
||
251 | |||
252 | if ($dateCreated > 0) { |
||
253 | $crEvent->add(new \Criteria('datecreated', $dateCreated, '>=')); |
||
254 | } |
||
255 | if ($useGroups) { |
||
256 | // current user |
||
257 | // - must have perm to see event or |
||
258 | // - must be event owner |
||
259 | // - is admin |
||
260 | if (!$userIsAdmin) { |
||
261 | $crEventGroup = new \CriteriaCompo(); |
||
262 | $crEventGroup->add(new \Criteria('groups', '%00000%', 'LIKE')); //all users |
||
263 | if ($uidCurrent > 0) { |
||
264 | // Get groups |
||
265 | $memberHandler = \xoops_getHandler('member'); |
||
266 | $xoopsGroups = $memberHandler->getGroupsByUser($uidCurrent); |
||
267 | foreach ($xoopsGroups as $group) { |
||
268 | $crEventGroup->add(new \Criteria('groups', '%' . substr('00000' . $group, -5) . '%', 'LIKE'), 'OR'); |
||
269 | } |
||
270 | } |
||
271 | $crEventGroup->add(new \Criteria('submitter', $uidCurrent), 'OR'); |
||
272 | $crEvent->add($crEventGroup); |
||
273 | unset($crEventGroup); |
||
274 | } |
||
275 | } |
||
276 | if (!$showItem) { |
||
277 | if ('past' == $op) { |
||
278 | // list events before now |
||
279 | $crEvent->add(new \Criteria('datefrom', $dateFrom, '<')); |
||
280 | $sortBy = 'datefrom'; |
||
281 | $orderBy = 'DESC'; |
||
282 | } else { |
||
283 | // calendar view: |
||
284 | // - event start is between dateFrom and dateTo |
||
285 | // - event end is between dateFrom and dateTo |
||
286 | // ==> dateFrom and dateTo needed |
||
287 | |||
288 | // index/event/block view: |
||
289 | // - event start or event end is greater than dateFrom |
||
290 | // ==> dateFrom needed, dateTo must be 0 |
||
291 | $crEventFromTo = new \CriteriaCompo(); |
||
292 | $crEventStart = new \CriteriaCompo(); |
||
293 | $crEventStart->add(new \Criteria('datefrom', $dateFrom, '>=')); |
||
294 | if ($dateTo > 0) { |
||
295 | $crEventStart->add(new \Criteria('datefrom', $dateTo, '<=')); |
||
296 | } |
||
297 | $crEventFromTo->add($crEventStart); |
||
298 | $crEventEnd = new \CriteriaCompo(); |
||
299 | $crEventEnd->add(new \Criteria('dateto', $dateFrom, '>=')); |
||
300 | if ($dateTo > 0) { |
||
301 | $crEventEnd->add(new \Criteria('dateto', $dateTo, '<=')); |
||
302 | } |
||
303 | $crEventFromTo->add($crEventEnd, 'OR'); |
||
304 | $crEvent->add($crEventFromTo); |
||
305 | |||
306 | unset($crEventStart, $crEventEnd, $crEventFromTo); |
||
307 | $sortBy = 'datefrom'; |
||
308 | $orderBy = 'ASC'; |
||
309 | } |
||
310 | if (\count($filterCats) > 0) { |
||
311 | $crEventCats = new \CriteriaCompo(); |
||
312 | $crEventCats->add(new \Criteria('catid', '(' . \implode(',', $filterCats) . ')', 'IN')); |
||
313 | foreach ($filterCats as $filterCat) { |
||
314 | $crEventCats->add(new \Criteria('subcats', '%"' . $filterCat . '"%', 'LIKE'), 'OR'); |
||
315 | } |
||
316 | $crEvent->add($crEventCats); |
||
317 | } |
||
318 | } |
||
319 | $crEvent->setSort($sortBy); |
||
320 | $crEvent->setOrder($orderBy); |
||
321 | $eventsCount = $this->getCount($crEvent); |
||
322 | if ($eventsCount > 0) { |
||
323 | if ($limit > 0) { |
||
324 | $crEvent->setStart($start); |
||
325 | $crEvent->setLimit($limit); |
||
326 | } |
||
327 | // Get All Event |
||
328 | $eventsAll = $this->getAll($crEvent); |
||
329 | |||
330 | return ['count' => $eventsCount, 'eventsAll' => $eventsAll]; |
||
331 | } |
||
332 | |||
333 | return ['count' => 0, 'eventsAll' => []]; |
||
334 | } |
||
335 | |||
336 | /** |
||
337 | * compare two versions of events |
||
338 | * @param $versionOld |
||
339 | * @param $versionNew |
||
340 | * @return string |
||
341 | */ |
||
342 | public function getEventsCompare($versionOld, $versionNew) |
||
343 | { |
||
344 | $changedValues = []; |
||
345 | // find changes in important fields of table events |
||
346 | $fields = []; |
||
347 | $fields[] = ['name' => 'name', 'caption' => \_MA_WGEVENTS_EVENT_NAME, 'type' => 'text']; |
||
348 | $fields[] = ['name' => 'desc', 'caption' => \_MA_WGEVENTS_EVENT_DESC, 'type' => 'text']; |
||
349 | $fields[] = ['name' => 'datefrom', 'caption' => \_MA_WGEVENTS_EVENT_DATEFROM, 'type' => 'datetime']; |
||
350 | $fields[] = ['name' => 'dateto', 'caption' => \_MA_WGEVENTS_EVENT_DATETO, 'type' => 'datetime']; |
||
351 | $fields[] = ['name' => 'location', 'caption' => \_MA_WGEVENTS_EVENT_LOCATION, 'type' => 'text']; |
||
352 | $fields[] = ['name' => 'fee', 'caption' => \_MA_WGEVENTS_EVENT_FEE, 'type' => 'text']; |
||
353 | |||
354 | foreach ($fields as $field) { |
||
355 | $valueOld = $versionOld->getVar($field['name']); |
||
356 | $valueNew = $versionNew->getVar($field['name']); |
||
357 | if ($valueOld != $valueNew) { |
||
358 | if ('' == $valueNew) { |
||
359 | $valueNew = _MA_WGEVENTS_MAIL_REG_MODIFICATION_DELETED; |
||
360 | } |
||
361 | switch ($field['type']) { |
||
362 | case 'datetime': |
||
363 | $changedValues[] = [ |
||
364 | 'caption' => $field['caption'], |
||
365 | 'valueOld' => \formatTimestamp($valueOld, 'm'), |
||
366 | 'valueNew' => \formatTimestamp($valueNew, 'm') |
||
367 | ]; |
||
368 | break; |
||
369 | case'default': |
||
370 | default: |
||
371 | $changedValues[] = [ |
||
372 | 'caption' => $field['caption'], |
||
373 | 'valueOld' => $valueOld, |
||
374 | 'valueNew' => $valueNew |
||
375 | ]; |
||
376 | break; |
||
377 | } |
||
378 | } |
||
379 | } |
||
380 | if (\count($changedValues) > 0) { |
||
381 | $mailHandler = new MailHandler(); |
||
382 | return $mailHandler->array2table ($changedValues); |
||
383 | } |
||
384 | |||
385 | return ''; |
||
386 | } |
||
387 | /** |
||
388 | * get email recipients for noticiations |
||
389 | * @param $registerNotify |
||
390 | * @return array|false|string[] |
||
391 | */ |
||
392 | public function getRecipientsNotify($registerNotify) |
||
408 | } |
||
409 | /** |
||
410 | * get clean date from/to for displaying |
||
411 | * @param int $datefrom |
||
412 | * @param int $dateto |
||
413 | * @param bool $allday |
||
414 | * @return string |
||
415 | */ |
||
416 | public function getDateFromToText($datefrom, $dateto, $allday) |
||
417 | { |
||
418 | $text = ''; |
||
419 | $today = date('d.m.Y', time()) === date('d.m.Y', $datefrom); |
||
420 | $multiday = (int)date('j', $dateto) > (int)date('j', $datefrom); |
||
421 | |||
422 | // currently only used by blocks |
||
423 | //if (\defined(\_MB_WGEVENTS_EVENT_TODAY)) { |
||
424 | $lng_today = \_MA_WGEVENTS_EVENT_TODAY; |
||
425 | $lng_allday = \_MA_WGEVENTS_EVENT_ALLDAY; |
||
426 | //} |
||
427 | |||
428 | if ($today) { |
||
429 | // get all types of today |
||
430 | if ($allday && !$multiday) { |
||
431 | // today, allday, no multiday |
||
432 | $text = $lng_today . ' ' . $lng_allday; |
||
433 | } else if ($today && !$allday && !$multiday) { |
||
434 | // today, no allday, no multiday |
||
435 | $text = $lng_today . ' ' . date('H:i', $datefrom) . ' - ' . date('H:i', $dateto); |
||
436 | } else { |
||
437 | // today, no allday, multiday |
||
438 | $text = $lng_today . ' ' . date('H:i', $datefrom) . ' - ' . \formatTimestamp($dateto, 'm'); |
||
439 | } |
||
440 | } else { |
||
441 | // not today |
||
442 | if ($allday && $multiday) { |
||
443 | // allday, multiday |
||
444 | $text = \formatTimestamp($datefrom, 's') . $lng_allday . ' - ' . \formatTimestamp($dateto, 'm') . $lng_allday; |
||
445 | } else if (!$allday && !$multiday) { |
||
446 | // no allday, no multiday |
||
447 | $text = \formatTimestamp($datefrom, 's') . ' ' . date('H:i', $datefrom) . ' - ' . date('H:i', $dateto); |
||
448 | } else { |
||
449 | // no allday, multiday |
||
450 | $text = \formatTimestamp($datefrom, 'm') . ' - ' . \formatTimestamp($dateto, 'm'); |
||
451 | } |
||
452 | } |
||
453 | /* |
||
454 | echo '<br>today:'.$today; |
||
455 | echo '<br>datefrom:'.\formatTimestamp($datefrom, 'm'); |
||
456 | echo '<br>dateto:'.\formatTimestamp($dateto, 'm'); |
||
457 | echo '<br>multiday:'.$multiday; |
||
458 | echo '<br>return:'.$text; |
||
459 | */ |
||
460 | return $text; |
||
461 | } |
||
462 | |||
463 | |||
464 | /** |
||
465 | * @public function getFormFilterExport: form for selecting cats and number of lines for export of events |
||
466 | * @param bool $eventDisplayCats |
||
467 | * @param array $filterCats |
||
468 | * @return \XoopsThemeForm |
||
469 | */ |
||
470 | public function getFormFilterExport($limit, $dateFrom, $dateTo, $eventDisplayCats = false, $filterCats = []) |
||
526 | } |
||
527 | } |
||
528 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths