| Conditions | 18 |
| Paths | 1584 |
| Total Lines | 125 |
| Code Lines | 69 |
| 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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
| 1 | <?php declare(strict_types=1); |
||
| 208 | public function getEvents($start = 0, $limit = 0, $dateFrom = 0, $dateTo = 0, $sortBy = 'datefrom', $orderBy = 'ASC', $op = 'list', $evId = 0, $filter = '', $filterCats = [], $dateCreated = 0) |
||
| 209 | { |
||
| 210 | $helper = Helper::getInstance(); |
||
| 211 | |||
| 212 | /* |
||
| 213 | echo '<br>start:'.$start; |
||
| 214 | echo '<br>limit:'.$limit; |
||
| 215 | echo '<br>datefrom:'.\formatTimestamp($dateFrom, 'm').'('.$dateFrom.')'; |
||
| 216 | echo '<br>dateto:'.\formatTimestamp($dateTo, 'm').'('.$dateTo.')'; |
||
| 217 | echo '<br>sortBy:'.$sortBy; |
||
| 218 | echo '<br>orderBy:'.$orderBy; |
||
| 219 | echo '<br>op:'.$op; |
||
| 220 | echo '<br>evId:'.$evId; |
||
| 221 | echo '<br>filter:'.$filter; |
||
| 222 | foreach ($filterCats as $filterCat) { |
||
| 223 | echo '<br>filterCat:'.$filterCat; |
||
| 224 | } |
||
| 225 | */ |
||
| 226 | |||
| 227 | $showItem = ($evId > 0); |
||
| 228 | $uidCurrent = 0; |
||
| 229 | $userIsAdmin = false; |
||
| 230 | if (\is_object($GLOBALS['xoopsUser'])) { |
||
| 231 | $uidCurrent = $GLOBALS['xoopsUser']->uid(); |
||
| 232 | $userIsAdmin = $GLOBALS['xoopsUser']->isAdmin(); |
||
| 233 | } |
||
| 234 | $useGroups = (bool)$helper->getConfig('use_groups'); |
||
| 235 | |||
| 236 | //apply criteria for events |
||
| 237 | $crEvent = new \CriteriaCompo(); |
||
| 238 | if ($showItem) { |
||
| 239 | $crEvent->add(new \Criteria('id', $evId)); |
||
| 240 | } else { |
||
| 241 | if ('me' == $filter && $uidCurrent > 0) { |
||
| 242 | $crEvent->add(new \Criteria('submitter', $uidCurrent)); |
||
| 243 | } |
||
| 244 | } |
||
| 245 | //get only events which are online or from me |
||
| 246 | $crEventOnline = new \CriteriaCompo(); |
||
| 247 | $crEventOnline->add(new \Criteria('status', Constants::STATUS_OFFLINE, '>')); |
||
| 248 | $crEventOnline->add(new \Criteria('submitter', $uidCurrent), 'OR'); |
||
| 249 | $crEvent->add($crEventOnline); |
||
| 250 | |||
| 251 | if ($dateCreated > 0) { |
||
| 252 | $crEvent->add(new \Criteria('datecreated', $dateCreated, '>=')); |
||
| 253 | } |
||
| 254 | if ($useGroups) { |
||
| 255 | // current user |
||
| 256 | // - must have perm to see event or |
||
| 257 | // - must be event owner |
||
| 258 | // - is admin |
||
| 259 | if (!$userIsAdmin) { |
||
| 260 | $crEventGroup = new \CriteriaCompo(); |
||
| 261 | $crEventGroup->add(new \Criteria('groups', '%00000%', 'LIKE')); //all users |
||
| 262 | if ($uidCurrent > 0) { |
||
| 263 | // Get groups |
||
| 264 | $memberHandler = \xoops_getHandler('member'); |
||
| 265 | $xoopsGroups = $memberHandler->getGroupsByUser($uidCurrent); |
||
| 266 | foreach ($xoopsGroups as $group) { |
||
| 267 | $crEventGroup->add(new \Criteria('groups', '%' . substr('00000' . $group, -5) . '%', 'LIKE'), 'OR'); |
||
| 268 | } |
||
| 269 | } |
||
| 270 | $crEventGroup->add(new \Criteria('submitter', $uidCurrent), 'OR'); |
||
| 271 | $crEvent->add($crEventGroup); |
||
| 272 | unset($crEventGroup); |
||
| 273 | } |
||
| 274 | } |
||
| 275 | if (!$showItem) { |
||
| 276 | if ('past' == $op) { |
||
| 277 | // list events before now |
||
| 278 | $crEvent->add(new \Criteria('datefrom', $dateFrom, '<')); |
||
| 279 | $sortBy = 'datefrom'; |
||
| 280 | $orderBy = 'DESC'; |
||
| 281 | } else { |
||
| 282 | // calendar view: |
||
| 283 | // - event start is between dateFrom and dateTo |
||
| 284 | // - event end is between dateFrom and dateTo |
||
| 285 | // ==> dateFrom and dateTo needed |
||
| 286 | |||
| 287 | // index/event/block view: |
||
| 288 | // - event start or event end is greater than dateFrom |
||
| 289 | // ==> dateFrom needed, dateTo must be 0 |
||
| 290 | $crEventFromTo = new \CriteriaCompo(); |
||
| 291 | $crEventStart = new \CriteriaCompo(); |
||
| 292 | $crEventStart->add(new \Criteria('datefrom', $dateFrom, '>=')); |
||
| 293 | if ($dateTo > 0) { |
||
| 294 | $crEventStart->add(new \Criteria('datefrom', $dateTo, '<=')); |
||
| 295 | } |
||
| 296 | $crEventFromTo->add($crEventStart); |
||
| 297 | $crEventEnd = new \CriteriaCompo(); |
||
| 298 | $crEventEnd->add(new \Criteria('dateto', $dateFrom, '>=')); |
||
| 299 | if ($dateTo > 0) { |
||
| 300 | $crEventEnd->add(new \Criteria('dateto', $dateTo, '<=')); |
||
| 301 | } |
||
| 302 | $crEventFromTo->add($crEventEnd, 'OR'); |
||
| 303 | $crEvent->add($crEventFromTo); |
||
| 304 | |||
| 305 | unset($crEventStart, $crEventEnd, $crEventFromTo); |
||
| 306 | $sortBy = 'datefrom'; |
||
| 307 | $orderBy = 'ASC'; |
||
| 308 | } |
||
| 309 | if (\count($filterCats) > 0) { |
||
| 310 | $crEventCats = new \CriteriaCompo(); |
||
| 311 | $crEventCats->add(new \Criteria('catid', '(' . \implode(',', $filterCats) . ')', 'IN')); |
||
| 312 | foreach ($filterCats as $filterCat) { |
||
| 313 | $crEventCats->add(new \Criteria('subcats', '%"' . $filterCat . '"%', 'LIKE'), 'OR'); |
||
| 314 | } |
||
| 315 | $crEvent->add($crEventCats); |
||
| 316 | } |
||
| 317 | } |
||
| 318 | $crEvent->setSort($sortBy); |
||
| 319 | $crEvent->setOrder($orderBy); |
||
| 320 | $eventsCount = $this->getCount($crEvent); |
||
| 321 | if ($eventsCount > 0) { |
||
| 322 | if ($limit > 0) { |
||
| 323 | $crEvent->setStart($start); |
||
| 324 | $crEvent->setLimit($limit); |
||
| 325 | } |
||
| 326 | // Get All Event |
||
| 327 | $eventsAll = $this->getAll($crEvent); |
||
| 328 | |||
| 329 | return ['count' => $eventsCount, 'eventsAll' => $eventsAll]; |
||
| 330 | } |
||
| 331 | |||
| 332 | return ['count' => 0, 'eventsAll' => []]; |
||
| 333 | } |
||
| 462 |
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