| Conditions | 10 |
| Paths | 27 |
| Total Lines | 55 |
| Code Lines | 36 |
| 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 |
||
| 39 | function b_xoopsfaq_category_show($options) |
||
| 40 | { |
||
| 41 | $moduleDirName = basename(dirname(__DIR__)); |
||
| 42 | |||
| 43 | $myts = \MyTextSanitizer::getInstance(); |
||
| 44 | |||
| 45 | /** @var Xoopsfaq\CategoryHandler $categoryHandler */ /** @var Xoopsfaq\ContentsHandler $contentsHandler */ |
||
| 46 | /** @var Xoopsfaq\Helper $helper */ |
||
| 47 | $helper = \XoopsModules\Xoopsfaq\Helper::getInstance(); |
||
| 48 | $permHelper = new \Xmf\Module\Helper\Permission($moduleDirName); |
||
| 49 | $categoryHandler = $helper->getHandler('Category'); |
||
| 50 | $block = []; |
||
| 51 | |||
| 52 | // Get a list of all cats this user can access |
||
| 53 | $catListArray = $categoryHandler->getList(); |
||
| 54 | $cTu = $catsToUse = array_keys($catListArray); |
||
| 55 | // Remove any cats this user doesn't have rights to view |
||
| 56 | foreach ($cTu as $key => $thisCat) { |
||
| 57 | if (false === $permHelper->checkPermission('viewcat', $thisCat)) { |
||
| 58 | unset($catsToUse[$key]); |
||
| 59 | } |
||
| 60 | } |
||
| 61 | // catsToUse contains all categories user has rights to view |
||
| 62 | |||
| 63 | $criteria = new \CriteriaCompo(); |
||
| 64 | $criteria->setSort('category_order ASC, category_title'); |
||
| 65 | $criteria->order = 'ASC'; |
||
| 66 | if (!isset($options[0]) || 0 === (int)$options[0]) { // only show cats with FAQs |
||
| 67 | $contentsHandler = $helper->getHandler('Contents'); |
||
| 68 | $faqCountArray = $contentsHandler->getCategoriesIdsWithContent(); |
||
| 69 | if (is_array($faqCountArray) && !empty($faqCountArray)) { |
||
| 70 | $catsToShow = array_intersect($catsToUse, array_keys($faqCountArray)); |
||
| 71 | $criteria->add(new \Criteria('category_id', '(' . implode(',', $catsToShow) . ')', 'IN')); |
||
| 72 | } else { |
||
| 73 | // there are no categories to show |
||
| 74 | return $block; |
||
| 75 | } |
||
| 76 | unset($contentsHandler, $faqCountArray, $catsToShow); |
||
| 77 | } else { |
||
| 78 | $criteria->add(new \Criteria('category_id', '(' . implode(',', $catsToUse) . ')', 'IN')); |
||
| 79 | } |
||
| 80 | $fieldsArray = ['category_id', 'category_title']; |
||
| 81 | $catObjArray = $categoryHandler->getAll($criteria, $fieldsArray); |
||
| 82 | $catCount = is_array($catObjArray) ? count($catObjArray) : 0; |
||
|
|
|||
| 83 | if ($catCount > 0) { |
||
| 84 | $block['title'] = _MB_XOOPSFAQ_CATTITLE; |
||
| 85 | foreach ($catObjArray as $cId => $catObj) { |
||
| 86 | $block['cat'][] = [ |
||
| 87 | 'title' => $myts->displayTarea($catObj->getVar('category_title')), |
||
| 88 | 'link' => $helper->url('index.php?cat_id=' . $cId), |
||
| 89 | ]; |
||
| 90 | } |
||
| 91 | } |
||
| 92 | unset($catObjArray, $categoryHandler); |
||
| 93 | return $block; |
||
| 94 | } |
||
| 122 |