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