Complex classes like XoopsUser often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use XoopsUser, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
35 | class XoopsUser extends XoopsObject |
||
36 | { |
||
37 | /** |
||
38 | * @var array groups that user belongs to |
||
39 | */ |
||
40 | private $groups = array(); |
||
41 | |||
42 | /** |
||
43 | * @var string user's rank |
||
44 | */ |
||
45 | private $rank = null; |
||
46 | |||
47 | /** |
||
48 | * @var bool is the user online? |
||
49 | */ |
||
50 | private $isOnline = null; |
||
51 | |||
52 | /** |
||
53 | * constructor |
||
54 | * |
||
55 | * @param int|array $id ID of the user to be loaded from the database or |
||
56 | * Array of key-value-pairs to be assigned to the user. |
||
57 | * (for backward compatibility only) |
||
58 | */ |
||
59 | 54 | public function __construct($id = null) |
|
108 | |||
109 | /** |
||
110 | * check if the user is a guest user |
||
111 | * |
||
112 | * @return bool returns false |
||
113 | */ |
||
114 | 1 | public function isGuest() |
|
118 | |||
119 | /** |
||
120 | * Updated by Catzwolf 11 Jan 2004 |
||
121 | * find the username for a given ID |
||
122 | * |
||
123 | * @param int $userid ID of the user to find |
||
124 | * @param int $usereal switch for usename or realname |
||
125 | * |
||
126 | * @return string name of the user. name for 'anonymous' if not found. |
||
127 | */ |
||
128 | 1 | public static function getUnameFromId($userid, $usereal = 0) |
|
152 | |||
153 | /** |
||
154 | * increase the number of posts for the user |
||
155 | * |
||
156 | * @deprecated |
||
157 | * @return bool |
||
158 | */ |
||
159 | public function incrementPost() |
||
160 | { |
||
161 | return \Xoops::getInstance()->getHandlerMember()->updateUserByField($this, 'posts', $this->getVar('posts') + 1); |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * set the groups for the user |
||
166 | * |
||
167 | * @param array $groupsArr Array of groups that user belongs to |
||
168 | * |
||
169 | * @return void |
||
170 | */ |
||
171 | 1 | public function setGroups($groupsArr) |
|
177 | |||
178 | /** |
||
179 | * get the groups that the user belongs to |
||
180 | * |
||
181 | * @return array array of groups |
||
182 | */ |
||
183 | 3 | public function getGroups() |
|
190 | |||
191 | /** |
||
192 | * alias for getGroups() |
||
193 | * |
||
194 | * @see getGroups() |
||
195 | * @return array array of groups |
||
196 | * @deprecated |
||
197 | */ |
||
198 | public function groups() |
||
199 | { |
||
200 | $groups = $this->getGroups(); |
||
201 | return $groups; |
||
202 | } |
||
203 | |||
204 | /** |
||
205 | * Is the user admin ? |
||
206 | * |
||
207 | * This method will return true if this user has admin rights for the specified module.<br /> |
||
208 | * - If you don't specify any module ID, the current module will be checked.<br /> |
||
209 | * - If you set the module_id to -1, it will return true if the user has admin rights for at least one module |
||
210 | * |
||
211 | * @param int $module_id check if user is admin of this module |
||
212 | * |
||
213 | * @return bool is the user admin of that module? |
||
214 | */ |
||
215 | 1 | public function isAdmin($module_id = null) |
|
226 | |||
227 | /** |
||
228 | * get the user's rank |
||
229 | * |
||
230 | * @return array array of rank ID and title |
||
231 | */ |
||
232 | 1 | public function rank() |
|
240 | |||
241 | /** |
||
242 | * is the user activated? |
||
243 | * |
||
244 | * @return bool |
||
245 | */ |
||
246 | 1 | public function isActive() |
|
253 | |||
254 | /** |
||
255 | * is the user currently logged in? |
||
256 | * |
||
257 | * @return bool |
||
258 | */ |
||
259 | 1 | public function isOnline() |
|
268 | |||
269 | /** |
||
270 | * getter |
||
271 | * |
||
272 | * @param string $format Dtype::FORMAT_xxxx constant |
||
273 | * |
||
274 | * @return mixed |
||
275 | */ |
||
276 | 2 | public function uid($format = '') |
|
280 | |||
281 | /** |
||
282 | * getter |
||
283 | * |
||
284 | * @param string $format Dtype::FORMAT_xxxx constant |
||
285 | * |
||
286 | * @return mixed |
||
287 | */ |
||
288 | 1 | public function id($format = Dtype::FORMAT_NONE) |
|
292 | |||
293 | /** |
||
294 | * getter |
||
295 | * |
||
296 | * @param string $format Dtype::FORMAT_xxxx constant |
||
297 | * |
||
298 | * @return mixed |
||
299 | */ |
||
300 | 1 | public function name($format = '') |
|
304 | |||
305 | /** |
||
306 | * getter |
||
307 | * |
||
308 | * @param string $format Dtype::FORMAT_xxxx constant |
||
309 | * |
||
310 | * @return mixed |
||
311 | */ |
||
312 | public function uname($format = '') |
||
316 | |||
317 | /** |
||
318 | * getter |
||
319 | * |
||
320 | * @param string $format Dtype::FORMAT_xxxx constant |
||
321 | * |
||
322 | * @return mixed |
||
323 | */ |
||
324 | 1 | public function email($format = '') |
|
328 | |||
329 | /** |
||
330 | * getter |
||
331 | * |
||
332 | * @param string $format Dtype::FORMAT_xxxx constant |
||
333 | * |
||
334 | * @return mixed |
||
335 | */ |
||
336 | 1 | public function url($format = '') |
|
340 | |||
341 | /** |
||
342 | * getter |
||
343 | * |
||
344 | * @param string $format Dtype::FORMAT_xxxx constant |
||
345 | * |
||
346 | * @return mixed |
||
347 | */ |
||
348 | 1 | public function user_avatar($format = '') |
|
352 | |||
353 | /** |
||
354 | * getter |
||
355 | * |
||
356 | * @param string $format Dtype::FORMAT_xxxx constant |
||
357 | * |
||
358 | * @return mixed |
||
359 | */ |
||
360 | 1 | public function user_regdate($format = '') |
|
364 | |||
365 | /** |
||
366 | * getter |
||
367 | * |
||
368 | * @param string $format Dtype::FORMAT_xxxx constant |
||
369 | * |
||
370 | * @return mixed |
||
371 | */ |
||
372 | 1 | public function user_icq($format = 'S') |
|
376 | |||
377 | /** |
||
378 | * getter |
||
379 | * |
||
380 | * @param string $format Dtype::FORMAT_xxxx constant |
||
381 | * |
||
382 | * @return mixed |
||
383 | */ |
||
384 | 1 | public function user_from($format = '') |
|
388 | |||
389 | /** |
||
390 | * getter |
||
391 | * |
||
392 | * @param string $format Dtype::FORMAT_xxxx constant |
||
393 | * |
||
394 | * @return mixed |
||
395 | */ |
||
396 | 1 | public function user_sig($format = '') |
|
400 | |||
401 | /** |
||
402 | * getter |
||
403 | * |
||
404 | * @param string $format Dtype::FORMAT_xxxx constant |
||
405 | * |
||
406 | * @return mixed |
||
407 | */ |
||
408 | 1 | public function user_viewemail($format = '') |
|
412 | |||
413 | /** |
||
414 | * getter |
||
415 | * |
||
416 | * @param string $format Dtype::FORMAT_xxxx constant |
||
417 | * |
||
418 | * @return mixed |
||
419 | */ |
||
420 | 1 | public function actkey($format = '') |
|
424 | |||
425 | /** |
||
426 | * getter |
||
427 | * |
||
428 | * @param string $format Dtype::FORMAT_xxxx constant |
||
429 | * |
||
430 | * @return mixed |
||
431 | */ |
||
432 | 1 | public function user_aim($format = '') |
|
436 | |||
437 | /** |
||
438 | * getter |
||
439 | * |
||
440 | * @param string $format Dtype::FORMAT_xxxx constant |
||
441 | * |
||
442 | * @return mixed |
||
443 | */ |
||
444 | 1 | public function user_yim($format = '') |
|
448 | |||
449 | /** |
||
450 | * getter |
||
451 | * |
||
452 | * @param string $format Dtype::FORMAT_xxxx constant |
||
453 | * |
||
454 | * @return mixed |
||
455 | */ |
||
456 | 1 | public function user_msnm($format = '') |
|
460 | |||
461 | /** |
||
462 | * getter |
||
463 | * |
||
464 | * @param string $format Dtype::FORMAT_xxxx constant |
||
465 | * |
||
466 | * @return mixed |
||
467 | */ |
||
468 | 2 | public function pass($format = '') |
|
472 | |||
473 | /** |
||
474 | * getter |
||
475 | * |
||
476 | * @param string $format Dtype::FORMAT_xxxx constant |
||
477 | * |
||
478 | * @return mixed |
||
479 | */ |
||
480 | 1 | public function posts($format = '') |
|
484 | |||
485 | /** |
||
486 | * getter |
||
487 | * |
||
488 | * @param string $format Dtype::FORMAT_xxxx constant |
||
489 | * |
||
490 | * @return mixed |
||
491 | */ |
||
492 | 1 | public function attachsig($format = '') |
|
496 | |||
497 | /** |
||
498 | * getter |
||
499 | * |
||
500 | * @param string $format Dtype::FORMAT_xxxx constant |
||
501 | * |
||
502 | * @return mixed |
||
503 | */ |
||
504 | 1 | public function level($format = '') |
|
508 | |||
509 | /** |
||
510 | * getter |
||
511 | * |
||
512 | * @param string $format Dtype::FORMAT_xxxx constant |
||
513 | * |
||
514 | * @return mixed |
||
515 | */ |
||
516 | 1 | public function theme($format = '') |
|
520 | |||
521 | /** |
||
522 | * getter |
||
523 | * |
||
524 | * @param string $format Dtype::FORMAT_xxxx constant |
||
525 | * |
||
526 | * @return mixed |
||
527 | */ |
||
528 | 1 | public function timezone($format = '') |
|
532 | |||
533 | /** |
||
534 | * getter |
||
535 | * |
||
536 | * @param string $format Dtype::FORMAT_xxxx constant |
||
537 | * |
||
538 | * @return mixed |
||
539 | */ |
||
540 | 1 | public function umode($format = '') |
|
544 | |||
545 | /** |
||
546 | * getter |
||
547 | * |
||
548 | * @param string $format Dtype::FORMAT_xxxx constant |
||
549 | * |
||
550 | * @return mixed |
||
551 | */ |
||
552 | 1 | public function uorder($format = '') |
|
556 | |||
557 | /** |
||
558 | * getter |
||
559 | * |
||
560 | * @param string $format Dtype::FORMAT_xxxx constant |
||
561 | * |
||
562 | * @return mixed |
||
563 | */ |
||
564 | 1 | public function notify_method($format = '') |
|
568 | |||
569 | /** |
||
570 | * getter |
||
571 | * |
||
572 | * @param string $format Dtype::FORMAT_xxxx constant |
||
573 | * |
||
574 | * @return mixed |
||
575 | */ |
||
576 | 1 | public function notify_mode($format = '') |
|
580 | |||
581 | /** |
||
582 | * getter |
||
583 | * |
||
584 | * @param string $format Dtype::FORMAT_xxxx constant |
||
585 | * |
||
586 | * @return mixed |
||
587 | */ |
||
588 | 1 | public function user_occ($format = '') |
|
592 | |||
593 | /** |
||
594 | * getter |
||
595 | * |
||
596 | * @param string $format Dtype::FORMAT_xxxx constant |
||
597 | * |
||
598 | * @return mixed |
||
599 | */ |
||
600 | 1 | public function bio($format = '') |
|
604 | |||
605 | /** |
||
606 | * getter |
||
607 | * |
||
608 | * @param string $format Dtype::FORMAT_xxxx constant |
||
609 | * |
||
610 | * @return mixed |
||
611 | */ |
||
612 | 1 | public function user_intrest($format = '') |
|
616 | } |
||
617 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: