| Total Complexity | 61 |
| Total Lines | 515 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| 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 Forms\FormInline |
||
| 161 | */ |
||
| 162 | public function getFormPageNavCounter($params = [], $action = '') |
||
| 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) |
||
| 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' => 'fee']; |
||
| 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 'fee': |
||
| 370 | $evFee = \json_decode($valueOld, true); |
||
| 371 | $evFeeText = ''; |
||
| 372 | foreach($evFee as $fee) { |
||
| 373 | $evFeeText .= Utility::FloatToString((float)$fee[0]) . ' ' . $fee[1] . '<br>'; |
||
| 374 | } |
||
| 375 | $valueOld = $evFeeText; |
||
| 376 | $evFee = \json_decode($valueNew, true); |
||
| 377 | $evFeeText = ''; |
||
| 378 | foreach($evFee as $fee) { |
||
| 379 | $evFeeText .= Utility::FloatToString((float)$fee[0]) . ' ' . $fee[1] . '<br>'; |
||
| 380 | } |
||
| 381 | $valueNew = $evFeeText; |
||
| 382 | $changedValues[] = [ |
||
| 383 | 'caption' => $field['caption'], |
||
| 384 | 'valueOld' => $valueOld, |
||
| 385 | 'valueNew' => $valueNew |
||
| 386 | ]; |
||
| 387 | break; |
||
| 388 | case'default': |
||
| 389 | default: |
||
| 390 | $changedValues[] = [ |
||
| 391 | 'caption' => $field['caption'], |
||
| 392 | 'valueOld' => $valueOld, |
||
| 393 | 'valueNew' => $valueNew |
||
| 394 | ]; |
||
| 395 | break; |
||
| 396 | } |
||
| 397 | } |
||
| 398 | } |
||
| 399 | if (\count($changedValues) > 0) { |
||
| 400 | $mailHandler = new MailHandler(); |
||
| 401 | return $mailHandler->array2table ($changedValues); |
||
| 402 | } |
||
| 403 | |||
| 404 | return ''; |
||
| 405 | } |
||
| 406 | /** |
||
| 407 | * get email recipients for noticiations |
||
| 408 | * @param $registerNotify |
||
| 409 | * @return array|false|string[] |
||
| 410 | */ |
||
| 411 | public function getRecipientsNotify($registerNotify) |
||
| 427 | } |
||
| 428 | /** |
||
| 429 | * get clean date from/to for displaying |
||
| 430 | * @param int $datefrom |
||
| 431 | * @param int $dateto |
||
| 432 | * @param bool $allday |
||
| 433 | * @return string |
||
| 434 | */ |
||
| 435 | public function getDateFromToText($datefrom, $dateto, $allday) |
||
| 436 | { |
||
| 437 | $text = ''; |
||
| 438 | $today = date('d.m.Y', time()) === date('d.m.Y', $datefrom); |
||
| 439 | $multiday = (int)date('j', $dateto) !== (int)date('j', $datefrom); |
||
| 440 | /* |
||
| 441 | $days = 1; |
||
| 442 | if ($multiday) { |
||
| 443 | $days = (1 + date_create(date('d.m.Y', $dateto))->diff(date_create(date('d.m.Y', $datefrom)))->format("%a")); |
||
| 444 | } |
||
| 445 | */ |
||
| 446 | $lng_until = ' ' . \_MA_WGEVENTS_EVENT_DATEUNTIL . ' '; |
||
| 447 | $lng_today = \_MA_WGEVENTS_EVENT_TODAY; |
||
| 448 | $lng_allday = \_MA_WGEVENTS_EVENT_ALLDAY; |
||
| 449 | |||
| 450 | if ($today) { |
||
| 451 | // get all types of today |
||
| 452 | if ($allday && !$multiday) { |
||
| 453 | // today, allday, no multiday |
||
| 454 | $text = $lng_today . ' ' . $lng_allday; |
||
| 455 | } else if ($today && !$allday && !$multiday) { |
||
| 456 | // today, no allday, no multiday |
||
| 457 | $text = $lng_today . ' ' . date('H:i', $datefrom) . $lng_until . date('H:i', $dateto); |
||
| 458 | } else { |
||
| 459 | // today, no allday, multiday |
||
| 460 | $text = $lng_today . ' ' . date('H:i', $datefrom) . $lng_until . \formatTimestamp($dateto, 'm'); |
||
| 461 | } |
||
| 462 | } else { |
||
| 463 | // not today |
||
| 464 | if ($allday && $multiday) { |
||
| 465 | // allday, multiday |
||
| 466 | $text = \formatTimestamp($datefrom, 's') . $lng_allday . $lng_until . \formatTimestamp($dateto, 'm') . $lng_allday; |
||
| 467 | } else if (!$allday && !$multiday) { |
||
| 468 | // no allday, no multiday |
||
| 469 | $text = \formatTimestamp($datefrom, 's') . ' ' . date('H:i', $datefrom) . $lng_until . date('H:i', $dateto); |
||
| 470 | } else { |
||
| 471 | // no allday, multiday |
||
| 472 | $text = \formatTimestamp($datefrom, 'm') . $lng_until . \formatTimestamp($dateto, 'm'); |
||
| 473 | //TODO: same time for each day / different times for different days |
||
| 474 | } |
||
| 475 | } |
||
| 476 | /* |
||
| 477 | echo '<br>today:'.$today; |
||
| 478 | echo '<br>datefrom:'.\formatTimestamp($datefrom, 'm'); |
||
| 479 | echo '<br>dateto:'.\formatTimestamp($dateto, 'm'); |
||
| 480 | echo '<br>multiday:'.$multiday; |
||
| 481 | echo '<br>return:'.$text; |
||
| 482 | */ |
||
| 483 | return $text; |
||
| 484 | } |
||
| 485 | |||
| 486 | |||
| 487 | /** |
||
| 488 | * @public function getFormFilterExport: form for selecting cats and number of lines for export of events |
||
| 489 | * @param bool $eventDisplayCats |
||
| 490 | * @param array $filterCats |
||
| 491 | * @return \XoopsThemeForm |
||
| 492 | */ |
||
| 493 | public function getFormFilterExport($limit, $dateFrom, $dateTo, $eventDisplayCats = false, $filterCats = []) |
||
| 549 | } |
||
| 550 | } |
||
| 551 |
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