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