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