Conditions | 11 |
Paths | 14 |
Total Lines | 55 |
Code Lines | 38 |
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); |
||
27 | function b_news_topicsnav_show($options) |
||
28 | { |
||
29 | /** @var Helper $helper */ |
||
30 | if (!class_exists(Helper::class)) { |
||
31 | return false; |
||
|
|||
32 | } |
||
33 | |||
34 | $helper = Helper::getInstance(); |
||
35 | |||
36 | $myts = \MyTextSanitizer::getInstance(); |
||
37 | $block = []; |
||
38 | $newscountbytopic = []; |
||
39 | $perms = ''; |
||
40 | $xt = new NewsTopic(); |
||
41 | $restricted = News\Utility::getModuleOption('restrictindex'); |
||
42 | if ($restricted) { |
||
43 | global $xoopsUser; |
||
44 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
45 | $moduleHandler = xoops_getHandler('module'); |
||
46 | $newsModule = $moduleHandler->getByDirname('news'); |
||
47 | $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
48 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
49 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
50 | $topics = $grouppermHandler->getItemIds('news_view', $groups, $newsModule->getVar('mid')); |
||
51 | if (count($topics) > 0) { |
||
52 | $topics = implode(',', $topics); |
||
53 | $perms = ' AND topic_id IN (' . $topics . ') '; |
||
54 | } else { |
||
55 | return ''; |
||
56 | } |
||
57 | } |
||
58 | $topics_arr = $xt->getChildTreeArray(0, 'topic_title', $perms); |
||
59 | if (1 == $options[0]) { |
||
60 | $newscountbytopic = $xt->getNewsCountByTopic(); |
||
61 | } |
||
62 | if (is_array($topics_arr) && count($topics_arr)) { |
||
63 | foreach ($topics_arr as $onetopic) { |
||
64 | if (1 == $options[0]) { |
||
65 | $count = 0; |
||
66 | if (array_key_exists($onetopic['topic_id'], $newscountbytopic)) { |
||
67 | $count = $newscountbytopic[$onetopic['topic_id']]; |
||
68 | } |
||
69 | } else { |
||
70 | $count = ''; |
||
71 | } |
||
72 | $block['topics'][] = [ |
||
73 | 'id' => $onetopic['topic_id'], |
||
74 | 'news_count' => $count, |
||
75 | 'topic_color' => '#' . $onetopic['topic_color'], |
||
76 | 'title' => $myts->displayTarea($onetopic['topic_title']), |
||
77 | ]; |
||
78 | } |
||
79 | } |
||
80 | |||
81 | return $block; |
||
82 | } |
||
117 |