| Conditions | 7 |
| Paths | 12 |
| Total Lines | 52 |
| Code Lines | 31 |
| 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 declare(strict_types=1); |
||
| 30 | function adslight_notify_iteminfo( |
||
| 31 | $category, |
||
| 32 | $item_id |
||
| 33 | ) { |
||
| 34 | global $xoopsDB; |
||
| 35 | $moduleDirName = \basename(\dirname(__DIR__)); |
||
| 36 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
| 37 | $moduleHandler = xoops_getHandler('module'); |
||
| 38 | $module = $moduleHandler->getByDirname($moduleDirName); |
||
|
|
|||
| 39 | if ('global' === $category) { |
||
| 40 | $item['name'] = ''; |
||
| 41 | $item['url'] = ''; |
||
| 42 | |||
| 43 | return $item; |
||
| 44 | } |
||
| 45 | |||
| 46 | $item_id = (int)$item_id; |
||
| 47 | if ('category' === $category) { |
||
| 48 | // Assume we have a valid topid id |
||
| 49 | $sql = 'SELECT SQL_CACHE title FROM ' . $xoopsDB->prefix('adslight_categories') . " WHERE cid ={$item_id} LIMIT 1"; |
||
| 50 | |||
| 51 | $result = $xoopsDB->query($sql); |
||
| 52 | if (!$xoopsDB->isResultSet($result)) { |
||
| 53 | \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); |
||
| 54 | } |
||
| 55 | if ($xoopsDB->isResultSet($result)) { |
||
| 56 | $result_array = $xoopsDB->fetchArray($result); |
||
| 57 | $item['name'] = $result_array['title']; |
||
| 58 | $item['url'] = XOOPS_URL . '/modules/adslight/index.php?pa=adsview&cid=' . $item_id; |
||
| 59 | |||
| 60 | return $item; |
||
| 61 | } |
||
| 62 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
| 63 | $moduleHandler = xoops_getHandler('module'); |
||
| 64 | /** @var \XoopsModule $myModule */ |
||
| 65 | $myModule = $moduleHandler->getByDirname('adslight'); |
||
| 66 | $myModule->setErrors('Could not query the database.'); |
||
| 67 | } |
||
| 68 | |||
| 69 | if ('listing' === $category) { |
||
| 70 | // Assume we have a valid post id |
||
| 71 | $sql = 'SELECT title FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE lid={$item_id} LIMIT 1"; |
||
| 72 | $result = $xoopsDB->query($sql); |
||
| 73 | if (!$xoopsDB->isResultSet($result)) { |
||
| 74 | \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); |
||
| 75 | } |
||
| 76 | $result_array = $xoopsDB->fetchArray($result); |
||
| 77 | $item['name'] = $result_array['title']; |
||
| 78 | // $item['catname'] = $result_array['cat.title']; |
||
| 79 | $item['url'] = XOOPS_URL . '/modules/adslight/viewads.php?lid= ' . $item_id; |
||
| 80 | |||
| 81 | return $item; |
||
| 82 | } |
||
| 84 |