| Conditions | 10 |
| Paths | 33 |
| Total Lines | 56 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 42 | function wfdownloads_top_by_cat_show($options) |
||
| 43 | { |
||
| 44 | if (!class_exists(Helper::class)) { |
||
| 45 | return false; |
||
|
|
|||
| 46 | } |
||
| 47 | $helper = Helper::getInstance(); |
||
| 48 | $categoryHandler = new Wfdownloads\CategoryHandler($GLOBALS['xoopsDB']); |
||
| 49 | |||
| 50 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
| 51 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 52 | $groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : [0 => XOOPS_GROUP_ANONYMOUS]; |
||
| 53 | $allowedDownCategoriesIds = $grouppermHandler->getItemIds('WFDownCatPerm', $groups, $helper->getModule()->mid()); |
||
| 54 | |||
| 55 | $block = []; |
||
| 56 | |||
| 57 | // get downloads |
||
| 58 | $criteria = new CriteriaCompo(); |
||
| 59 | $criteria->add(new Criteria('cid', '(' . implode(',', $allowedDownCategoriesIds) . ')', 'IN')); |
||
| 60 | $criteria->add(new Criteria('offline', false)); |
||
| 61 | $criteria->setSort('date'); |
||
| 62 | $criteria->setOrder('DESC'); |
||
| 63 | $criteria->setLimit($options[1]); |
||
| 64 | $downloadObjs = $helper->getHandler('Download')->getObjects($criteria); |
||
| 65 | |||
| 66 | foreach ($downloadObjs as $downloadObj) { |
||
| 67 | $download = $downloadObj->toArray(); |
||
| 68 | if (!in_array((int)$download['cid'], $allowedDownCategoriesIds)) { |
||
| 69 | continue; |
||
| 70 | } |
||
| 71 | $download['title'] = xoops_substr($download['title'], 0, $options[2] - 1); |
||
| 72 | $download['id'] = (int)$download['lid']; |
||
| 73 | if ('published' === $options[0]) { |
||
| 74 | $download['date'] = formatTimestamp($download['published'], $helper->getConfig('dateformat')); |
||
| 75 | } else { |
||
| 76 | $download['date'] = formatTimestamp($download['date'], $helper->getConfig('dateformat')); |
||
| 77 | } |
||
| 78 | $download['dirname'] = $helper->getModule()->dirname(); |
||
| 79 | $block['downloads'][] = $download; |
||
| 80 | } |
||
| 81 | |||
| 82 | $categoriesTopParentByCid = $helper->getHandler('Category')->getAllSubcatsTopParentCid(); |
||
| 83 | |||
| 84 | // foreach ($helper->getHandler('Category')->topCategories as $cid) { |
||
| 85 | if ($categoryHandler->topCategories && is_array($categoryHandler->topCategories)) { |
||
| 86 | foreach ($categoryHandler->topCategories as $cid) { |
||
| 87 | $block['topcats'][$cid]['title'] = $helper->getHandler('Category')->allCategories[$cid]->getVar('title'); |
||
| 88 | $block['topcats'][$cid]['cid'] = $cid; |
||
| 89 | $block['topcats'][$cid]['imgurl'] = $helper->getHandler('Category')->allCategories[$cid]->getVar('imgurl'); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | foreach ($block['downloads'] as $value) { |
||
| 94 | $block['topcats'][$categoriesTopParentByCid[$value['cid']]]['downloads'][] = $value; |
||
| 95 | } |
||
| 96 | |||
| 97 | return $block; |
||
| 98 | } |
||
| 115 |