Conditions | 13 |
Paths | 132 |
Total Lines | 70 |
Code Lines | 49 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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); |
||
44 | function b_xoopsfaq_recent_show(array $options) |
||
45 | { |
||
46 | $moduleDirName = \basename(\dirname(__DIR__)); |
||
47 | |||
48 | $myts = \MyTextSanitizer::getInstance(); |
||
49 | |||
50 | /** @var Helper $helper */ |
||
51 | $helper = Helper::getInstance(); |
||
52 | $contentsHandler = $helper->getHandler('Contents'); |
||
53 | $permHelper = new Permission($moduleDirName); |
||
54 | $block = []; |
||
55 | |||
56 | $criteria = new \CriteriaCompo(); |
||
57 | $criteria->add(new \Criteria('contents_active', Constants::ACTIVE, '=')); |
||
58 | $criteria->setSort('contents_publish DESC, contents_weight'); |
||
59 | $criteria->order = 'ASC'; |
||
60 | $criteria->setLimit($options[0]); |
||
61 | |||
62 | $options[3] = $options[3] ?? [0]; |
||
63 | $cTu = $catsToUse = (false === mb_strpos($options[3], ',')) ? (array)$options[3] : explode(',', $options[3]); |
||
64 | if (in_array(0, $catsToUse, true) || empty($catsToUse)) { |
||
65 | // Get a list of all cats |
||
66 | $categoryHandler = $helper->getHandler('Category'); |
||
67 | $catListArray = $categoryHandler->getList(); |
||
68 | $cTu = $catsToUse = array_keys($catListArray); |
||
69 | } |
||
70 | // Remove any cats this user doesn't have rights to view |
||
71 | foreach ($cTu as $key => $thisCat) { |
||
72 | if (false === $permHelper->checkPermission('viewcat', $thisCat)) { |
||
73 | unset($catsToUse[$key]); |
||
74 | } |
||
75 | } |
||
76 | if (!empty($catsToUse)) { |
||
77 | $criteria->add(new \Criteria('contents_cid', '(' . implode(',', $catsToUse) . ')', 'IN')); |
||
78 | } else { |
||
79 | return $block; |
||
80 | } |
||
81 | |||
82 | $fieldsArray = ['contents_cid', 'contents_title', 'contents_contents']; |
||
83 | $faqObjArray = $contentsHandler->getAll($criteria, $fieldsArray); |
||
84 | $faqCount = is_array($faqObjArray) ? count($faqObjArray) : 0; |
||
85 | if ($faqCount > 0) { |
||
86 | $block['title'] = _MB_XOOPSFAQ_RECENT_TITLE; |
||
87 | $block['show_date'] = (isset($options[2]) && $options[2] > 0) ? 1 : 0; |
||
88 | foreach ($faqObjArray as $fId => $faqObj) { |
||
89 | $faqTitle = $myts->displayTarea($faqObj->getVar('contents_title')); |
||
90 | if (!empty($options[1])) { |
||
91 | $txtAns = strip_tags($faqObj->getVar('contents_contents')); // get rid of html for block |
||
92 | $faqAns = $myts->displayTarea(xoops_substr($txtAns, 0, $options[1]), 0, 0, 0, 0, 0); |
||
93 | } else { |
||
94 | $faqAns = $myts->displayTarea( |
||
95 | $faqObj->getVar('contents_contents'), |
||
96 | (int)$faqObj->getVar('dohtml'), |
||
97 | (int)$faqObj->getVar('dosmiley'), |
||
98 | (int)$faqObj->getVar('doxcode'), |
||
99 | 1, |
||
100 | (int)$faqObj->getVar('dobr') |
||
101 | ); |
||
102 | } |
||
103 | $block['faq'][] = [ |
||
104 | 'title' => $faqTitle, |
||
105 | 'ans' => $faqAns, |
||
106 | 'published' => $faqObj->getPublished(_SHORTDATESTRING), |
||
107 | 'id' => $faqObj->getVar('contents_id'), |
||
108 | 'cid' => $faqObj->getVar('contents_cid'), |
||
109 | ]; |
||
110 | } |
||
111 | } |
||
112 | |||
113 | return $block; |
||
114 | } |
||
182 |