Conditions | 5 |
Paths | 12 |
Total Lines | 57 |
Code Lines | 34 |
Lines | 3 |
Ratio | 5.26 % |
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 |
||
23 | public function usermenu() |
||
24 | { |
||
25 | $xoops = \Xoops::getInstance(); |
||
26 | $ret = array(); |
||
27 | if (!$xoops->isActiveModule('profile')) { |
||
28 | // View Account |
||
29 | $ret[] = [ |
||
30 | 'name' => XoopsLocale::VIEW_ACCOUNT, |
||
31 | 'link' => $xoops->url('userinfo.php?uid=' . $xoops->user->getVar('uid')), |
||
32 | 'icon' => 'glyphicon-user', |
||
33 | ]; |
||
34 | |||
35 | // Edit Account |
||
36 | $ret[] = [ |
||
37 | 'name' => XoopsLocale::EDIT_ACCOUNT, |
||
38 | 'link' => $xoops->url('edituser.php'), |
||
39 | 'icon' => 'glyphicon-pencil', |
||
40 | ]; |
||
41 | } |
||
42 | |||
43 | // Administration Menu |
||
44 | if ($xoops->isAdmin()) { |
||
45 | $ret[] = [ |
||
46 | 'name' => SystemLocale::ADMINISTRATION_MENU, |
||
47 | 'link' => $xoops->url('admin.php'), |
||
48 | 'icon' => 'glyphicon-wrench', |
||
49 | ]; |
||
50 | } |
||
51 | |||
52 | // Inbox |
||
53 | if (!$xoops->isActiveModule('pm')) { |
||
54 | $criteria = new CriteriaCompo(new Criteria('read_msg', 0)); |
||
55 | $criteria->add(new Criteria('to_userid', $xoops->user->getVar('uid'))); |
||
56 | $pm_handler = $xoops->getHandlerPrivateMessage(); |
||
57 | $xoops->events()->triggerEvent('system.blocks.system_blocks.usershow', array(&$pm_handler)); |
||
58 | |||
59 | $name = XoopsLocale::INBOX; |
||
60 | View Code Duplication | if ($pm_count = $pm_handler->getCount($criteria)) { |
|
|
|||
61 | $name = XoopsLocale::INBOX . ' <span class="badge">' . $pm_count . '</span>'; |
||
62 | } |
||
63 | |||
64 | $ret[] = [ |
||
65 | 'name' => $name, |
||
66 | 'link' => $xoops->url('viewpmsg.php'), |
||
67 | 'icon' => 'glyphicon-envelope', |
||
68 | ]; |
||
69 | } |
||
70 | |||
71 | // Logout |
||
72 | $ret[] = [ |
||
73 | 'name' => XoopsLocale::A_LOGOUT, |
||
74 | 'link' => $xoops->url('user.php?op=logout'), |
||
75 | 'icon' => 'glyphicon-log-out', |
||
76 | ]; |
||
77 | |||
78 | return $ret; |
||
79 | } |
||
80 | } |
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: