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