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