| Conditions | 7 |
| Paths | 8 |
| Total Lines | 116 |
| Code Lines | 79 |
| 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); |
||
| 111 | function newbb_list_topic_edit(array $options ): string |
||
| 112 | { |
||
| 113 | // require_once $GLOBALS['xoops']->path('class/blockform.php'); //reserve for 2.6 |
||
| 114 | xoops_load('XoopsFormLoader'); |
||
| 115 | // $form = new \XoopsBlockForm(); //reserve for 2.6 |
||
| 116 | $form = new \XoopsThemeForm(_MB_NEWBB_DISPLAYMODE_DESC, 'list_topic', ''); |
||
| 117 | |||
| 118 | $topicRenderer = new TopicRenderer(); |
||
| 119 | $topicRenderer->userlevel = 2; // 2 - moderator or admin |
||
| 120 | |||
| 121 | // status element |
||
| 122 | $optionsStatus = explode(',', (string) $options[0]); |
||
| 123 | $statusEle = new \XoopsFormSelect(_MB_NEWBB_CRITERIA, 'options[0]', $optionsStatus, 5, true); |
||
| 124 | $status = $topicRenderer->getStatus($topicRenderer->userlevel); // get all public status + admin status (admin mode, pending deleted) |
||
| 125 | $statusEle->addOptionArray($status); |
||
| 126 | $statusEle->setExtra("onchange = \"validate('options[0][]','select', true)\""); // if user dont select any option it select "all" |
||
| 127 | $statusEle->setDescription(_MB_NEWBB_CRITERIA_DESC); |
||
| 128 | |||
| 129 | // topic_poster element |
||
| 130 | $topicPosterRadioEle = new \XoopsFormRadio(_MB_NEWBB_AUTHOR, 'options[1]', $options[1]); |
||
| 131 | $topicPosterRadioEle->addOption('-1', _MD_NEWBB_TOTALUSER); |
||
| 132 | $topicPosterRadioEle->addOption((-1 !== $options[1]) ? $options[1] : 0, _SELECT); // if no user in selection box it select uid=0 anon users |
||
| 133 | $topicPosterRadioEle->setExtra("onchange=\"var el=document.getElementById('options[1]'); el.disabled=(this.id == 'options[1]1'); if (!el.value) {el.value= this.value}\""); // if user dont select any option it select "all" |
||
| 134 | $topicPosterSelectEle = new \XoopsFormSelectUser(_MB_NEWBB_AUTHOR, 'options[1]', true, explode(',', (string) $options[1]), 5, true); // show $limit = 200 users when no user is selected; |
||
| 135 | $topicPosterEle = new \XoopsFormLabel(_MB_NEWBB_AUTHOR, $topicPosterRadioEle->render() . $topicPosterSelectEle->render()); |
||
| 136 | |||
| 137 | // lastposter element |
||
| 138 | $lastPosterRadioEle = new \XoopsFormRadio(_MD_NEWBB_POSTER, 'options[2]', $options[2]); |
||
| 139 | $lastPosterRadioEle->addOption('-1', _MD_NEWBB_TOTALUSER); |
||
| 140 | $lastPosterRadioEle->addOption((-1 !== $options[2]) ? $options[2] : 0, _SELECT); // if no user in selection box it select uid=1 |
||
| 141 | $lastPosterRadioEle->setExtra("onchange=\"var el=document.getElementById('options[2]'); el.disabled=(this.id == 'options[2]1'); if (!el.value) {el.value= this.value}\""); // if user dont select any option it select "all" |
||
| 142 | $lastPosterSelectEle = new \XoopsFormSelectUser(_MD_NEWBB_POSTER, 'options[2]', true, explode(',', (string) $options[2]), 5, true); // show $limit = 200 users when no user is selected; |
||
| 143 | $lastPosterEle = new \XoopsFormLabel(_MD_NEWBB_POSTER, $lastPosterRadioEle->render() . $lastPosterSelectEle->render()); |
||
| 144 | |||
| 145 | // type element |
||
| 146 | $types = $topicRenderer->getTypes(); // get all available types in all forums |
||
| 147 | $typeEle = new \XoopsFormSelect(_MD_NEWBB_TYPE, 'options[3]', $options[3]); |
||
| 148 | $typeEle->addOption('0', _NONE); |
||
| 149 | if (!empty($types)) { |
||
| 150 | foreach ($types as $type_id => $type) { |
||
| 151 | $typeEle->addOption($type_id, $type['type_name']); |
||
| 152 | } |
||
| 153 | } |
||
| 154 | |||
| 155 | // sort element |
||
| 156 | $sortEle = new \XoopsFormSelect(_MD_NEWBB_SORTBY, 'options[4]', $options[4]); |
||
| 157 | $sortEle->setDescription(_MB_NEWBB_CRITERIA_SORT_DESC); |
||
| 158 | $sorts = $topicRenderer->getSort('', 'title'); |
||
|
|
|||
| 159 | $sortEle->addOptionArray($sorts); |
||
| 160 | |||
| 161 | // order element |
||
| 162 | $orderEle = new \XoopsFormSelect(_MB_NEWBB_CRITERIA_ORDER, 'options[5]', $options[5]); |
||
| 163 | $orderEle->addOption('0', _DESCENDING); |
||
| 164 | $orderEle->addOption('1', _ASCENDING); |
||
| 165 | |||
| 166 | // number of topics to display element |
||
| 167 | $numdispEle = new \XoopsFormText(_MB_NEWBB_DISPLAY, 'options[6]', 10, 255, (string)$options[6]); |
||
| 168 | |||
| 169 | $timeEle = new \XoopsFormText(_MB_NEWBB_TIME, 'options[7]', 10, 255, $options[7]); |
||
| 170 | $timeEle->setDescription(_MB_NEWBB_TIME_DESC); |
||
| 171 | |||
| 172 | // mode disp element |
||
| 173 | $options_headers = explode(',', (string) $options[8]); |
||
| 174 | $modeEle = new \XoopsFormCheckBox(_MB_NEWBB_DISPLAYMODE, 'options[8][]', $options_headers); |
||
| 175 | $modeEle->setDescription(_MB_NEWBB_DISPLAYMODE_DESC); |
||
| 176 | $modeEle->columns = 4; |
||
| 177 | $disps = $topicRenderer->getHeader(); |
||
| 178 | $modeEle->addOptionArray($disps); |
||
| 179 | $modeEle->setExtra("onchange = \"validate('options[8][]','checkbox', true)\""); // prevent user select no option |
||
| 180 | // Index navigation element |
||
| 181 | $navEle = new \XoopsFormRadioYN(_MB_NEWBB_INDEXNAV, 'options[9]', $options[9]); |
||
| 182 | |||
| 183 | // Topic title element |
||
| 184 | $lengthEle = new \XoopsFormText(_MB_NEWBB_TITLE_LENGTH, 'options[10]', 10, 255, $options[10]); |
||
| 185 | $lengthEle->setDescription(_MB_NEWBB_TITLE_LENGTH_DESC); |
||
| 186 | |||
| 187 | // Post text element |
||
| 188 | $postExcerptEle = new \XoopsFormText(_MB_NEWBB_POST_EXCERPT, 'options[11]', 10, 255, $options[11]); |
||
| 189 | $postExcerptEle->setDescription(_MB_NEWBB_POST_EXCERPT_DESC); |
||
| 190 | |||
| 191 | // forum element |
||
| 192 | $optionsForum = explode(',', (string) $options[12]); |
||
| 193 | require_once \dirname(__DIR__) . '/include/functions.forum.php'; |
||
| 194 | $forumHandler = Helper::getInstance()->getHandler('Forum'); |
||
| 195 | assert($forumHandler instanceof ForumHandler); |
||
| 196 | //get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums |
||
| 197 | // Get accessible forums |
||
| 198 | $accessForums = $forumHandler->getIdsByValues(array_map('\intval', $optionsForum)); |
||
| 199 | $isAll = (0 === count($optionsForum) || empty($optionsForum[0])); |
||
| 200 | $forumSel = "<select name=\"options[12][]\" multiple=\"multiple\" onchange = \"validate('options[12][]','select', true)\">"; // if user dont select any it select "0" |
||
| 201 | $forumSel .= '<option value="0" '; |
||
| 202 | if ($isAll) { |
||
| 203 | $forumSel .= ' selected'; |
||
| 204 | $accessForums = null; // just select _ALL option |
||
| 205 | } |
||
| 206 | $forumSel .= '>' . _ALL . '</option>'; |
||
| 207 | $forumSel .= newbbForumSelectBox($accessForums, 'access', false); //$accessForums, $permission = "access", $delimitorCategory = false |
||
| 208 | $forumSel .= '</select>'; |
||
| 209 | $forumEle = new \XoopsFormLabel(_MB_NEWBB_FORUMLIST, $forumSel); |
||
| 210 | |||
| 211 | // add all elements to form |
||
| 212 | $form->addElement($statusEle); |
||
| 213 | $form->addElement($topicPosterEle); |
||
| 214 | $form->addElement($lastPosterEle); |
||
| 215 | $form->addElement($typeEle); |
||
| 216 | $form->addElement($sortEle); |
||
| 217 | $form->addElement($orderEle); |
||
| 218 | $form->addElement($numdispEle); |
||
| 219 | $form->addElement($timeEle); |
||
| 220 | $form->addElement($modeEle, true); // required: user should select at least one otherwise it will select the first one |
||
| 221 | $form->addElement($navEle); |
||
| 222 | $form->addElement($lengthEle); |
||
| 223 | $form->addElement($postExcerptEle); |
||
| 224 | $form->addElement($forumEle); |
||
| 225 | |||
| 226 | return $form->render(); |
||
| 227 | } |
||
| 228 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.