| Conditions | 13 | 
| Paths | 192 | 
| Total Lines | 71 | 
| 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  | 
            ||
| 35 | function smallworld_search($queryarray, $andor, $limit, $offset, $userid, $sortby = 'created DESC')  | 
            ||
| 36 | { | 
            ||
| 37 | global $xoopsDB, $xoopsConfig, $myts, $xoopsUser;  | 
            ||
| 38 | |||
| 39 |     if (file_exists(XOOPS_ROOT_PATH . '/modules/smallworld/language/' . $xoopsConfig['language'] . '/main.php')) { | 
            ||
| 40 | require_once XOOPS_ROOT_PATH . '/modules/smallworld/language/' . $xoopsConfig['language'] . '/main.php';  | 
            ||
| 41 |     } else { | 
            ||
| 42 | require_once XOOPS_ROOT_PATH . '/modules/smallworld/language/english/main.php';  | 
            ||
| 43 | }  | 
            ||
| 44 | |||
| 45 |     $moduleHandler = xoops_getHandler('module'); | 
            ||
| 46 |     $module        = $moduleHandler->getByDirname('smallworld'); | 
            ||
| 47 |     $modid         = $module->getVar('mid'); | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 48 | $searchparam = '';  | 
            ||
| 49 | $highlight = false;  | 
            ||
| 50 | |||
| 51 |     $gpermHandler = xoops_getHandler('groupperm'); | 
            ||
| 52 |     if (is_object($xoopsUser)) { | 
            ||
| 53 | $groups =& $xoopsUser->getGroups();  | 
            ||
| 54 |         $id        = $xoopsUser->getVar('uid'); | 
            ||
| 55 | $Wall = new smallworld\WallUpdates();  | 
            ||
| 56 | $followers = Smallworld_array_flatten($Wall->getFollowers($id), 0);  | 
            ||
| 57 |     } else { | 
            ||
| 58 | $id = 0;  | 
            ||
| 59 | $groups = XOOPS_GROUP_ANONYMOUS;  | 
            ||
| 60 | $followers = [];  | 
            ||
| 61 | }  | 
            ||
| 62 | |||
| 63 |     if ($id > 0 && '' != $id) { | 
            ||
| 64 |         $sql = 'SELECT M.msg_id, M.uid_fk, M.message, M.created, M.priv, U.username FROM ' . $xoopsDB->prefix('smallworld_messages') . ' M, ' . $xoopsDB->prefix('smallworld_user') . ' U WHERE M.uid_fk=U.userid'; | 
            ||
| 65 |     } else { | 
            ||
| 66 |         $sql = 'SELECT M.msg_id, M.uid_fk, M.message, M.created, M.priv, U.username FROM ' . $xoopsDB->prefix('smallworld_messages') . ' M, ' . $xoopsDB->prefix('smallworld_user') . ' U WHERE M.uid_fk=U.userid'; | 
            ||
| 67 | }  | 
            ||
| 68 | |||
| 69 |     if (0 != $userid) { | 
            ||
| 70 | $sql .= ' AND M.uid_fk = ' . $userid . ' ';  | 
            ||
| 71 | }  | 
            ||
| 72 |     if (is_array($queryarray) && $count = count($queryarray)) { | 
            ||
| 73 | $sql .= " AND (M.message LIKE '%$queryarray[0]%' OR M.message LIKE '%$queryarray[0]%' OR U.username LIKE '%$queryarray[0]%'";  | 
            ||
| 74 | $sql .= ') ';  | 
            ||
| 75 | // keywords highlighting  | 
            ||
| 76 |         if ($highlight) { | 
            ||
| 77 |             $searchparam = '&keywords=' . urlencode(trim(implode(' ', $queryarray))); | 
            ||
| 78 | }  | 
            ||
| 79 | }  | 
            ||
| 80 | $sql .= 'ORDER BY created DESC';  | 
            ||
| 81 | $result = $xoopsDB->query($sql, $limit, $offset);  | 
            ||
| 82 | $ret = [];  | 
            ||
| 83 | $i = 0;  | 
            ||
| 84 |     while ($myrow = $xoopsDB->fetchArray($result)) { | 
            ||
| 85 |         if (in_array($myrow['uid_fk'], $followers) || $myrow['uid_fk'] == $id) { | 
            ||
| 86 | $ret[$i]['image'] = 'images/smallworld_icn.png';  | 
            ||
| 87 | $ret[$i]['link'] = 'permalink.php?ownerid=' . $myrow['uid_fk'] . '&updid=' . $myrow['msg_id'];  | 
            ||
| 88 |             if (preg_match('/UPLIMAGE/', $myrow['message'])) { | 
            ||
| 89 |                 $ownmsg           = str_replace('UPLIMAGE ', '', $myrow['message']); | 
            ||
| 90 | $ret[$i]['title'] = $ownmsg;  | 
            ||
| 91 | $ret[$i]['title'] = Smallworld_getName($myrow['uid_fk']) . ' -> ' . _SMALLWORLD_GALLERY;  | 
            ||
| 92 | $ret[$i]['title'] = str_replace(['<', '>'], ['<', '>'], $ret[$i]['title']);  | 
            ||
| 93 |             } else { | 
            ||
| 94 | $ret[$i]['title'] = smallworld_shortenText($myrow['message'], 60);  | 
            ||
| 95 | }  | 
            ||
| 96 | $ret[$i]['time'] = $myrow['created'];  | 
            ||
| 97 | $ret[$i]['uid'] = $myrow['uid_fk'];  | 
            ||
| 98 |         } else { | 
            ||
| 99 | --$i;  | 
            ||
| 100 | }  | 
            ||
| 101 | ++$i;  | 
            ||
| 102 | }  | 
            ||
| 103 | |||
| 104 | return $ret;  | 
            ||
| 105 | }  | 
            ||
| 106 | 
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.