Conditions | 8 |
Paths | 12 |
Total Lines | 53 |
Code Lines | 32 |
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 |
||
17 | function wflinks_notify_iteminfo($category, $item_id) |
||
18 | { |
||
19 | $moduleDirName = basename(dirname(__DIR__)); |
||
20 | global $xoopsModule, $xoopsModuleConfig, $xoopsConfig; |
||
21 | |||
22 | if (empty($xoopsModule) || $xoopsModule->getVar('dirname') != $moduleDirName) { |
||
23 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
24 | $moduleHandler = xoops_getHandler('module'); |
||
25 | $module = $moduleHandler->getByDirname($moduleDirName); |
||
26 | /* @var \XoopsConfigHandler $configHandler */ |
||
27 | /** @var \XoopsConfigHandler $configHandler */ |
||
28 | $configHandler = xoops_getHandler('config'); |
||
29 | $config = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
||
|
|||
30 | } else { |
||
31 | $module = $xoopsModule; |
||
32 | $config = $xoopsModuleConfig; |
||
33 | } |
||
34 | |||
35 | if ('global' === $category) { |
||
36 | $item['name'] = ''; |
||
37 | $item['url'] = ''; |
||
38 | |||
39 | return $item; |
||
40 | } |
||
41 | |||
42 | global $xoopsDB; |
||
43 | if ('category' === $category) { |
||
44 | // Assume we have a valid category id |
||
45 | $sql = 'SELECT title FROM ' . $xoopsDB->prefix('wflinks_cat') . ' WHERE cid=' . $item_id; |
||
46 | if (!$result = $xoopsDB->query($sql)) { |
||
47 | return false; |
||
48 | } |
||
49 | $result_array = $xoopsDB->fetchArray($result); |
||
50 | $item['name'] = $result_array['title']; |
||
51 | $item['url'] = XOOPS_URL . '/modules/' . $moduleDirName . '/viewcat.php?cid=' . $item_id; |
||
52 | |||
53 | return $item; |
||
54 | } |
||
55 | |||
56 | if ('link' === $category) { |
||
57 | // Assume we have a valid file id |
||
58 | $sql = 'SELECT cid,title FROM ' . $xoopsDB->prefix('wflinks_links') . ' WHERE lid=' . $item_id; |
||
59 | if (!$result = $xoopsDB->query($sql)) { |
||
60 | return false; |
||
61 | } |
||
62 | $result_array = $xoopsDB->fetchArray($result); |
||
63 | $item['name'] = $result_array['title']; |
||
64 | $item['url'] = XOOPS_URL . '/modules/' . $moduleDirName . '/singlelink.php?cid=' . $result_array['cid'] . '&lid=' . $item_id; |
||
65 | |||
66 | return $item; |
||
67 | } |
||
68 | |||
69 | return null; |
||
70 | } |
||
71 |