| Conditions | 5 |
| Paths | 5 |
| Total Lines | 64 |
| Code Lines | 46 |
| 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); |
||
| 28 | function suico_iteminfo($category, $item_id) |
||
| 29 | { |
||
| 30 | $moduleHandler = xoops_getHandler('module'); |
||
| 31 | $module = $moduleHandler->getByDirname('suico'); |
||
|
|
|||
| 32 | if ('global' === $category) { |
||
| 33 | $item['name'] = ''; |
||
| 34 | $item['url'] = ''; |
||
| 35 | |||
| 36 | return $item; |
||
| 37 | } |
||
| 38 | global $xoopsDB; |
||
| 39 | if ('picture' === $category) { |
||
| 40 | $sql = 'SELECT title,uid_owner,filename FROM ' . $xoopsDB->prefix( |
||
| 41 | 'suico_images' |
||
| 42 | ) . ' WHERE uid_owner = ' . $item_id . ' LIMIT 1'; |
||
| 43 | $result = $xoopsDB->query($sql); |
||
| 44 | $result_array = $xoopsDB->fetchArray($result); |
||
| 45 | /** |
||
| 46 | * Let's get the user name of the owner of the album |
||
| 47 | */ |
||
| 48 | $owner = new \XoopsUser(); |
||
| 49 | $identifier = $owner::getUnameFromId($result_array['uid_owner']); |
||
| 50 | $item['name'] = $identifier . "'s Album"; |
||
| 51 | $item['url'] = XOOPS_URL . '/modules/' . $module->getVar( |
||
| 52 | 'dirname' |
||
| 53 | ) . '/album.php?uid=' . $result_array['uid_owner']; |
||
| 54 | |||
| 55 | return $item; |
||
| 56 | } |
||
| 57 | if ('video' === $category) { |
||
| 58 | $sql = 'SELECT video_id,uid_owner,video_title,video_desc,youtube_code, featuredvideo FROM ' . $xoopsDB->prefix( |
||
| 59 | 'suico_images' |
||
| 60 | ) . ' WHERE uid_owner = ' . $item_id . ' LIMIT 1'; |
||
| 61 | $result = $xoopsDB->query($sql); |
||
| 62 | $result_array = $xoopsDB->fetchArray($result); |
||
| 63 | /** |
||
| 64 | * Let's get the user name of the owner of the album |
||
| 65 | */ |
||
| 66 | $owner = new \XoopsUser(); |
||
| 67 | $identifier = $owner::getUnameFromId($result_array['uid_owner']); |
||
| 68 | $item['name'] = $identifier . "'s Videos"; |
||
| 69 | $item['url'] = XOOPS_URL . '/modules/' . $module->getVar( |
||
| 70 | 'dirname' |
||
| 71 | ) . '/videos.php?uid=' . $result_array['uid_owner']; |
||
| 72 | |||
| 73 | return $item; |
||
| 74 | } |
||
| 75 | if ('Note' === $category) { |
||
| 76 | $sql = 'SELECT note_id, note_from, note_to, note_text FROM ' . $xoopsDB->prefix( |
||
| 77 | 'suico_notes' |
||
| 78 | ) . ' WHERE note_from = ' . $item_id . ' LIMIT 1'; |
||
| 79 | $result = $xoopsDB->query($sql); |
||
| 80 | $result_array = $xoopsDB->fetchArray($result); |
||
| 81 | /** |
||
| 82 | * Let's get the user name of the owner of the album |
||
| 83 | */ |
||
| 84 | $owner = new \XoopsUser(); |
||
| 85 | $identifier = $owner::getUnameFromId($result_array['note_from']); |
||
| 86 | $item['name'] = $identifier . "'s Notes"; |
||
| 87 | $item['url'] = XOOPS_URL . '/modules/' . $module->getVar( |
||
| 88 | 'dirname' |
||
| 89 | ) . '/notebook.php?uid=' . $result_array['note_from']; |
||
| 90 | |||
| 91 | return $item; |
||
| 92 | } |
||
| 94 |