| Conditions | 13 |
| Paths | 72 |
| Total Lines | 85 |
| Code Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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); |
||
| 24 | function b_sitemap_newbb(): array |
||
| 25 | { |
||
| 26 | global $sitemap_configs; |
||
| 27 | $sitemap = []; |
||
| 28 | |||
| 29 | $forumHandler = Helper::getInstance()->getHandler('Forum'); |
||
| 30 | /* Allowed forums */ |
||
| 31 | $forums_allowed = $forumHandler->getIdsByPermission(); |
||
| 32 | |||
| 33 | /* fetch top forums */ |
||
| 34 | $forums_top_id = []; |
||
| 35 | if (!empty($forums_allowed)) { |
||
| 36 | $crit_top = new \CriteriaCompo(new \Criteria('parent_forum', '0')); |
||
| 37 | //$crit_top->add(new \Criteria("cat_id", "(".implode(", ", array_keys($categories)).")", "IN")); |
||
| 38 | $crit_top->add(new \Criteria('forum_id', '(' . implode(', ', $forums_allowed) . ')', 'IN')); |
||
| 39 | $forums_top_id = $forumHandler->getIds($crit_top); |
||
| 40 | } |
||
| 41 | |||
| 42 | $forums_sub_id = []; |
||
| 43 | if ($forums_top_id && $sitemap_configs['show_subcategoris']) { |
||
| 44 | $crit_sub = new \CriteriaCompo(new \Criteria('parent_forum', '(' . implode(', ', $forums_top_id) . ')', 'IN')); |
||
| 45 | $crit_sub->add(new \Criteria('forum_id', '(' . implode(', ', $forums_allowed) . ')', 'IN')); |
||
| 46 | $forums_sub_id = $forumHandler->getIds($crit_sub); |
||
| 47 | } |
||
| 48 | |||
| 49 | /* Fetch forum data */ |
||
| 50 | $forums_available = array_merge($forums_top_id, $forums_sub_id); |
||
| 51 | $forums_array = []; |
||
| 52 | if ($forums_available !== []) { |
||
| 53 | $crit_forum = new \Criteria('forum_id', '(' . implode(', ', $forums_available) . ')', 'IN'); |
||
| 54 | $crit_forum->setSort('cat_id ASC, parent_forum ASC, forum_order'); |
||
| 55 | $crit_forum->setOrder('ASC'); |
||
| 56 | $forums_array = $forumHandler->getAll($crit_forum, ['forum_name', 'parent_forum', 'cat_id'], false); |
||
| 57 | } |
||
| 58 | |||
| 59 | $forums = []; |
||
| 60 | foreach ($forums_array as $forumid => $forum) { |
||
| 61 | if ($forum['parent_forum']) { |
||
| 62 | $forums[$forum['parent_forum']]['fchild'][$forumid] = [ |
||
| 63 | 'id' => $forumid, |
||
| 64 | 'url' => 'viewforum.php?forum=' . $forumid, |
||
| 65 | 'title' => $forum['forum_name'], |
||
| 66 | ]; |
||
| 67 | } else { |
||
| 68 | $forums[$forumid] = [ |
||
| 69 | 'id' => $forumid, |
||
| 70 | 'cid' => $forum['cat_id'], |
||
| 71 | 'url' => 'viewforum.php?forum=' . $forumid, |
||
| 72 | 'title' => $forum['forum_name'], |
||
| 73 | ]; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | if ($sitemap_configs['show_subcategoris']) { |
||
| 78 | $categoryHandler = Helper::getInstance()->getHandler('Category'); |
||
| 79 | $categories = []; |
||
|
|
|||
| 80 | $categories = $categoryHandler->getByPermission('access', ['cat_id', 'cat_title'], false); |
||
| 81 | |||
| 82 | foreach ($categories as $key => $category) { |
||
| 83 | $cat_id = $category['cat_id']; |
||
| 84 | $i = $cat_id; |
||
| 85 | $sitemap['parent'][$i]['id'] = $cat_id; |
||
| 86 | $sitemap['parent'][$i]['title'] = $category['cat_title']; |
||
| 87 | $sitemap['parent'][$i]['url'] = XOOPS_URL . '/modules/newbb/index.php?cat=' . $cat_id; |
||
| 88 | } |
||
| 89 | foreach ($forums as $id => $forum) { |
||
| 90 | $cid = $forum['cid']; |
||
| 91 | $sitemap['parent'][$cid]['child'][$id] = $forum; |
||
| 92 | $sitemap['parent'][$cid]['child'][$id]['image'] = 2; |
||
| 93 | if (empty($forum['fchild'])) { |
||
| 94 | continue; |
||
| 95 | } |
||
| 96 | |||
| 97 | foreach ($forum['fchild'] as $_id => $_forum) { |
||
| 98 | $sitemap['parent'][$cid]['child'][$_id] = $_forum; |
||
| 99 | $sitemap['parent'][$cid]['child'][$_id]['image'] = 3; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } else { |
||
| 103 | foreach ($forums as $id => $forum) { |
||
| 104 | $sitemap['parent'][$id] = $forum; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | return $sitemap; |
||
| 109 | } |
||
| 110 |