Completed
Push — master ( c622f7...33a06a )
by Richard
09:52 queued 02:32
created

SystemUsermenuPlugin::usermenu()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 55
Code Lines 33

Duplication

Lines 3
Ratio 5.45 %

Importance

Changes 0
Metric Value
cc 4
eloc 33
nc 6
nop 0
dl 3
loc 55
rs 9.078
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
14
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
15
 * @author          trabis <[email protected]>
16
 */
17
class SystemUsermenuPlugin implements UsermenuPluginInterface
18
{
19
20
    /**
21
     * @return array
22
     */
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)) {
0 ignored issues
show
Bug introduced by
The method getCount does only exist in XoopsPersistableObjectHandler, but not in XoopsObjectHandler.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
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
}