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