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

PmUsermenuPlugin   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 10 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 3
loc 30
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A usermenu() 3 23 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 PmUsermenuPlugin implements UsermenuPluginInterface
18
{
19
20
    /**
21
     * @return array
22
     */
23
    public function usermenu()
24
    {
25
        $xoops = \Xoops::getInstance();
26
        $helper = \Xoops::getModuleHelper('pm');
27
        $ret = array();
28
29
        $criteria = new CriteriaCompo(new Criteria('read_msg', 0));
30
        $criteria->add(new Criteria('to_userid', $xoops->user->getVar('uid')));
31
        $pm_handler = $helper->getHandler('message');
32
33
        $name = XoopsLocale::INBOX;
34 View Code Duplication
        if ($pm_count = $pm_handler->getCount($criteria)) {
35
            $name = XoopsLocale::INBOX . ' <span class="badge">' . $pm_count . '</span>';
36
        }
37
38
        $ret[] = [
39
            'name' => $name,
40
            'link' => $helper->url('viewpmsg.php'),
41
        ];
42
43
44
        return $ret;
45
    }
46
}