| Conditions | 7 |
| Paths | 12 |
| Total Lines | 59 |
| Code Lines | 29 |
| 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 lexikon_notify_iteminfo($category, $item_id) |
||
| 18 | { |
||
| 19 | /*global $xoopsModule, $xoopsModuleConfig, $xoopsConfig; |
||
| 20 | |||
| 21 | if (empty($xoopsModule) || $xoopsModule->getVar('dirname') != 'lexikon') { |
||
| 22 | |||
| 23 | $moduleHandler = xoops_getHandler('module'); |
||
| 24 | $module = $moduleHandler->getByDirname('lexikon'); |
||
| 25 | $configHandler = xoops_getHandler('config'); |
||
| 26 | $config = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
||
| 27 | } |
||
| 28 | |||
| 29 | else { |
||
| 30 | $module = $xoopsModule; |
||
| 31 | $config = $xoopsModuleConfig; |
||
| 32 | }*/ |
||
| 33 | |||
| 34 | if (mb_strpos(__DIR__, '/') > 0) { |
||
| 35 | $pathparts = explode('/', __DIR__); |
||
| 36 | } else { |
||
| 37 | $pathparts = explode('\\', __DIR__); |
||
| 38 | } |
||
| 39 | $moduleDirName = $pathparts[array_search('modules', $pathparts, true) + 1]; // checken |
||
|
|
|||
| 40 | |||
| 41 | if ('global' === $category) { |
||
| 42 | $item['name'] = ''; |
||
| 43 | $item['url'] = ''; |
||
| 44 | |||
| 45 | return $item; |
||
| 46 | } |
||
| 47 | $item_id = (int)$item_id; |
||
| 48 | |||
| 49 | global $xoopsDB; |
||
| 50 | if ('category' === $category) { |
||
| 51 | // Assume we have a valid category id |
||
| 52 | $sql = 'SELECT name FROM ' . $xoopsDB->prefix('lxcategories') . ' WHERE categoryID = ' . $item_id; |
||
| 53 | if (!$result = $xoopsDB->query($sql)) { |
||
| 54 | redirect_header('index.php', 2, _ERRORS); |
||
| 55 | } |
||
| 56 | $result = $xoopsDB->query($sql); |
||
| 57 | $result_array = $xoopsDB->fetchArray($result); |
||
| 58 | $item['name'] = $result_array['name']; |
||
| 59 | $item['url'] = XOOPS_URL . '/modules/lexikon/category.php?categoryID=' . $item_id; |
||
| 60 | |||
| 61 | return $item; |
||
| 62 | } |
||
| 63 | |||
| 64 | if ('term' === $category) { |
||
| 65 | // Assume we have a valid entry id |
||
| 66 | $sql = 'SELECT entryID,term FROM ' . $xoopsDB->prefix('lxentries') . ' WHERE entryID = ' . $item_id; |
||
| 67 | if (!$result = $xoopsDB->query($sql)) { |
||
| 68 | redirect_header('index.php', 2, _ERRORS); |
||
| 69 | } |
||
| 70 | $result = $xoopsDB->query($sql); |
||
| 71 | $result_array = $xoopsDB->fetchArray($result); |
||
| 72 | $item['name'] = $result_array['term']; |
||
| 73 | $item['url'] = XOOPS_URL . '/modules/lexikon/entry.php?entryID=' . $item_id; |
||
| 74 | |||
| 75 | return $item; |
||
| 76 | } |
||
| 78 |