Conditions | 10 |
Paths | 16 |
Total Lines | 62 |
Code Lines | 40 |
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 |
||
26 | function lookup($category, $item_id) |
||
27 | { |
||
28 | global $xoopsModule, $xoopsModuleConfig, $xoopsConfig; |
||
29 | $moduleDirName = \basename(\dirname(__DIR__)); |
||
30 | if (empty($xoopsModule) || $xoopsModule->getVar('dirname') !== $moduleDirName) { |
||
31 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
32 | $moduleHandler = xoops_getHandler('module'); |
||
33 | $module = $moduleHandler->getByDirname($moduleDirName); |
||
34 | /** @var \XoopsConfigHandler $configHandler */ |
||
35 | $configHandler = xoops_getHandler('config'); |
||
36 | $config = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
||
|
|||
37 | } else { |
||
38 | $module = $xoopsModule; |
||
39 | $config = $xoopsModuleConfig; |
||
40 | } |
||
41 | |||
42 | if ('global' === $category) { |
||
43 | $item['name'] = ''; |
||
44 | $item['url'] = ''; |
||
45 | |||
46 | return $item; |
||
47 | } |
||
48 | $item_id = (int)$item_id; |
||
49 | |||
50 | global $xoopsDB; |
||
51 | if ('dog' === $category) { |
||
52 | // Assume we have a valid forum id |
||
53 | $sql = 'SELECT pname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' WHERE id = ' . $item_id; |
||
54 | if (!$result = $GLOBALS['xoopsDB']->query($sql)) { |
||
55 | redirect_header('index.php', 2, _MD_ERRORFORUM); |
||
56 | } |
||
57 | $result_array = $GLOBALS['xoopsDB']->fetchArray($result); |
||
58 | $item['name'] = $result_array['pname']; |
||
59 | $item['url'] = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/dog.php?id=' . $item_id; |
||
60 | |||
61 | return $item; |
||
62 | } |
||
63 | |||
64 | if ('thread' === $category) { |
||
65 | // Assume we have a valid topid id |
||
66 | $sql = 'SELECT t.topic_title,f.forum_id,f.forum_name FROM ' . $GLOBALS['xoopsDB']->prefix('bb_topics') . ' t, ' . $GLOBALS['xoopsDB']->prefix('bb_forums') . ' f WHERE t.forum_id = f.forum_id AND t.topic_id = ' . $item_id . ' LIMIT 1'; |
||
67 | if (!$result = $GLOBALS['xoopsDB']->query($sql)) { |
||
68 | redirect_header('index.php', 2, _MD_ERROROCCURED); |
||
69 | } |
||
70 | $result_array = $GLOBALS['xoopsDB']->fetchArray($result); |
||
71 | $item['name'] = $result_array['topic_title']; |
||
72 | $item['url'] = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/viewtopic.php?forum=' . $result_array['forum_id'] . '&topic_id=' . $item_id; |
||
73 | |||
74 | return $item; |
||
75 | } |
||
76 | |||
77 | if ('post' === $category) { |
||
78 | // Assume we have a valid post id |
||
79 | $sql = 'SELECT subject,topic_id,forum_id FROM ' . $GLOBALS['xoopsDB']->prefix('bb_posts') . ' WHERE post_id = ' . $item_id . ' LIMIT 1'; |
||
80 | if (!$result = $GLOBALS['xoopsDB']->query($sql)) { |
||
81 | redirect_header('index.php', 2, _MD_ERROROCCURED); |
||
82 | } |
||
83 | $result_array = $GLOBALS['xoopsDB']->fetchArray($result); |
||
84 | $item['name'] = $result_array['subject']; |
||
85 | $item['url'] = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/viewtopic.php?forum= ' . $result_array['forum_id'] . '&topic_id=' . $result_array['topic_id'] . '#forumpost' . $item_id; |
||
86 | |||
87 | return $item; |
||
88 | } |
||
90 |