| Conditions | 11 |
| Paths | 8 |
| Total Lines | 52 |
| Code Lines | 35 |
| 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); |
||
| 36 | function newbbForumSelectBox($value = null, string $permission = 'access', bool $categoryDelimiter = true, bool $see = false): string |
||
| 37 | { |
||
| 38 | global $xoopsUser; |
||
| 39 | $categoryHandler = Helper::getInstance()->getHandler('Category'); |
||
| 40 | $categories = $categoryHandler->getByPermission($permission, ['cat_id', 'cat_order', 'cat_title'], false); |
||
| 41 | |||
| 42 | $cacheHelper = new Cache('newbb'); |
||
| 43 | |||
| 44 | $groups = [XOOPS_GROUP_ANONYMOUS]; |
||
| 45 | if (is_object($xoopsUser)) { |
||
| 46 | $groups = $xoopsUser->getGroups(); |
||
| 47 | } |
||
| 48 | sort($groups); |
||
| 49 | $groupKey = 'forumselect_' . $permission . '_' . md5(implode(',', $groups)); |
||
| 50 | $forums = $cacheHelper->cacheRead( |
||
| 51 | $groupKey, |
||
| 52 | static function () use ($categories, $permission) { |
||
|
|
|||
| 53 | $categoryHandler = Helper::getInstance()->getHandler('Category'); |
||
| 54 | $categories = $categoryHandler->getByPermission($permission, ['cat_id', 'cat_order', 'cat_title'], false); |
||
| 55 | $forumHandler = Helper::getInstance()->getHandler('Forum'); |
||
| 56 | $forums = $forumHandler->getTree(array_keys($categories), 0, 'all'); |
||
| 57 | |||
| 58 | return $forums; |
||
| 59 | }, |
||
| 60 | 300 |
||
| 61 | ); |
||
| 62 | |||
| 63 | $value = is_array($value) ? $value : [$value]; |
||
| 64 | //$see = is_array($see) ? $see : array($see); |
||
| 65 | $box = ''; |
||
| 66 | if (is_iterable($forums)) { |
||
| 67 | foreach (array_keys($categories) as $key) { |
||
| 68 | if ($categoryDelimiter) { |
||
| 69 | $box .= "<option value=0> </option>\n"; |
||
| 70 | } |
||
| 71 | $box .= "<option value='" . (-1 * $key) . "'>[" . $categories[$key]['cat_title'] . "]</option>\n"; |
||
| 72 | if (empty($forums[$key])) { |
||
| 73 | continue; |
||
| 74 | } |
||
| 75 | foreach ($forums[$key] as $f => $forum) { |
||
| 76 | if ($see && in_array($f, $value, true)) { |
||
| 77 | continue; |
||
| 78 | } |
||
| 79 | $box .= "<option value='{$f}' " . (in_array($f, $value, true) ? ' selected' : '') . '>' . $forum['prefix'] . $forum['forum_name'] . "</option>\n"; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | } else { |
||
| 83 | $box .= '<option value=0>' . _MD_NEWBB_NOFORUMINDB . "</option>\n"; |
||
| 84 | } |
||
| 85 | unset($forums, $categories); |
||
| 86 | |||
| 87 | return $box; |
||
| 88 | } |
||
| 223 |
This check looks for imports that have been defined, but are not used in the scope.