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