| Conditions | 7 |
| Paths | 4 |
| Total Lines | 78 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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); |
||
| 18 | function b_faqs_recent_show($options) |
||
| 19 | { |
||
| 20 | // require_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/functions.php'; |
||
| 21 | $myts = \MyTextSanitizer::getInstance(); |
||
|
|
|||
| 22 | |||
| 23 | /** @var \XoopsModules\Smartfaq\Helper $helper */ |
||
| 24 | $helper = Helper::getInstance(); |
||
| 25 | $smartModule = $helper->getModule(); |
||
| 26 | $smartModuleConfig = $helper->getConfig(); |
||
| 27 | |||
| 28 | $block = []; |
||
| 29 | |||
| 30 | if (0 == $options[0]) { |
||
| 31 | $categoryid = -1; |
||
| 32 | } else { |
||
| 33 | $categoryid = $options[0]; |
||
| 34 | } |
||
| 35 | |||
| 36 | $sort = $options[1]; |
||
| 37 | $limit = $options[2]; |
||
| 38 | $maxQuestionLength = $options[3]; |
||
| 39 | |||
| 40 | // Creating the faq handler object |
||
| 41 | /** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */ |
||
| 42 | $faqHandler = $helper->getHandler('Faq'); |
||
| 43 | |||
| 44 | // Creating the category handler object |
||
| 45 | /** @var \XoopsModules\Smartfaq\CategoryHandler $categoryHandler */ |
||
| 46 | $categoryHandler = $helper->getHandler('Category'); |
||
| 47 | |||
| 48 | // Creating the last FAQs |
||
| 49 | $faqsObj = $faqHandler->getAllPublished($limit, 0, $categoryid, $sort); |
||
| 50 | $allcategories = $categoryHandler->getObjects(null, true); |
||
| 51 | if ($faqsObj) { |
||
| 52 | $userids = []; |
||
| 53 | foreach ($faqsObj as $key => $thisfaq) { |
||
| 54 | $faqids[] = $thisfaq->getVar('faqid'); |
||
| 55 | $userids[$thisfaq->uid()] = 1; |
||
| 56 | } |
||
| 57 | /** @var \XoopsModules\Smartfaq\AnswerHandler $answerHandler */ |
||
| 58 | $answerHandler = $helper->getHandler('Answer'); |
||
| 59 | $allanswers = $answerHandler->getLastPublishedByFaq($faqids); |
||
| 60 | |||
| 61 | foreach ($allanswers as $key => $thisanswer) { |
||
| 62 | $userids[$thisanswer->uid()] = 1; |
||
| 63 | } |
||
| 64 | |||
| 65 | /** @var \XoopsMemberHandler $memberHandler */ |
||
| 66 | $memberHandler = xoops_getHandler('member'); |
||
| 67 | $users = $memberHandler->getUsers(new \Criteria('uid', '(' . implode(',', array_keys($userids)) . ')', 'IN'), true); |
||
| 68 | foreach ($faqsObj as $iValue) { |
||
| 69 | $faqs['categoryid'] = $iValue->categoryid(); |
||
| 70 | $faqs['question'] = $iValue->question($maxQuestionLength); |
||
| 71 | $faqs['faqid'] = $iValue->faqid(); |
||
| 72 | $faqs['categoryname'] = $allcategories[$iValue->categoryid()]->getVar('name'); |
||
| 73 | |||
| 74 | // Creating the answer object |
||
| 75 | $faqid = $iValue->faqid(); |
||
| 76 | $answerObj = $allanswers[$faqid]; |
||
| 77 | |||
| 78 | $faqs['date'] = $iValue->datesub(); |
||
| 79 | $faqs['poster'] = ''; |
||
| 80 | if (null !== $answerObj) { |
||
| 81 | $faqs['poster'] = Smartfaq\Utility::getLinkedUnameFromId($answerObj->uid(), $smartModuleConfig['userealname'], $users); |
||
| 82 | } |
||
| 83 | |||
| 84 | $block['faqs'][] = $faqs; |
||
| 85 | } |
||
| 86 | |||
| 87 | $block['lang_question'] = _MB_SF_FAQS; |
||
| 88 | $block['lang_category'] = _MB_SF_CATEGORY; |
||
| 89 | $block['lang_poster'] = _MB_SF_ANSWEREDBY; |
||
| 90 | $block['lang_date'] = _MB_SF_DATE; |
||
| 91 | $modulename = htmlspecialchars($smartModule->getVar('name'), ENT_QUOTES | ENT_HTML5); |
||
| 92 | $block['lang_visitfaq'] = _MB_SF_VISITFAQ . ' ' . $modulename; |
||
| 93 | } |
||
| 94 | |||
| 95 | return $block; |
||
| 96 | } |
||
| 135 |