Conditions | 7 |
Paths | 32 |
Total Lines | 64 |
Code Lines | 39 |
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); |
||
60 | function addFaq_display() |
||
61 | { |
||
62 | global $xoopsOption, $xoopsTpl, $xoopsConfig, $xoopsUser, $xoopsLogger, $xoopsUserIsAdmin, $session, $staff; |
||
63 | $helper = Xhelp\Helper::getInstance(); |
||
64 | |||
65 | if (!isset($_POST['ticketid']) && 0 === Request::getInt('ticketid', 0, 'POST')) { |
||
66 | $helper->redirect('', 3, _XHELP_MSG_NO_ID); |
||
67 | } |
||
68 | $ticketid = Request::getInt('ticketid', 0, 'POST'); |
||
69 | /** @var \XoopsModules\Xhelp\TicketHandler $ticketHandler */ |
||
70 | $ticketHandler = $helper->getHandler('Ticket'); |
||
71 | /** @var \XoopsModules\Xhelp\ResponseHandler $responseHandler */ |
||
72 | $responseHandler = $helper->getHandler('Response'); |
||
73 | $ticket = $ticketHandler->get($ticketid); |
||
74 | |||
75 | if (!$hasRights = $staff->checkRoleRights(XHELP_SEC_FAQ_ADD, $ticket->getVar('department'))) { |
||
|
|||
76 | $helper->redirect("ticket.php?id=$ticketid", 3, _AM_XHELP_MESSAGE_NO_ADD_FAQ); |
||
77 | } |
||
78 | |||
79 | $GLOBALS['xoopsOption']['template_main'] = 'xhelp_addFaq.tpl'; |
||
80 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||
81 | |||
82 | $criteria = new \Criteria('ticketid', $ticketid); |
||
83 | $responses = $responseHandler->getObjects($criteria, true); |
||
84 | $responseText = ''; |
||
85 | |||
86 | $allUsers = []; |
||
87 | foreach ($responses as $response) { |
||
88 | $allUsers[$response->getVar('uid')] = ''; |
||
89 | } |
||
90 | |||
91 | $criteria = new \Criteria('uid', '(' . implode(',', array_keys($allUsers)) . ')', 'IN'); |
||
92 | $users = Xhelp\Utility::getUsers($criteria, $helper->getConfig('xhelp_displayName')); |
||
93 | unset($allUsers); |
||
94 | |||
95 | foreach ($responses as $response) { |
||
96 | $responseText .= sprintf(_XHELP_TEXT_USER_SAID, $users[$response->getVar('uid')]) . "\n"; |
||
97 | $responseText .= $response->getVar('message', 'e') . "\n"; |
||
98 | } |
||
99 | |||
100 | // Get current faq adapter |
||
101 | /** @var \XoopsModules\Xhelp\FaqAdapterAbstract $oAdapter */ |
||
102 | $oAdapter = Xhelp\FaqAdapterFactory::getFaqAdapter(); |
||
103 | if (!$oAdapter) { |
||
104 | $helper->redirect('', 3, _XHELP_MESSAGE_NO_FAQ); |
||
105 | } |
||
106 | $categories = &$oAdapter->getCategories(); |
||
107 | |||
108 | $tree = new Xhelp\Tree($categories, 'id', 'parent'); |
||
109 | |||
110 | // $xoopsTpl->assign('xhelp_categories', $tree->makeSelBox('categories', 'name', '--', 0, false, 0, $oAdapter->categoryType)); |
||
111 | |||
112 | $categorySelect = $tree->makeSelectElement('categories', 'name', '--', 0, false, 0, $oAdapter->categoryType, ''); |
||
113 | $xoopsTpl->assign('xhelp_categories', $categorySelect->render()); |
||
114 | |||
115 | $xoopsTpl->assign('xhelp_imagePath', XHELP_IMAGE_URL . '/'); |
||
116 | $xoopsTpl->assign('xhelp_baseURL', XHELP_BASE_URL); |
||
117 | $xoopsTpl->assign('xhelp_faqProblem', $ticket->getVar('description', 'e')); |
||
118 | $xoopsTpl->assign('xhelp_faqSolution', $responseText); |
||
119 | $xoopsTpl->assign('xhelp_hasMultiCats', $oAdapter->categoryType); |
||
120 | $xoopsTpl->assign('xhelp_ticketID', $ticketid); |
||
121 | $xoopsTpl->assign('xhelp_faqSubject', $ticket->getVar('subject', 'e')); |
||
122 | |||
123 | require_once XOOPS_ROOT_PATH . '/footer.php'; |
||
124 | } |
||
159 |