Completed
Push — master ( fd0c8a...c024a6 )
by
unknown
03:33 queued 01:53
created

WallUpdates::ParsePubArray()   F

Complexity

Conditions 28
Paths > 20000

Size

Total Lines 128

Duplication

Lines 128
Ratio 100 %

Importance

Changes 0
Metric Value
cc 28
nc 76804
nop 2
dl 128
loc 128
rs 0
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\smallworld;
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
 * SmallWorld
14
 *
15
 * @copyright    The XOOPS Project (https://xoops.org)
16
 * @copyright    2011 Culex
17
 * @license      GNU GPL (http://www.gnu.org/licenses/gpl-2.0.html/)
18
 * @package      SmallWorld
19
 * @since        1.0
20
 * @author       Michael Albertsen (http://culex.dk) <[email protected]>
21
 */
22
23
//include_once $GLOBALS['xoops']->path('include/common.php');
24
25
// Moderated and fitted from the tutorial by Srinivas Tamada http://9lessons.info
26
27
class WallUpdates
28
{
29
    /**
30
     * @return array
31
     */
32
    private function getAdminModerators()
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
33
    {
34
        global $xoopsDB, $xoopsUser;
35
        $data = [];
36
        $sql    = 'SELECT userid
37
                FROM ' . $xoopsDB->prefix('smallworld_user') . ' su
38
                LEFT JOIN ' . $xoopsDB->prefix('groups_users_link') . ' xu ON su.userid = xu.uid
39
                WHERE xu.uid IN (1)';
40
        $result = $xoopsDB->queryF($sql);
41
        while ($row = $xoopsDB->fetchArray($result)) {
42
            $data[] = $row;
43
        }
44
        return $data;
45
    }
46
47
    /**
48
     * @param $last
49
     * @param $uid
50
     * @param $followers
51
     * @return array|bool
0 ignored issues
show
Documentation introduced by
Should the return type not be false|array|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
52
     */
53 View Code Duplication
    public function Updates($last, $uid, $followers)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        global $xoopsUser, $xoopsDB, $moduleConfig;
56
        $query = '';
57
        $hm        = smallworld_GetModuleOption('msgtoshow');
58
        $set       = smallworld_checkPrivateOrPublic();
0 ignored issues
show
Unused Code introduced by
$set 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...
59
        $followers = is_array($followers) ? $followers : [$followers];
60
        $followers = array_unique(Smallworld_array_flatten($followers, 0));
61
62
        $i = 0;
63
        if (0 == $last) {
64
            $query = 'SELECT M.msg_id, M.uid_fk, M.priv, M.message, M.created, U.username FROM ' . $xoopsDB->prefix('smallworld_messages') . ' M, ' . $xoopsDB->prefix('smallworld_user') . " U  WHERE M.uid_fk=U.userid AND M.uid_fk='" . $uid . "'";
65
        } elseif ($last > 0) {
66
            $query = 'SELECT M.msg_id, M.uid_fk, M.priv, M.message, M.created, U.username FROM ' . $xoopsDB->prefix('smallworld_messages') . ' M, ' . $xoopsDB->prefix('smallworld_user') . " U  WHERE M.uid_fk=U.userid AND M.uid_fk='" . $uid . "' AND M.msg_id < '" . $last . "'";
67
        } elseif ('a' === $last) {
68
            $query = 'SELECT M.msg_id, M.uid_fk, M.priv, M.message, M.created, U.username FROM ' . $xoopsDB->prefix('smallworld_messages') . ' M, ' . $xoopsDB->prefix('smallworld_user') . " U  WHERE M.uid_fk=U.userid AND M.uid_fk='" . $uid . "'";
69
        }
70
71
        if (is_array($followers)) {
72
            foreach ($followers as $k => $v) {
73
                if ($last > 0) {
74
                    $query .= " OR M.uid_fk=U.userid and M.uid_fk= '" . $v . "' and M.msg_id < '" . $last . "'";
75
                } elseif (0 == $last) {
76
                    $query .= " OR M.uid_fk=U.userid and M.uid_fk= '" . $v . "'";
77
                } elseif ('a' === $last) {
78
                    $query .= " OR M.uid_fk=U.userid and M.uid_fk= '" . $v . "'";
79
                }
80
                ++$i;
81
            }
82
        }
83
        if (!is_array($followers)) {
84
            $followers = $uid;
85
            if ($last > 0) {
86
                $query .= " OR M.uid_fk=U.userid and M.uid_fk= '" . $followers . "' and M.msg_id < '" . $last . "'";
87
            } elseif (0 == $last) {
88
                $query .= " OR M.uid_fk=U.userid and M.uid_fk= '" . $followers . "'";
89
            } elseif ('a' === $last) {
90
                $query .= " OR M.uid_fk=U.userid and M.uid_fk= '" . $followers . "'";
91
            }
92
        }
93
94
        if ($last > 0) {
95
            $query .= ' order by created DESC LIMIT ' . $hm;
96
        } elseif ('a' === $last) {
97
            $query .= ' order by M.msg_id DESC LIMIT ' . $hm;
98
        } else {
99
            $query .= ' order by created DESC LIMIT ' . $hm;
100
        }
101
        $result = $xoopsDB->queryF($query);
102
        $count  = $xoopsDB->getRowsNum($result);
103
        if (0 == $count) {
104
            return false;
105
        } else {
106
            while ($row = $xoopsDB->fetchArray($result)) {
107
                $data[] = $row;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = 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...
108
            }
109
            if (!empty($data)) {
110
                return $data;
111
            }
112
        }
113
    }
114
115
    /**
116
     * @Get comments based on msg id
117
     * @param int $msg_id
118
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be array|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
119
     */
120 View Code Duplication
    public function Comments($msg_id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
121
    {
122
        global $xoopsUser, $xoopsDB;
123
        $query  = 'SELECT C.msg_id_fk, C.com_id, C.uid_fk, C.comment, C.created, U.username FROM ' . $xoopsDB->prefix('smallworld_comments') . ' C, ' . $xoopsDB->prefix('smallworld_user') . " U WHERE C.uid_fk=U.userid AND C.msg_id_fk='" . $msg_id . "' ORDER BY C.com_id ASC ";
124
        $result = $xoopsDB->queryF($query);
125
        $i      = $xoopsDB->getRowsNum($result);
0 ignored issues
show
Unused Code introduced by
$i 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...
126
        while ($row = $xoopsDB->fetchArray($result)) {
127
            $data[] = $row;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = 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...
128
        }
129
        if (!empty($data)) {
130
            return $data;
131
        }
132
    }
133
134
    /**
135
     * @Get user image based on uid
136
     * @param int $uid
137
     * @return string
138
     */
139 View Code Duplication
    public function Gravatar($uid)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
140
    {
141
        global $xoopsUser, $xoopsDB;
142
        $image  = '';
143
        $sql    = 'SELECT userimage FROM ' . $xoopsDB->prefix('smallworld_user') . " WHERE userid = '" . $uid . "'";
144
        $result = $xoopsDB->queryF($sql);
145
        while ($r = $xoopsDB->fetchArray($result)) {
146
            $image = $r['userimage'];
147
        }
148
149
        $image = ('' == $image || 'blank.gif' === $image) ? smallworld_getAvatarLink($uid, $image) : $image;
150
151
        $type = [
152
            1 => 'jpg',
153
            2 => 'jpeg',
154
            3 => 'png',
155
            4 => 'gif'
156
        ];
157
158
        $ext = explode('.', $image);
159
160
        if (@!in_array(strtolower($ext[1]), $type) || '' == $image) {
161
            $avatar = '';
162
        } else {
163
            $avatar = $image;
164
        }
165
        return $avatar;
166
    }
167
168
    /**
169
     * @Insert update
170
     * @param int    $uid
171
     * @param string|array $update
172
     * @param int    $priv
173
     * @return array|bool
0 ignored issues
show
Documentation introduced by
Should the return type not be false|array|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
174
     */
175 View Code Duplication
    public function Insert_Update($uid, $update, $priv)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
176
    {
177
        global $xoopsUser, $xoopsDB;
178
        $update = Smallworld_sanitize(htmlentities($update, ENT_QUOTES, 'UTF-8'));
179
        $time   = time();
180
        if (!isset($priv)) {
181
            $priv = 0;
182
        }
183
        $query  = 'SELECT msg_id,message FROM ' . $xoopsDB->prefix('smallworld_messages') . " WHERE uid_fk='" . $uid . "' ORDER BY msg_id DESC LIMIT 1";
184
        $result = $xoopsDB->queryF($query);
185
        $row = $xoopsDB->fetchArray($result);
186
        if ($update != $row['message']) {
187
            $query    = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_messages') . " (message, uid_fk, priv, created) VALUES ('" . $update . "', '" . $uid . "', '" . $priv . "', '" . $time . "')";
188
            $result   = $xoopsDB->queryF($query);
0 ignored issues
show
Unused Code introduced by
$result 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...
189
            $newquery = 'SELECT M.msg_id, M.uid_fk, M.priv, M.message, M.created, U.username FROM ' . $xoopsDB->prefix('smallworld_messages') . ' M, ' . $xoopsDB->prefix('smallworld_user') . " U WHERE M.uid_fk=U.userid AND M.uid_fk='" . $uid . "' ORDER BY M.msg_id DESC LIMIT 1 ";
190
            $result2  = $xoopsDB->queryF($newquery);
191
            while ($row = $xoopsDB->fetchArray($result2)) {
192
                $data[] = $row;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = 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...
193
            }
194
            $count = $xoopsDB->getRowsNum($result2);
195
            if ($count < 1) {
196
                return false;
197
            } else {
198
                while ($row = $xoopsDB->fetchArray($result2)) {
199
                    $data[] = $row;
0 ignored issues
show
Bug introduced by
The variable $data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
200
                }
201
                if (!empty($data)) {
202
                    return $data;
203
                }
204
            }
205
        }
206
    }
207
208
    /**
209
     * @Insert comment
210
     * @param int    $uid
211
     * @param  int    $msg_id
212
     * @param string|array $comment
213
     * @return string / void
214
     */
215 View Code Duplication
    public function Insert_Comment($uid, $msg_id, $comment)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
216
    {
217
        global $xoopsUser, $xoopsDB;
218
        $comment = Smallworld_sanitize(htmlentities($comment, ENT_QUOTES, 'UTF-8'));
219
        $time    = time();
220
        $query   = 'SELECT com_id,comment FROM ' . $xoopsDB->prefix('smallworld_comments') . " WHERE uid_fk='" . $uid . "' AND msg_id_fk='" . $msg_id . "' ORDER BY com_id DESC LIMIT 1 ";
221
        $result  = $xoopsDB->fetchArray($query);
222
        if ($comment != $result['comment']) {
223
            $query    = 'INSERT INTO ' . $xoopsDB->prefix('smallworld_comments') . " (comment, uid_fk,msg_id_fk,created) VALUES ('" . $comment . "', '" . $uid . "','" . $msg_id . "', '" . $time . "')";
224
            $result   = $xoopsDB->queryF($query);
0 ignored issues
show
Unused Code introduced by
$result 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...
225
            $newquery = 'SELECT C.com_id, C.uid_fk, C.comment, C.msg_id_fk, C.created, U.username FROM '
226
                        . $xoopsDB->prefix('smallworld_comments')
227
                        . ' C, '
228
                        . $xoopsDB->prefix('smallworld_user')
229
                        . " U WHERE C.uid_fk=U.userid AND C.uid_fk='"
230
                        . $uid
231
                        . "' AND C.msg_id_fk='"
232
                        . $msg_id
233
                        . "' ORDER BY C.com_id DESC LIMIT 1 ";
234
            $result2  = $xoopsDB->queryF($newquery);
235
            while ($row = $xoopsDB->fetchArray($result2)) {
236
                $data[0] = $row;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = 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...
237
            }
238
            return $data[0];
0 ignored issues
show
Bug introduced by
The variable $data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
239
        } else {
240
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by Xoopsmodules\smallworld\...Updates::Insert_Comment of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
241
        }
242
    }
243
244
    /**
245
     * @Get array of users followers
246
     * @param int $me
247
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be array|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
248
     */
249 View Code Duplication
    public function getFollowers($me)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
250
    {
251
        global $xoopsDB, $xoopsUser;
252
        $query  = 'SELECT you FROM ' . $xoopsDB->prefix('smallworld_followers') . " WHERE me = '" . $me . "'";
253
        $result = $xoopsDB->queryF($query);
254
        $i      = $xoopsDB->getRowsNum($result);
255
        while ($row = $xoopsDB->fetchArray($result)) {
256
            $data[] = $row;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = 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...
257
        }
258
        if (0 == $i) {
259
            $data = [$me];
260
        }
261
        if (!empty($data)) {
262
            return $data;
263
        }
264
    }
265
266
    /**
267
     * @count all votes
268
     * @param int $type
269
     * @param int $val
270
     * @param int $msgid
271
     * @return int
272
     */
273
    public function countVotes($type, $val, $msgid)
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
274
    {
275
        global $xoopsUser, $xoopsDB;
276
        $query  = 'Select SUM(' . $val . ') as sum from ' . $xoopsDB->prefix('smallworld_vote') . " where msg_id = '" . $msgid . "' and com_id = '0'";
277
        $result = $xoopsDB->queryF($query);
278
        while ($row = $xoopsDB->fetchArray($result)) {
279
            $sum = $row['sum'];
280
        }
281
        if ('' == $sum) {
0 ignored issues
show
Bug introduced by
The variable $sum does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
282
            $sum = '0';
283
        }
284
        return $sum;
285
    }
286
287
    /**
288
     * @Count comments votes
289
     * @param int $type
290
     * @param int $val
291
     * @param int $comid
292
     * @param int $msgid
293
     * @returns int
294
     */
295 View Code Duplication
    public function countVotesCom($type, $val, $comid, $msgid)
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
296
    {
297
        global $xoopsUser, $xoopsDB;
298
        $query  = 'Select SUM(' . $val . ') as sum from ' . $xoopsDB->prefix('smallworld_vote') . " where com_id = '" . $comid . "' AND msg_id = '" . $msgid . "'";
299
        $result = $xoopsDB->queryF($query);
300
        while ($row = $xoopsDB->fetchArray($result)) {
301
            $sum = $row['sum'];
302
        }
303
        if ('' == $sum) {
0 ignored issues
show
Bug introduced by
The variable $sum does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
304
            $sum = '0';
305
        }
306
        return $sum;
307
    }
308
309
    /**
310
     * @Check if user is friend
311
     * @param int    $userid
312
     * @param string $type
313
     * @param int    $comid
314
     * @param int    $msgid
315
     * @return int
316
     */
317 View Code Duplication
    public function HasVoted($userid, $type, $comid, $msgid)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
318
    {
319
        global $xoopsUser, $xoopsDB;
320
        if ('msg' === $type) {
321
            $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_vote') . " WHERE com_id = '0' AND msg_id = '" . $msgid . "' AND user_id = '" . $userid . "'";
322
            $result = $xoopsDB->queryF($sql);
323
            $i      = $xoopsDB->getRowsNum($result);
324
        } else {
325
            $sql    = 'SELECT * FROM ' . $xoopsDB->prefix('smallworld_vote') . " WHERE com_id = '" . $comid . "' AND msg_id = '" . $msgid . "' AND user_id = '" . $userid . "'";
326
            $result = $xoopsDB->queryF($sql);
327
            $i      = $xoopsDB->getRowsNum($result);
328
        }
329
        return $i;
330
    }
331
332
    /**
333
     * @count messages per user
334
     * @param int $userid
335
     * @return int
336
     */
337
    public function CountMsges($userid)
338
    {
339
        global $xoopsDB;
340
        $sql    = 'SELECT (SELECT COUNT(*) FROM ' . $xoopsDB->prefix('smallworld_comments') . " WHERE uid_fk = '" . $userid . "') + (SELECT COUNT(*) FROM " . $xoopsDB->prefix('smallworld_messages') . " WHERE uid_fk = '" . $userid . "')";
341
        $result = $xoopsDB->queryF($sql);
342
        $sum    = $xoopsDB->fetchRow($result);
343
        return $sum[0];
344
    }
345
346
    /**
347
     * @Show permaling updates
348
     * @param int $updid
349
     * @param int $uid
350
     * @param int $ownerID
351
     * @return array|bool
0 ignored issues
show
Documentation introduced by
Should the return type not be false|array|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
352
     */
353
    public function UpdatesPermalink($updid, $uid, $ownerID)
0 ignored issues
show
Unused Code introduced by
The parameter $uid is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
354
    {
355
        global $xoopsUser, $xoopsDB, $moduleConfig;
356
        $query  = 'SELECT M.msg_id, M.uid_fk, M.message, M.created, M.priv, U.username FROM ' . $xoopsDB->prefix('smallworld_messages') . ' M, ' . $xoopsDB->prefix('smallworld_user') . " U  WHERE M.uid_fk=U.userid AND M.uid_fk='" . $ownerID . "'";
357
        $query  .= " AND M.msg_id = '" . $updid . "'";
358
        $query  .= ' order by M.created DESC LIMIT 1';
359
        $result = $xoopsDB->queryF($query);
360
        $count  = $xoopsDB->getRowsNum($result);
361
        if ($count < 1) {
362
            return false;
363
        } else {
364
            while ($row = $xoopsDB->fetchArray($result)) {
365
                $data[] = $row;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = 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...
366
            }
367
            if (!empty($data)) {
368
                return $data;
369
            }
370
        }
371
    }
372
373
    /**
374
     * @Get share link
375
     * @param int $updid
376
     * @param int $ownerID
377
     * @return array|bool
0 ignored issues
show
Documentation introduced by
Should the return type not be false|array|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
378
     */
379 View Code Duplication
    public function UpdatesSharelink($updid, $ownerID)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
380
    {
381
        global $xoopsUser, $xoopsDB, $moduleConfig, $xoopsLogger;
382
        $xoopsLogger->activated = false;
383
        //error_reporting(E_ALL);
384
        $query  = 'SELECT M.msg_id, M.uid_fk, M.message, M.created, M.priv, U.username FROM ' . $xoopsDB->prefix('smallworld_messages') . ' M, ' . $xoopsDB->prefix('smallworld_user') . " U WHERE M.uid_fk=U.userid AND M.uid_fk='" . $ownerID . "' AND M.priv = 0";
385
        $query  .= " AND M.msg_id = '" . $updid . "'";
386
        $query  .= ' order by created DESC LIMIT 1';
387
        $result = $xoopsDB->queryF($query);
388
        $count  = $xoopsDB->getRowsNum($result);
389
        if ($count < 1) {
390
            return false;
391
        } else {
392
            while ($row = $xoopsDB->fetchArray($result)) {
393
                $data[] = $row;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = 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...
394
            }
395
            if (!empty($data)) {
396
                return $data;
397
            }
398
        }
399
    }
400
401
    /**
402
     * @Get sharing link
403
     * @param int $id
404
     * @param int $priv
405
     * @return string
406
     */
407 View Code Duplication
    public function GetSharing($id, $priv)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
408
    {
409
        if (1 != $priv) {
410
            $text = " | <span class='smallworld_share' id='smallworld_share'>";
411
            $text .= "<a class='share' id='share-page" . $id . "' href='javascript:void(0);'>" . _SMALLWORLD_SHARELINK . '</a></span>';
412
        } else {
413
            $text = '';
414
        }
415
        return $text;
416
    }
417
418
    /**
419
     * @Get content for sharing div
420
     * @param int    $id
421
     * @param int    $priv
422
     * @param string $permalink
423
     * @param string $desc
424
     * @param string $username
425
     * @return string
426
     */
427 View Code Duplication
    public function GetSharingDiv($id, $priv, $permalink, $desc, $username)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
428
    {
429
        if (1 != $priv) {
430
            $text = "<div style='display: none;' class='smallworld_bookmarks' id='share-page' name='share-page" . $id . "'>";
431
            $text .= "<span name='share-page" . $id . "' rel1='" . $desc . "' rel2= '" . $username . "' rel=" . $permalink . " id='basicBookmark' title='" . _SMALLWORLD_SHAREBOX_TITLE . "'>";
432
            $text .= '</span></div>';
433
        } else {
434
            $text = '';
435
        }
436
        return $text;
437
    }
438
439
    /**
440
     * @Parse update and comments array to template for public updates
441
     * @param array $updatesarray
442
     * @param int   $id
443
     * @return void
444
     */
445 View Code Duplication
    public function ParsePubArray($updatesarray, $id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
446
    {
447
        global $xoopsUser, $xoopsTpl, $tpl, $xoopsModule, $xoopsConfig;
448
449
        $check          = new SmallWorldUser;
450
        $dBase          = new SmallWorldDB;
451
        $profile        = $xoopsUser ? $check->checkIfProfile($id) : 0;
452
        $moduleHandler = xoops_getHandler('module');
453
        $module         = $moduleHandler->getByDirname('smallworld');
454
        $configHandler = xoops_getHandler('config');
455
        $moduleConfig   = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
0 ignored issues
show
Unused Code introduced by
$moduleConfig 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...
456
457
        $myavatar          = $this->Gravatar($id);
458
        $myavatarlink      = smallworld_getAvatarLink($id, $myavatar);
459
        $myavatar_size     = smallworld_getImageSize(80, 100, $myavatarlink);
0 ignored issues
show
Documentation introduced by
$myavatarlink is of type string, but the function expects a object<url>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
460
        $myavatar_highwide = smallworld_imageResize($myavatar_size[0], $myavatar_size[1], 35);
461
462
        $xoopsTpl->assign('myavatar', $myavatar);
463
        $xoopsTpl->assign('myavatarlink', $myavatarlink);
464
        $xoopsTpl->assign('myavatar_highwide', $myavatar_highwide);
465
466
        if (!empty($updatesarray)) {
467
            foreach ($updatesarray as $data) {
468
469
                // Is update's user a friend ?
470
                $frU = $check->friendcheck($id, $data['uid_fk']);
471
472
                $USW             = [];
473
                $USW['posts']    = 0;
474
                $USW['comments'] = 0;
475
476
                if ($xoopsUser) {
477
                    if ($xoopsUser->isAdmin($xoopsModule->getVar('mid')) || $data['uid_fk'] == $id) {
478
                        $USW['posts']    = 1;
479
                        $USW['comments'] = 1;
480
                        $frU[0]          = 2;
481
                    } else {
482
                        $USW = json_decode($dBase->GetSettings($data['uid_fk']), true);
483
                    }
484
                }
485
486
                if (!$xoopsUser) {
487
                    $USW = json_decode($dBase->GetSettings($data['uid_fk']), true);
488
                }
489
490
                $wm['msg_id']          = $data['msg_id'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$wm was never initialized. Although not strictly required by PHP, it is generally a good practice to add $wm = 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...
491
                $wm['orimessage']      = (1 == $USW['posts'] || $profile >= 2) ? str_replace(["\r", "\n"], '', Smallworld_stripWordsKeepUrl($data['message'])) : '';
0 ignored issues
show
Bug introduced by
The variable $wm does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
492
                $wm['message']         = (1 == $USW['posts'] || $profile >= 2) ? smallworld_tolink(htmlspecialchars_decode($data['message']), $data['uid_fk']) : _SMALLWORLD_MESSAGE_PRIVSETPOSTS;
493
                $wm['message']         = Smallworld_cleanup($wm['message']);
494
                $wm['created']         = smallworld_time_stamp($data['created']);
495
                $wm['username']        = $data['username'];
496
                $wm['uid_fk']          = $data['uid_fk'];
497
                $wm['priv']            = $data['priv'];
498
                $wm['avatar']          = $this->Gravatar($data['uid_fk']);
499
                $wm['avatar_link']     = smallworld_getAvatarLink($data['uid_fk'], $wm['avatar']);
500
                $wm['avatar_size']     = smallworld_getImageSize(80, 100, $wm['avatar_link']);
0 ignored issues
show
Documentation introduced by
$wm['avatar_link'] is of type string, but the function expects a object<url>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
501
                $wm['avatar_highwide'] = smallworld_imageResize($wm['avatar_size'][0], $wm['avatar_size'][1], 50);
502
                $wm['vote_up']         = $this->countVotes('msg', 'up', $data['msg_id']);
503
                $wm['vote_down']       = $this->countVotes('msg', 'down', $data['msg_id']);
504
                $wm['sharelinkurl']    = XOOPS_URL . '/modules/smallworld/smallworldshare.php?ownerid=' . $data['uid_fk'];
505
                $wm['sharelinkurl']    .= '&updid=' . $data['msg_id'] . '';
506
                $wm['usernameTitle']   = $wm['username'] . _SMALLWORLD_UPDATEONSITEMETA . $xoopsConfig['sitename'];
507
                if (1 == $USW['posts'] || $profile >= 2) {
508
                    $wm['sharelink'] = $this->GetSharing($wm['msg_id'], $wm['priv']);
509
                } else {
510
                    $wm['sharelink'] = $this->GetSharing($wm['msg_id'], 1);
511
                }
512
513
                if (1 == $USW['posts'] || $profile >= 2) {
514
                    $wm['sharediv'] = $this->GetSharingDiv($wm['msg_id'], $wm['priv'], $wm['sharelinkurl'], $wm['orimessage'], $wm['usernameTitle']);
515
                } else {
516
                    $wm['sharediv'] = $this->GetSharingDiv($wm['msg_id'], 1, $wm['sharelinkurl'], $wm['orimessage'], $wm['usernameTitle']);
517
                }
518
                $wm['linkimage']     = XOOPS_URL . '/modules/smallworld/assets/images/link.png';
519
                $wm['permalink']     = XOOPS_URL . '/modules/smallworld/permalink.php?ownerid=' . $data['uid_fk'] . '&updid=' . $data['msg_id'];
520
                $wm['commentsarray'] = $this->Comments($data['msg_id']);
521
522
                if (2 == $frU[0] || 1 == $USW['posts']) {
523
                    $xoopsTpl->append('walldata', $wm);
524
                }
525
526
                if (!empty($wm['commentsarray'])) {
527
                    foreach ($wm['commentsarray'] as $cdata) {
528
                        // Is commentuser a friend ?
529
                        $frC = $check->friendcheck($id, $cdata['uid_fk']);
530
531
                        $USC             = [];
532
                        $USC['posts']    = 0;
533
                        $USC['comments'] = 0;
534
535
                        if ($xoopsUser) {
536
                            if ($xoopsUser->isAdmin($xoopsModule->getVar('mid')) || $cdata['uid_fk'] == $id) {
537
                                $USC['posts']    = 1;
538
                                $USC['comments'] = 1;
539
                                $frC[0]          = 2;
540
                            } else {
541
                                $USC = json_decode($dBase->GetSettings($cdata['uid_fk']), true);
542
                            }
543
                        }
544
545
                        if (!$xoopsUser) {
546
                            $USC = json_decode($dBase->GetSettings($cdata['uid_fk']), true);
547
                        }
548
549
                        $wc['msg_id_fk']       = $cdata['msg_id_fk'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$wc was never initialized. Although not strictly required by PHP, it is generally a good practice to add $wc = 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...
550
                        $wc['com_id']          = $cdata['com_id'];
551
                        $wc['comment']         = (1 == $USC['comments'] || $profile >= 2) ? smallworld_tolink(htmlspecialchars_decode($cdata['comment']), $cdata['uid_fk']) : _SMALLWORLD_MESSAGE_PRIVSETCOMMENTS;
552
                        $wc['comment']         = Smallworld_cleanup($wc['comment']);
553
                        $wc['time']            = smallworld_time_stamp($cdata['created']);
554
                        $wc['username']        = $cdata['username'];
555
                        $wc['uid']             = $cdata['uid_fk'];
556
                        $wc['myavatar']        = $this->Gravatar($id);
557
                        $wc['myavatar_link']   = $myavatarlink;
558
                        $wc['avatar_size']     = smallworld_getImageSize(80, 100, $wc['myavatar_link']);
0 ignored issues
show
Documentation introduced by
$wc['myavatar_link'] is of type string, but the function expects a object<url>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
559
                        $wc['avatar_highwide'] = smallworld_imageResize($wc['avatar_size'][0], $wc['avatar_size'][1], 35);
560
                        $wc['cface']           = $this->Gravatar($cdata['uid_fk']);
561
                        $wc['avatar_link']     = smallworld_getAvatarLink($cdata['uid_fk'], $wc['cface']);
562
                        $wc['vote_up']         = $this->countVotesCom('com', 'up', $cdata['msg_id_fk'], $cdata['com_id']);
563
                        $wc['vote_down']       = $this->countVotesCom('com', 'down', $cdata['msg_id_fk'], $cdata['com_id']);
564
565
                        if (2 == $frC[0] || 1 == $USC['comments']) {
566
                            $xoopsTpl->append('comm', $wc);
567
                        }
568
                    }
569
                }
570
            }
571
        }
572
    }
573
}
574