| Conditions | 6 |
| Paths | 6 |
| Total Lines | 64 |
| Code Lines | 28 |
| 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 |
||
| 15 | function sb_notify_iteminfo($category, $item_id, $event = null) |
||
| 16 | { |
||
| 17 | /* |
||
| 18 | global $xoopsModule, $xoopsModuleConfig, $xoopsConfig; |
||
| 19 | |||
| 20 | if ( empty( $xoopsModule ) || $xoopsModule -> getVar( 'dirname' ) != 'soapbox' ) { |
||
| 21 | $moduleHandler = xoops_getHandler( 'module' ); |
||
| 22 | $module = $moduleHandler -> getByDirname( 'soapbox' ); |
||
| 23 | $configHandler = xoops_getHandler( 'config' ); |
||
| 24 | $config = $configHandler->getConfigsByCat( 0, $module -> getVar( 'mid' ) ); |
||
| 25 | } else { |
||
| 26 | $module = $xoopsModule; |
||
| 27 | if ( empty( $xoopsModuleConfig ) ) { |
||
| 28 | $configHandler = xoops_getHandler( 'config' ); |
||
| 29 | $config = $configHandler->getConfigsByCat( 0, $module -> getVar( 'mid' ) ); |
||
| 30 | } else { |
||
| 31 | $config = $xoopsModuleConfig; |
||
| 32 | } |
||
| 33 | } |
||
| 34 | */ |
||
| 35 | // $moduleDirName = 'soapbox'; |
||
| 36 | $pathparts = explode('/', __DIR__); |
||
| 37 | $moduleDirName = $pathparts[array_search('modules', $pathparts, true) + 1]; |
||
| 38 | $item_id = (int)$item_id; |
||
| 39 | $item = []; |
||
| 40 | if ('global' === $category) { |
||
| 41 | $item['name'] = ''; |
||
| 42 | $item['url'] = ''; |
||
| 43 | |||
| 44 | return $item; |
||
| 45 | } |
||
| 46 | |||
| 47 | global $xoopsDB; |
||
| 48 | |||
| 49 | if ('column' === $category) { |
||
| 50 | // Assume we have a valid category id |
||
| 51 | |||
| 52 | $sql = 'SELECT name FROM ' . $xoopsDB->prefix('sbcolumns') . ' WHERE columnID = ' . $item_id; |
||
| 53 | $result = $xoopsDB->query($sql); |
||
| 54 | if (!$result) { |
||
| 55 | return $item; |
||
| 56 | } |
||
| 57 | $result_array = $xoopsDB->fetchArray($result); |
||
| 58 | $item['name'] = $result_array['name']; |
||
| 59 | $item['url'] = XOOPS_URL . '/modules/' . $moduleDirName . '/column.php?columnID=' . $item_id; |
||
| 60 | |||
| 61 | return $item; |
||
| 62 | } |
||
| 63 | |||
| 64 | if ('article' === $category) { |
||
| 65 | // Assume we have a valid story id |
||
| 66 | $sql = 'SELECT headline FROM ' . $xoopsDB->prefix('sbarticles') . ' WHERE articleID = ' . $item_id; |
||
| 67 | $result = $xoopsDB->query($sql); |
||
| 68 | if (!$result) { |
||
| 69 | return $item; |
||
| 70 | } |
||
| 71 | $result_array = $xoopsDB->fetchArray($result); |
||
| 72 | $item['name'] = $result_array['headline']; |
||
| 73 | $item['url'] = XOOPS_URL . '/modules/' . $moduleDirName . '/article.php?articleID=' . $item_id; |
||
| 74 | |||
| 75 | return $item; |
||
| 76 | } |
||
| 77 | |||
| 78 | return ''; |
||
| 79 | } |
||
| 80 |