| Conditions | 23 | 
| Paths | > 20000 | 
| Total Lines | 229 | 
| Lines | 229 | 
| Ratio | 100 % | 
| 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 namespace Xoopsmodules\smallworld;  | 
            ||
| 29 | public function ShowUser($id)  | 
            ||
| 30 |     { | 
            ||
| 31 | global $xoopsUser, $xoTheme, $xoopsTpl, $arr04, $arr05, $xoopsDB;  | 
            ||
| 32 |         if ($xoopsUser) { | 
            ||
| 33 |             $moduleHandler = xoops_getHandler('module'); | 
            ||
| 34 |             $module        = $moduleHandler->getByDirname('smallworld'); | 
            ||
| 35 |             $configHandler = xoops_getHandler('config'); | 
            ||
| 36 |             $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid')); | 
            ||
| 37 | |||
| 38 | $user = new \XoopsUser($id);  | 
            ||
| 39 |             $myName = $xoopsUser->getUnameFromId($xoopsUser->getVar('uid')); // My name | 
            ||
| 40 | $db = new SmallWorldDB;  | 
            ||
| 41 | $check = new SmallWorldUser;  | 
            ||
| 42 | $Wall = new WallUpdates();  | 
            ||
| 43 | |||
| 44 |             $cdb    = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid = '" . $id . "'"; | 
            ||
| 45 | $result = $xoopsDB->queryF($cdb);  | 
            ||
| 46 | $cnt = $xoopsDB->getRowsNum($result);  | 
            ||
| 47 |             while ($r = $xoopsDB->fetchArray($result)) { | 
            ||
| 48 | $uname = $r['username'];  | 
            ||
| 49 | $realname = $r['realname'];  | 
            ||
| 50 |                 $membersince     = date('d-m-Y', $user->user_regdate()); | 
            ||
| 51 | $birthday = Smallworld_UsToEuroDate($r['birthday']);  | 
            ||
| 52 | $cnt_bday = smallworldNextBdaySecs($r['birthday']);  | 
            ||
| 53 | $birthcity = $r['birthplace'];  | 
            ||
| 54 | $email = $user->email();  | 
            ||
| 55 | $country = $user->user_from();  | 
            ||
| 56 | $signature = $user->user_sig();  | 
            ||
| 57 | $messenger = $user->user_msnm();  | 
            ||
| 58 | $totalposts = $Wall->CountMsges($id);  | 
            ||
| 59 |                 $membersince     = date('m-d-Y', $user->user_regdate()); | 
            ||
| 60 | $usersratedplus = $db->CountUsersRates($id, 'up');  | 
            ||
| 61 | $usersratedminus = $db->CountUsersRates($id, 'down');  | 
            ||
| 62 | $workfull = $db->getJobsToDiv($id);  | 
            ||
| 63 | $workArray = unserialize($r['employer']);  | 
            ||
| 64 |                 $work            = "<a href='javascript:void(0)' id='_smallworld_workmore'>" . $workArray[0] . ' (' . _SMALLWORLD_MORE . ')</a>'; | 
            ||
| 65 | $educationfull = $db->getSchoolToDiv($id);  | 
            ||
| 66 | $educationArray = unserialize($r['school_type']);  | 
            ||
| 67 |                 $education       = "<a href='javascript:void(0)' id='_smallworld_educationmore'>" . $educationArray[0] . ' (' . _SMALLWORLD_MORE . ')</a>'; | 
            ||
| 68 | $lng = $r['birthplace_lng'];  | 
            ||
| 69 | $latt = $r['birthplace_lat'];  | 
            ||
| 70 | $country = $r['birthplace_country'];  | 
            ||
| 71 | $rank = $user->rank();  | 
            ||
| 72 | $rank_title = $rank['title'];  | 
            ||
| 73 |                 if (isset($rank['image'])) { | 
            ||
| 74 | $rank_image = "<img align='center' src='" . XOOPS_UPLOAD_URL . '/' . $rank['image'] . "'>";  | 
            ||
| 75 |                 } else { | 
            ||
| 76 | $rank_image = '';  | 
            ||
| 77 | }  | 
            ||
| 78 | $commentsrating = "<img src='" . XOOPS_URL . "/modules/smallworld/assets/images/like.png' height='10px' width='10px'" . '> ' . $usersratedplus;  | 
            ||
| 79 | $commentsrating .= " <img src='" . XOOPS_URL . "/modules/smallworld/assets/images/dislike.png' height='10px' width='10px'" . '> ' . $usersratedminus;  | 
            ||
| 80 |                 $lastlogin      = $user->getVar('last_login'); | 
            ||
| 81 | |||
| 82 | $gender = $r['gender'];  | 
            ||
| 83 |                 if (2 == $gender) { | 
            ||
| 84 | $heorshe = _SMALLWORLD_HE;  | 
            ||
| 85 | $hisorher = _SMALLWORLD_HIS;  | 
            ||
| 86 | }  | 
            ||
| 87 |                 if (1 == $gender) { | 
            ||
| 88 | $heorshe = _SMALLWORLD_SHE;  | 
            ||
| 89 | $hisorher = _SMALLWORLD_HER;  | 
            ||
| 90 | }  | 
            ||
| 91 |                 if ('' == $gender || 0 == $gender) { | 
            ||
| 92 | $heorshe = _SMALLWORLD_HEORSHE;  | 
            ||
| 93 | $hisorher = _SMALLWORLD_HISHER;  | 
            ||
| 94 | }  | 
            ||
| 95 | $avatar = $Wall->Gravatar($id);  | 
            ||
| 96 | $avatar_size = smallworld_getImageSize(80, 100, smallworld_getAvatarLink($id, $avatar));  | 
            ||
| 97 | $avatar_highwide = smallworld_imageResize($avatar_size[0], $avatar_size[1], 100);  | 
            ||
| 98 | $user_img = "<img src='" . smallworld_getAvatarLink($id, $avatar) . "' id='smallworld_user_img' " . $avatar_highwide . '>';  | 
            ||
| 99 | |||
| 100 | $currentcity = $r['present_city'];  | 
            ||
| 101 | $currlng = $r['present_lng'];  | 
            ||
| 102 | $currlatt = $r['present_lat'];  | 
            ||
| 103 | $currcountry = $r['present_country'];  | 
            ||
| 104 | |||
| 105 | // experimental. Set javascript var using php getVar()  | 
            ||
| 106 | $js = "<script type='text/javascript'>";  | 
            ||
| 107 | $js .= 'var smallworld_currlng = ' . $currlng . "\n";  | 
            ||
| 108 | $js .= 'var smallworld_currlatt = ' . $currlatt . "\n";  | 
            ||
| 109 | $js .= 'var smallworld_birthlng = ' . $lng . "\n";  | 
            ||
| 110 | $js .= 'var smallworld_birthlatt = ' . $latt . "\n";  | 
            ||
| 111 | $js .= '</script>';  | 
            ||
| 112 | echo $js;  | 
            ||
| 113 | |||
| 114 | $relationship = $r['relationship'];  | 
            ||
| 115 | $spouseExists = $check->spousexist($r['partner']);  | 
            ||
| 116 | |||
| 117 |                 if (2 == $relationship) { | 
            ||
| 118 | $status = _SMALLWORLD_ISSINGLE;  | 
            ||
| 119 | $spouse = '';  | 
            ||
| 120 | }  | 
            ||
| 121 |                 if (3 == $relationship) { | 
            ||
| 122 | $status = _SMALLWORLD_INRELATIONSHIP;  | 
            ||
| 123 |                     if ($spouseExists > 0) { | 
            ||
| 124 | $spouse = "<a href='" . XOOPS_URL . '/modules/smallworld/userprofile.php?username=' . $r['partner'] . "' target='_self'>" . $r['partner'] . '</a>';  | 
            ||
| 125 |                     } else { | 
            ||
| 126 | $spouse = $r['partner'];  | 
            ||
| 127 | }  | 
            ||
| 128 | }  | 
            ||
| 129 |                 if (0 == $relationship) { | 
            ||
| 130 | $status = _SMALLWORLD_ISMARRIED;  | 
            ||
| 131 |                     if ($spouseExists > 0) { | 
            ||
| 132 | $spouse = "<a href='" . XOOPS_URL . '/modules/smallworld/userprofile.php?username=' . $r['partner'] . "' target='_self'>" . $r['partner'] . '</a>';  | 
            ||
| 133 |                     } else { | 
            ||
| 134 | $spouse = $r['partner'];  | 
            ||
| 135 | }  | 
            ||
| 136 | }  | 
            ||
| 137 |                 if (1 == $relationship) { | 
            ||
| 138 | $status = _SMALLWORLD_ISENGAGED;  | 
            ||
| 139 |                     if ($spouseExists > 0) { | 
            ||
| 140 | $spouse = "<a href='" . XOOPS_URL . '/modules/smallworld/userprofile.php?username=' . $r['partner'] . "' target='_self'>" . $r['partner'] . '</a>';  | 
            ||
| 141 |                     } else { | 
            ||
| 142 | $spouse = $r['partner'];  | 
            ||
| 143 | }  | 
            ||
| 144 | }  | 
            ||
| 145 |                 if (5 == $relationship) { | 
            ||
| 146 | $status = _SMALLWORLD_ISCOMPLICATED;  | 
            ||
| 147 |                     if ($spouseExists > 0) { | 
            ||
| 148 | $spouse = "<a href='" . XOOPS_URL . '/modules/smallworld/userprofile.php?username=' . $r['partner'] . "' target='_self'>" . $r['partner'] . '</a>';  | 
            ||
| 149 |                     } else { | 
            ||
| 150 | $spouse = $r['partner'];  | 
            ||
| 151 | }  | 
            ||
| 152 | }  | 
            ||
| 153 |                 if (4 == $relationship) { | 
            ||
| 154 | $status = _SMALLWORLD_OPENRELATIONSHIP;  | 
            ||
| 155 |                     if ($spouseExists > 0) { | 
            ||
| 156 | $spouse = "<a href='" . XOOPS_URL . '/modules/smallworld/userprofile.php?username=' . $r['partner'] . "' target='_self'>" . $r['partner'] . '</a>';  | 
            ||
| 157 |                     } else { | 
            ||
| 158 | $spouse = $r['partner'];  | 
            ||
| 159 | }  | 
            ||
| 160 | }  | 
            ||
| 161 | |||
| 162 | //Personal info  | 
            ||
| 163 | $aboutme = $r['aboutme'];  | 
            ||
| 164 | $religion = $arr05[$r['religion']];  | 
            ||
| 165 | $politic = $arr04[$r['politic']];  | 
            ||
| 166 | |||
| 167 | //Interests  | 
            ||
| 168 | $favbook = $r['books'];  | 
            ||
| 169 | $favmusic = $r['music'];  | 
            ||
| 170 | $favmovie = $r['movie'];  | 
            ||
| 171 | $favtvshow = $r['tvshow'];  | 
            ||
| 172 | $favinterests = $r['interests'];  | 
            ||
| 173 | |||
| 174 | // Contact and adresses  | 
            ||
| 175 | $email = unserialize($r['emailtype']);  | 
            ||
| 176 | $screenname = $db->getScreennamesToDiv($id);  | 
            ||
| 177 |                 if ('' == $r['phone'] || 0 == $r['phone']) { | 
            ||
| 178 | $phone = 'xxx-xxx-xxxx';  | 
            ||
| 179 |                 } else { | 
            ||
| 180 | $phone = $r['phone'];  | 
            ||
| 181 | }  | 
            ||
| 182 | |||
| 183 |                 if ('' == $r['mobile'] || 0 == $r['mobile']) { | 
            ||
| 184 | $gsm = 'xxx-xxx-xxxx';  | 
            ||
| 185 |                 } else { | 
            ||
| 186 | $gsm = $r['mobile'];  | 
            ||
| 187 | }  | 
            ||
| 188 | |||
| 189 | $adress = $r['adress'];  | 
            ||
| 190 | $website = $r['website'];  | 
            ||
| 191 | $age = Smallworld_Birthday($r['birthday']);  | 
            ||
| 192 | }  | 
            ||
| 193 | |||
| 194 | //SW_CheckIfUser ($userid);  | 
            ||
| 195 |             $xoopsTpl->assign('userid', $id); | 
            ||
| 196 | |||
| 197 | // ----- LANG DEFINES ------  | 
            ||
| 198 |             $xoopsTpl->assign('username', $uname); | 
            ||
| 199 |             $xoopsTpl->assign('MyUserName', $myName); | 
            ||
| 200 |             $xoopsTpl->assign('avatar', $user_img); | 
            ||
| 201 |             $xoopsTpl->assign('realname', $realname); | 
            ||
| 202 |             $xoopsTpl->assign('birthday', $birthday); | 
            ||
| 203 |             $xoopsTpl->assign('nextBDay', $cnt_bday); | 
            ||
| 204 | |||
| 205 |             $xoopsTpl->assign('usersratinf', $commentsrating); | 
            ||
| 206 | |||
| 207 |             $xoopsTpl->assign('age', $age); | 
            ||
| 208 |             $xoopsTpl->assign('birthcity', $birthcity); | 
            ||
| 209 |             $xoopsTpl->assign('country', $country); | 
            ||
| 210 |             $xoopsTpl->assign('heorshe', $heorshe); | 
            ||
| 211 |             $xoopsTpl->assign('hisorher', $hisorher); | 
            ||
| 212 | |||
| 213 |             $xoopsTpl->assign('membersince', $membersince); | 
            ||
| 214 |             $xoopsTpl->assign('msn', $messenger); | 
            ||
| 215 |             $xoopsTpl->assign('website', $website); | 
            ||
| 216 |             $xoopsTpl->assign('totalposts', $totalposts); | 
            ||
| 217 |             $xoopsTpl->assign('ranktitle', $rank_title); | 
            ||
| 218 |             $xoopsTpl->assign('rankimage', $rank_image); | 
            ||
| 219 |             $xoopsTpl->assign('lastlogin', date('d-m-Y', $lastlogin)); | 
            ||
| 220 |             $xoopsTpl->assign('signature', $signature); | 
            ||
| 221 |             $xoopsTpl->assign('currentcity', $currentcity); | 
            ||
| 222 |             $xoopsTpl->assign('currcity', $currentcity); | 
            ||
| 223 |             $xoopsTpl->assign('currcountry', $currcountry); | 
            ||
| 224 | |||
| 225 |             $xoopsTpl->assign('education', $education); | 
            ||
| 226 |             $xoopsTpl->assign('educationfull', $educationfull); | 
            ||
| 227 | |||
| 228 |             $xoopsTpl->assign('work', $work); | 
            ||
| 229 |             $xoopsTpl->assign('workfull', $workfull); | 
            ||
| 230 | |||
| 231 |             $xoopsTpl->assign('relationship', $status); | 
            ||
| 232 |             $xoopsTpl->assign('status', $status); | 
            ||
| 233 |             $xoopsTpl->assign('spouse', $spouse); | 
            ||
| 234 |             $xoopsTpl->assign('aboutme', $aboutme); | 
            ||
| 235 |             $xoopsTpl->assign('lang.avatar', _SMALLWORLD_AVATAR); | 
            ||
| 236 | |||
| 237 | // Pers info language define  | 
            ||
| 238 |             $xoopsTpl->assign('politic', $politic); | 
            ||
| 239 |             $xoopsTpl->assign('religion', $religion); | 
            ||
| 240 | |||
| 241 |             $xoopsTpl->assign('favbook', $favbook); | 
            ||
| 242 |             $xoopsTpl->assign('favmusic', $favmusic); | 
            ||
| 243 |             $xoopsTpl->assign('favmovie', $favmovie); | 
            ||
| 244 |             $xoopsTpl->assign('favtvshow', $favtvshow); | 
            ||
| 245 |             $xoopsTpl->assign('favinterests', $favinterests); | 
            ||
| 246 | |||
| 247 |             $xoopsTpl->assign('email', $email); | 
            ||
| 248 |             $xoopsTpl->assign('screenname', $screenname); | 
            ||
| 249 |             $xoopsTpl->assign('phone', $phone); | 
            ||
| 250 |             $xoopsTpl->assign('mobile', $gsm); | 
            ||
| 251 |             $xoopsTpl->assign('adress', $adress); | 
            ||
| 252 | |||
| 253 |             $xoopsTpl->assign('website', $website); | 
            ||
| 254 |             $xoopsTpl->assign('addsomeinfo', _SMALLWORLD_ADDSOMEINFO); | 
            ||
| 255 |             $xoopsTpl->assign('pagename', 'profile'); | 
            ||
| 256 | }  | 
            ||
| 257 | }  | 
            ||
| 258 | }  | 
            ||
| 259 | 
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.