Completed
Push — master ( 62af87...249590 )
by Michael
03:02
created

User.php ➔ newbb_calculateLevel()   F

Complexity

Conditions 11
Paths 1024

Size

Total Lines 72
Code Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 54
nc 1024
nop 2
dl 0
loc 72
rs 3.5064
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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 namespace XoopsModules\Newbb;
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 22 and the first side effect is on line 15.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/**
4
 * NewBB 5.0x,  the forum module for XOOPS project
5
 *
6
 * @copyright      XOOPS Project (https://xoops.org)
7
 * @license        GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
8
 * @author         Taiwen Jiang (phppp or D.J.) <[email protected]>
9
 * @since          4.00
10
 * @package        module::newbb
11
 */
12
13
// defined('XOOPS_ROOT_PATH') || exit('Restricted access.');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
14
15
defined('NEWBB_FUNCTIONS_INI') || include $GLOBALS['xoops']->path('modules/newbb/include/functions.ini.php');
16
17
/**
18
 * @param $RPG
19
 * @param $RPGDIFF
20
 * @return array|number
21
 */
22
function newbb_calculateLevel($RPG, $RPGDIFF)
0 ignored issues
show
Coding Style introduced by
function newbb_calculateLevel() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
$RPG does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
23
{
24
25
    //$RPG = $user->getVar('posts');
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
26
    //$RPGDIFF = $user->getVar('user_regdate');
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
27
28
    $today = time();
29
    $diff  = $today - $RPGDIFF;
0 ignored issues
show
Coding Style introduced by
$RPGDIFF does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
30
    $exp   = round($diff / 86400, 0);
31
    if ($exp <= 0) {
32
        $exp = 1;
33
    }
34
    $ppd       = round($RPG / $exp, 0);
0 ignored issues
show
Coding Style introduced by
$RPG does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
35
    $level     = pow(log10($RPG), 3);
0 ignored issues
show
Coding Style introduced by
$RPG does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
36
    $ep        = floor(100 * ($level - floor($level)));
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $ep. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
37
    $showlevel = floor($level + 1);
38
    $hpmulti   = round($ppd / 6, 1);
39
    if ($hpmulti > 1.5) {
40
        $hpmulti = 1.5;
41
    }
42
    if ($hpmulti < 1) {
43
        $hpmulti = 1;
44
    }
45
    $maxhp = $level * 25 * $hpmulti;
46
    $hp    = $ppd / 5;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $hp. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
47
    if ($hp >= 1) {
48
        $hp = $maxhp;
49
    } else {
50
        $hp = floor($hp * $maxhp);
51
    }
52
    $hp    = floor($hp);
53
    $maxhp = floor($maxhp);
54
    $zhp   = $maxhp;
55
    if ($maxhp <= 0) {
56
        $zhp = 1;
57
    }
58
    $hpf   = floor(100 * ($hp / $zhp)) - 1;
59
    $maxmp = ($exp * $level) / 5;
60
    $mp    = $RPG / 3;
0 ignored issues
show
Coding Style introduced by
$RPG does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $mp. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
61
    if ($mp >= $maxmp) {
62
        $mp = $maxmp;
63
    }
64
    $maxmp = floor($maxmp);
65
    $mp    = floor($mp);
66
    $zmp   = $maxmp;
67
    if ($maxmp <= 0) {
68
        $zmp = 1;
69
    }
70
    $mpf = floor(100 * ($mp / $zmp)) - 1;
71
    if ($hpf >= 98) {
72
        $hpf -= 2;
73
    }
74
    if ($ep >= 98) {
75
        $ep -= 2;
76
    }
77
    if ($mpf >= 98) {
78
        $mpf -= 2;
79
    }
80
81
    $level              = [];
82
    $level['level']     = $showlevel;
83
    $level['exp']       = $ep;
84
    $level['exp_width'] = $ep . '%';
85
    $level['hp']        = $hp;
86
    $level['hp_max']    = $maxhp;
87
    $level['hp_width']  = $hpf . '%';
88
    $level['mp']        = $mp;
89
    $level['mp_max']    = $maxmp;
90
    $level['mp_width']  = $mpf . '%';
91
92
    return $level;
93
}
94
95
/**
96
 * Class User
97
 */
98
class User
99
{
100
    public $user;
101
102
    public function __construct()
103
    {
104
    }
105
106
    /**
107
     * @return array
108
     */
109
    public function getUserbar()
0 ignored issues
show
Coding Style introduced by
getUserbar uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
110
    {
111
        global $isAdmin;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
112
113
        $userbar = [];
114
        if (empty($GLOBALS['xoopsModuleConfig']['userbar_enabled'])) {
115
            return $userbar;
116
        }
117
118
        $user               = $this->user;
119
        $userbar['profile'] = [
120
            'link' => XOOPS_URL . '/userinfo.php?uid=' . $user->getVar('uid'),
121
            'name' => _PROFILE
122
        ];
123
124
        if (is_object($GLOBALS['xoopsUser'])) {
125
            $userbar['pm'] = [
126
                'link' => "javascript:void openWithSelfMain('" . XOOPS_URL . '/pmlite.php?send2=1&amp;to_userid=' . $user->getVar('uid') . "', 'pmlite', 450, 380);",
127
                'name' => _MD_NEWBB_PM
128
            ];
129
        }
130
        if ($user->getVar('user_viewemail') || $isAdmin) {
131
            $userbar['email'] = [
132
                'link' => "javascript:void window.open('mailto:" . $user->getVar('email') . "', 'new');",
133
                'name' => _MD_NEWBB_EMAIL
134
            ];
135
        }
136
        if ($url = $user->getVar('url')) {
137
            $userbar['url'] = [
138
                'link' => "javascript:void window.open('" . $url . "', 'new');",
139
                'name' => _MD_NEWBB_WWW
140
            ];
141
        }
142
        if ($icq = $user->getVar('user_icq')) {
143
            $userbar['icq'] = [
144
                'link' => "javascript:void window.open('http://wwp.icq.com/scripts/search.dll?to=" . $icq . "', 'new');",
145
                'name' => _MD_NEWBB_ICQ
146
            ];
147
        }
148
        if ($aim = $user->getVar('user_aim')) {
149
            $userbar['aim'] = [
150
                'link' => "javascript:void window.open('aim:goim?screenname=" . $aim . '&amp;message=Hi+' . $aim . '+Are+you+there?' . "', 'new');",
151
                'name' => _MD_NEWBB_AIM
152
            ];
153
        }
154
        if ($yim = $user->getVar('user_yim')) {
155
            $userbar['yim'] = [
156
                'link' => "javascript:void window.open('http://edit.yahoo.com/config/send_webmesg?.target=" . $yim . '&.src=pg' . "', 'new');",
157
                'name' => _MD_NEWBB_YIM
158
            ];
159
        }
160
        if ($msn = $user->getVar('user_msnm')) {
161
            $userbar['msnm'] = [
162
                'link' => "javascript:void window.open('http://members.msn.com?mem=" . $msn . "', 'new');",
163
                'name' => _MD_NEWBB_MSNM
164
            ];
165
        }
166
167
        return $userbar;
168
    }
169
170
    /**
171
     * @return string
172
     */
173
    public function getLevel()
0 ignored issues
show
Coding Style introduced by
getLevel uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
174
    {
175
        global $forumUrl;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
176
177
        $level = newbb_calculateLevel($this->user->getVar('posts'), $this->user->getVar('user_regdate'));
178
        $info  = '';
0 ignored issues
show
Unused Code introduced by
$info is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
179
        if (2 == $GLOBALS['xoopsModuleConfig']['user_level']) {
180
            static $rpg_images;
181
            if (!isset($rpg_images)) {
0 ignored issues
show
Coding Style introduced by
$rpg_images does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
182
                $iconHandler = newbbGetIconHandler();
183
                $rpg_path    = $iconHandler->getPath('rpg');
0 ignored issues
show
Coding Style introduced by
$rpg_path does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
184
                foreach (['img_left', 'img_backing', 'img_right', 'blue', 'green', 'orange'] as $img) {
185
                    // irmtfan fix: double "/" removed
186
                    $rpg_images[$img] = XOOPS_URL . $rpg_path . '/' . $img . '.gif';
0 ignored issues
show
Coding Style introduced by
$rpg_images does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
187
                }
188
            }
189
            // irmtfan hardcore removed align="left"
190
            $table = "<table class='userlevel'><tr><td class='end'><img src='"
191
                     . $rpg_images['img_left']
0 ignored issues
show
Coding Style introduced by
$rpg_images does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
192
                     . "' alt='' /></td><td class='center' background='"
193
                     . $rpg_images['img_backing']
0 ignored issues
show
Coding Style introduced by
$rpg_images does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
194
                     . "'><img src='%s' width='%d' alt='' class='icon_left' /></td><td><img src='"
195
                     . $rpg_images['img_right']
0 ignored issues
show
Coding Style introduced by
$rpg_images does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
196
                     . "' alt='' /></td></tr></table>";
197
198
            $info = _MD_NEWBB_LEVEL . ' ' . $level['level'] . '<br><span title="' . _MD_NEWBB_HP_DESC . '">' . _MD_NEWBB_HP . ' ' . $level['hp'] . ' / ' . $level['hp_max'] . '</span><br>' . sprintf($table, $rpg_images['orange'], $level['hp_width']);
0 ignored issues
show
Coding Style introduced by
$rpg_images does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
199
            $info .= '<span title="' . _MD_NEWBB_MP_DESC . '">' . _MD_NEWBB_MP . ' ' . $level['mp'] . ' / ' . $level['mp_max'] . '</span><br>' . sprintf($table, $rpg_images['green'], $level['mp_width']);
0 ignored issues
show
Coding Style introduced by
$rpg_images does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
200
            $info .= '<span title="' . _MD_NEWBB_EXP_DESC . '">' . _MD_NEWBB_EXP . ' ' . $level['exp'] . '</span><br>' . sprintf($table, $rpg_images['blue'], $level['exp_width']);
0 ignored issues
show
Coding Style introduced by
$rpg_images does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
201
        } else {
202
            $info = _MD_NEWBB_LEVEL . ' ' . $level['level'] . '; <span title="' . _MD_NEWBB_EXP_DESC . '">' . _MD_NEWBB_EXP . ' ' . $level['exp'] . '</span><br>';
203
            $info .= '<span title="' . _MD_NEWBB_HP_DESC . '">' . _MD_NEWBB_HP . ' ' . $level['hp'] . ' / ' . $level['hp_max'] . '</span><br>';
204
            $info .= '<span title="' . _MD_NEWBB_MP_DESC . '">' . _MD_NEWBB_MP . ' ' . $level['mp'] . ' / ' . $level['mp_max'] . '</span>';
205
        }
206
207
        return $info;
208
    }
209
210
    /**
211
     * @param \XoopsUser $user
212
     * @return mixed
213
     */
214
    public function getInfo(&$user)
0 ignored issues
show
Coding Style introduced by
getInfo uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
215
    {
216
        global $myts;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
217
        static $name_anonymous;
218
219
        if (!is_object($user) || !$user->isActive()) {
220
            if (!isset($name_anonymous)) {
0 ignored issues
show
Coding Style introduced by
$name_anonymous does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
221
                $name_anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']);
0 ignored issues
show
Coding Style introduced by
$name_anonymous does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
222
            }
223
224
            return ['name' => $name_anonymous, 'link' => $name_anonymous];
0 ignored issues
show
Coding Style introduced by
$name_anonymous does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
225
        }
226
227
        $this->user = $user;
228
229
        $userinfo['uid'] = $user->getVar('uid');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$userinfo was never initialized. Although not strictly required by PHP, it is generally a good practice to add $userinfo = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
230
231
        $name             = empty($GLOBALS['xoopsModuleConfig']['show_realname']) ? $user->getVar('uname') : $user->getVar('name');
232
        $userinfo['name'] = $name ?: $user->getVar('uname');
233
234
        $userinfo['link'] = '<a href=\'' . XOOPS_URL . '/userinfo.php?uid=' . $user->getVar('uid') . '\'>' . $userinfo['name'] . '</a>';
235
236
        $userinfo['avatar'] = $user->getVar('user_avatar');
237
        // START hacked by irmtfan - easier rank getting - consistency with previous version back rank.title and rank.image
238
        $userrank         = $user->rank();
239
        $userinfo['rank'] = [];
240
        if (isset($userrank['image']) && $userrank['image']) {
241
            $userinfo['rank']['image'] = $userrank['image'];
242
            $userinfo['rank']['title'] = $userrank['title'];
243
        }
244
        // END hacked by irmtfan - easier rank getting  - a little correctness dot removed
245
        // START hacked by irmtfan - easier groups getting - can we use $_SESSION['xoopsUserGroups']???
246
        //checks for user's groups
247
        $userinfo['groups'] = [];
248
        /** @var \XoopsMemberHandler $memberHandler */
249
        $memberHandler = xoops_getHandler('member');
250
        $usergroups    = $memberHandler->getGroupsByUser($userinfo['uid'], true);
251
        foreach ($usergroups as $group) {
252
            $userinfo['groups'][] = $group->getVar('name');
253
        }
254
        // END hacked by irmtfan - easier groups getting - can we use $_SESSION['xoopsUserGroups']???
255
        $userinfo['from'] = $user->getVar('user_from');
256
257
        include_once __DIR__ . '/../include/functions.time.php';
258
        $userinfo['regdate']    = newbbFormatTimestamp($user->getVar('user_regdate'), 'reg');
259
        $userinfo['last_login'] = newbbFormatTimestamp($user->getVar('last_login')); // irmtfan add last_login
260
261
        $userinfo['posts'] = $user->getVar('posts');
262
263
        if (!empty($GLOBALS['xoopsModuleConfig']['user_level'])) {
264
            $userinfo['level'] = $this->getLevel();
265
        }
266
267
        if (!empty($GLOBALS['xoopsModuleConfig']['userbar_enabled'])) {
268
            $userinfo['userbar'] = $this->getUserbar();
269
        }
270
271
        $userinfo['signature'] = $user->getVar('user_sig');
272
273
        return $userinfo;
274
    }
275
}
276