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