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