Conditions | 8 |
Paths | 8 |
Total Lines | 54 |
Code Lines | 31 |
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 |
||
41 | function newbb_notify_iteminfo($category, $item_id) |
||
42 | { |
||
43 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
44 | $moduleHandler = xoops_getHandler('module'); |
||
45 | $module = $moduleHandler->getByDirname('newbb'); |
||
46 | |||
47 | if ('global' === $category) { |
||
48 | $item['name'] = ''; |
||
|
|||
49 | $item['url'] = ''; |
||
50 | |||
51 | return $item; |
||
52 | } |
||
53 | $item_id = (int)$item_id; |
||
54 | |||
55 | if ('forum' === $category) { |
||
56 | // Assume we have a valid forum id |
||
57 | $sql = 'SELECT forum_name FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_forums') . ' WHERE forum_id = ' . $item_id; |
||
58 | if (!$result = $GLOBALS['xoopsDB']->query($sql)) { |
||
59 | // irmtfan full URL |
||
60 | redirect_header(XOOPS_URL . '/modules/' . $module->getVar('dirname') . 'index.php', 2, _MD_NEWBB_ERRORFORUM); |
||
61 | } |
||
62 | $result_array = $GLOBALS['xoopsDB']->fetchArray($result); |
||
63 | $item['name'] = $result_array['forum_name']; |
||
64 | $item['url'] = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/viewforum.php?forum=' . $item_id; |
||
65 | |||
66 | return $item; |
||
67 | } |
||
68 | |||
69 | if ('thread' === $category) { |
||
70 | // Assume we have a valid topid id |
||
71 | $sql = 'SELECT t.topic_title,f.forum_id,f.forum_name FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_topics') . ' t, ' . $GLOBALS['xoopsDB']->prefix('newbb_forums') . ' f WHERE t.forum_id = f.forum_id AND t.topic_id = ' . $item_id . ' LIMIT 1'; |
||
72 | if (!$result = $GLOBALS['xoopsDB']->query($sql)) { |
||
73 | // irmtfan full URL |
||
74 | redirect_header(XOOPS_URL . '/modules/' . $module->getVar('dirname') . 'index.php', 2, _MD_NEWBB_ERROROCCURED); |
||
75 | } |
||
76 | $result_array = $GLOBALS['xoopsDB']->fetchArray($result); |
||
77 | $item['name'] = $result_array['topic_title']; |
||
78 | $item['url'] = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/viewtopic.php?forum=' . $result_array['forum_id'] . '&topic_id=' . $item_id; |
||
79 | |||
80 | return $item; |
||
81 | } |
||
82 | |||
83 | if ('post' === $category) { |
||
84 | // Assume we have a valid post id |
||
85 | $sql = 'SELECT subject,topic_id,forum_id FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_posts') . ' WHERE post_id = ' . $item_id . ' LIMIT 1'; |
||
86 | if (!$result = $GLOBALS['xoopsDB']->query($sql)) { |
||
87 | // irmtfan full URL |
||
88 | redirect_header(XOOPS_URL . '/modules/' . $module->getVar('dirname') . 'index.php', 2, _MD_NEWBB_ERROROCCURED); |
||
89 | } |
||
90 | $result_array = $GLOBALS['xoopsDB']->fetchArray($result); |
||
91 | $item['name'] = $result_array['subject']; |
||
92 | $item['url'] = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/viewtopic.php?forum= ' . $result_array['forum_id'] . '&topic_id=' . $result_array['topic_id'] . '#forumpost' . $item_id; |
||
93 | |||
94 | return $item; |
||
95 | } |
||
98 |