Conditions | 8 |
Paths | 12 |
Total Lines | 52 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
25 | function xtubeNotifyIteminfo($category, $item_id) |
||
26 | { |
||
27 | global $xoopsModule; |
||
28 | |||
29 | $moduleDirName = basename(dirname(__DIR__)); |
||
30 | // $modulePath = dirname(__DIR__); |
||
31 | |||
32 | if (empty($xoopsModule) || $xoopsModule->getVar('dirname') !== 'xoopstube') { |
||
33 | $moduleHandler = xoops_getHandler('module'); |
||
34 | $module = $moduleHandler->getByDirname($moduleDirName); |
||
35 | $configHandler = xoops_getHandler('config'); |
||
36 | $config = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
||
37 | } else { |
||
38 | $module = $xoopsModule; |
||
39 | $config = $GLOBALS['xoopsModuleConfig']; |
||
40 | } |
||
41 | |||
42 | if ('global' === $category) { |
||
43 | $item['name'] = ''; |
||
44 | $item['url'] = ''; |
||
45 | |||
46 | return $item; |
||
47 | } |
||
48 | |||
49 | if ('category' === $category) { |
||
50 | // Assume we have a valid category id |
||
51 | $sql = 'SELECT title FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_cat') . ' WHERE cid=' . $item_id; |
||
52 | if (!$result = $GLOBALS['xoopsDB']->query($sql)) { |
||
53 | return false; |
||
54 | } |
||
55 | $result_array = $GLOBALS['xoopsDB']->fetchArray($result); |
||
56 | $item['name'] = $result_array['title']; |
||
57 | $item['url'] = XOOPS_URL . '/modules/xoopstube/viewcat.php?cid=' . $item_id; |
||
58 | |||
59 | return $item; |
||
60 | } |
||
61 | |||
62 | if ('video' === $category) { |
||
63 | // Assume we have a valid file id |
||
64 | $sql = 'SELECT cid,title FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_videos') . ' WHERE lid=' . $item_id; |
||
65 | if (!$result = $GLOBALS['xoopsDB']->query($sql)) { |
||
66 | return false; |
||
67 | } |
||
68 | $result_array = $GLOBALS['xoopsDB']->fetchArray($result); |
||
69 | $item['name'] = $result_array['title']; |
||
70 | $item['url'] = XOOPS_URL . '/modules/xoopstube/singlevideo.php?cid=' . $result_array['cid'] . '&lid=' . $item_id; |
||
71 | |||
72 | return $item; |
||
73 | } |
||
74 | |||
75 | return null; |
||
76 | } |
||
77 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.