UserLanguage   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 39
c 0
b 0
f 0
dl 0
loc 70
rs 10
wmc 11

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getUserbar() 0 56 10
A __construct() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Newbb;
4
5
/**
6
 * User Language Class (moved from 'main' language file)
7
 * @subpackage:: class
8
 */
9
10
use XoopsModules\Newbb;
11
12
//require_once $GLOBALS['xoops']->path('modules/newbb/class/user.php');
13
14
/**
15
 * Allows setting for user information
16
 * If you have a customized userbar, define it here.
17
 */
18
class UserLanguage extends Newbb\User
19
{
20
    /**
21
     * UserLanguage constructor.
22
     * @param $user
23
     */
24
    public function __construct($user)
25
    {
26
        parent::__construct($user);
0 ignored issues
show
Unused Code introduced by
The call to XoopsModules\Newbb\User::__construct() has too many arguments starting with $user. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
        parent::/** @scrutinizer ignore-call */ 
27
                __construct($user);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
27
    }
28
29
    /**
30
     * @return array|null
31
     */
32
    public function getUserbar()
33
    {
34
        global $xoopsModuleConfig, $xoopsUser, $isadmin;
35
        if (empty($GLOBALS['xoopsModuleConfig']['userbar_enabled'])) {
36
            return null;
0 ignored issues
show
Bug Best Practice introduced by
The expression return null returns the type null which is incompatible with the return type mandated by XoopsModules\Newbb\User::getUserbar() of array<mixed,array<mixed,mixed|string>>.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
37
        }
38
        $user      = $this->user;
39
        $userbar   = [];
40
        $userbar[] = [
41
            'link' => $GLOBALS['xoops']->url('userinfo.php?uid=' . $user->getVar('uid')),
42
            'name' => PROFILE,
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Newbb\PROFILE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
43
        ];
44
        if (\is_object($xoopsUser)) {
45
            $userbar[] = [
46
                'link' => "javascript:void openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&amp;to_userid=' . $user->getVar('uid') . "','pmlite', 450, 380);",
47
                'name' => _MD_PM,
48
            ];
49
        }
50
        if ($isadmin || $user->getVar('user_viewemail')) {
51
            $userbar[] = [
52
                'link' => "javascript:void window.open('mailto:" . $user->getVar('email') . "','new');",
53
                'name' => _MD_EMAIL,
54
            ];
55
        }
56
        if ($user->getVar('url')) {
57
            $userbar[] = [
58
                'link' => "javascript:void window.open('" . $user->getVar('url') . "','new');",
59
                'name' => _MD_WWW,
60
            ];
61
        }
62
        if ($user->getVar('user_icq')) {
63
            $userbar[] = [
64
                'link' => "javascript:void window.open('https://wwp.icq.com/scripts/search.dll?to=" . $user->getVar('user_icq') . "','new');",
65
                'name' => _MD_ICQ,
66
            ];
67
        }
68
        if ($user->getVar('user_aim')) {
69
            $userbar[] = [
70
                'link' => "javascript:void window.open('aim:goim?screenname=" . $user->getVar('user_aim') . '&amp;message=Hi+' . $user->getVar('user_aim') . '+Are+you+there?' . "','new');",
71
                'name' => _MD_AIM,
72
            ];
73
        }
74
        if ($user->getVar('user_yim')) {
75
            $userbar[] = [
76
                'link' => "javascript:void window.open('https://edit.yahoo.com/config/send_webmesg?.target=" . $user->getVar('user_yim') . '&.src=pg' . "','new');",
77
                'name' => _MD_YIM,
78
            ];
79
        }
80
        if ($user->getVar('user_msnm')) {
81
            $userbar[] = [
82
                'link' => "javascript:void window.open('https://members.msn.com?mem=" . $user->getVar('user_msnm') . "','new');",
83
                'name' => _MD_MSNM,
84
            ];
85
        }
86
87
        return $userbar;
88
    }
89
}
90