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

ForumHandler::display()   F

Complexity

Conditions 20
Paths 4212

Size

Total Lines 119
Code Lines 78

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 20
eloc 78
nc 4212
nop 3
dl 0
loc 119
rs 2
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;
2
3
/**
4
 * Newbb module
5
 *
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 *
13
 * @copyright       XOOPS Project (https://xoops.org)
14
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
15
 * @package         newbb
16
 * @since           4.0
17
 * @author          Taiwen Jiang <[email protected]>
18
 */
19
20
use XoopsModules\Newbb;
21
22
// 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...
23
24
/**
25
 * Class ForumHandler
26
 */
27
class ForumHandler extends \XoopsPersistableObjectHandler
28
{
29
    /**
30
     * @param null|\XoopsDatabase $db
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $db a bit more specific; maybe use \XoopsDatabase.
Loading history...
31
     */
32
    public function __construct(\XoopsDatabase $db)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $db. 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...
33
    {
34
        parent::__construct($db, 'newbb_forums', Forum::class, 'forum_id', 'forum_name');
35
    }
36
37
    /**
38
     * @param \XoopsObject $object
39
     * @param  bool        $force
40
     * @return bool
41
     * @internal param \XoopsObject $forum
42
     */
43
44 View Code Duplication
    public function insert(\XoopsObject $object, $force = true) //insert($forum)
0 ignored issues
show
Coding Style introduced by
function insert() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

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...
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...
45
    {
46
        $forum = $object;
47
        if (!parent::insert($forum, true)) {
48
            return false;
49
        }
50
51
        if ($forum->isNew()) {
52
            $this->applyPermissionTemplate($forum);
53
        }
54
55
        return $forum->getVar('forum_id');
56
    }
57
58
    /**
59
     * @param \XoopsObject $forum
60
     * @param  bool        $force
61
     * @return bool
62
     */
63
    public function delete(\XoopsObject $forum, $force = false) //delete(&$forum)
0 ignored issues
show
Coding Style introduced by
function delete() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

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...
64
    {
65
        global $xoopsModule;
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...
66
        // RMV-NOTIFY
67
        xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'forum', $forum->getVar('forum_id'));
68
        // Get list of all topics in forum, to delete them too
69
        /** @var Newbb\TopicHandler $topicHandler */
70
        $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic');
71
        $topicHandler->deleteAll(new \Criteria('forum_id', $forum->getVar('forum_id')), true, true);
72
        $this->updateAll('parent_forum', $forum->getVar('parent_forum'), new \Criteria('parent_forum', $forum->getVar('forum_id')));
73
        $this->deletePermission($forum);
74
75
        return parent::delete($forum);
76
    }
77
78
    /**
79
     * @param  string $perm
80
     * @return mixed
81
     */
82
    public function getIdsByPermission($perm = 'access')
83
    {
84
        /** var Newbb\PermissionHandler $permHandler */
85
        $permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
86
        return $permHandler->getForums($perm);
87
    }
88
89
    /**
90
     * @param  int    $cat
91
     * @param  string $permission
92
     * @param  null   $tags
93
     * @param  bool   $asObject
94
     * @return array
95
     */
96
    public function &getByPermission($cat = 0, $permission = 'access', $tags = null, $asObject = true)
97
    {
98
        $_cachedForums = [];
0 ignored issues
show
Coding Style introduced by
$_cachedForums 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...
99
        if (!$valid_ids = $this->getIdsByPermission($permission)) {
0 ignored issues
show
Coding Style introduced by
$valid_ids 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...
100
            return $_cachedForums;
0 ignored issues
show
Coding Style introduced by
$_cachedForums 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...
101
        }
102
103
        $criteria = new \CriteriaCompo(new \Criteria('forum_id', '(' . implode(', ', $valid_ids) . ')', 'IN'));
0 ignored issues
show
Coding Style introduced by
$valid_ids 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...
104
        if (is_numeric($cat) && $cat > 0) {
105
            $criteria->add(new \Criteria('cat_id', (int)$cat));
106
        } elseif (is_array($cat) && count($cat) > 0) {
107
            $criteria->add(new \Criteria('cat_id', '(' . implode(', ', $cat) . ')', 'IN'));
108
        }
109
        $criteria->setSort('forum_order');
110
        $criteria->setOrder('ASC');
111
        $_cachedForums = $this->getAll($criteria, $tags, $asObject);
0 ignored issues
show
Coding Style introduced by
$_cachedForums 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...
112
113
        return $_cachedForums;
0 ignored issues
show
Coding Style introduced by
$_cachedForums 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...
114
    }
115
116
    /**
117
     * @param  int    $categoryid
118
     * @param  string $permission
119
     * @param  bool   $asObject
120
     * @param  null   $tags
121
     * @return array
122
     */
123
    public function &getForumsByCategory($categoryid = 0, $permission = '', $asObject = true, $tags = null)
124
    {
125
        $forums = $this->getByPermission($categoryid, $permission, $tags);
126
        if ($asObject) {
127
            return $forums;
128
        }
129
130
        $forums_array = [];
0 ignored issues
show
Coding Style introduced by
$forums_array 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...
131
        $array_cat    = [];
0 ignored issues
show
Coding Style introduced by
$array_cat 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...
Unused Code introduced by
$array_cat 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...
132
        $array_forum  = [];
0 ignored issues
show
Coding Style introduced by
$array_forum 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...
133
        if (!is_array($forums)) {
134
            return [];
135
        }
136
        foreach (array_keys($forums) as $forumid) {
137
            $forum                                                  = $forums[$forumid];
138
            $forums_array[$forum->getVar('parent_forum')][$forumid] = [
0 ignored issues
show
Coding Style introduced by
$forums_array 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...
139
                'cid'   => $forum->getVar('cat_id'),
140
                'title' => $forum->getVar('forum_name')
141
            ];
142
        }
143
        if (!isset($forums_array[0])) {
0 ignored issues
show
Coding Style introduced by
$forums_array 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...
144
            $ret = [];
145
146
            return $ret;
147
        }
148
        foreach ($forums_array[0] as $key => $forum) {
0 ignored issues
show
Coding Style introduced by
$forums_array 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...
149
            if (isset($forums_array[$key])) {
0 ignored issues
show
Coding Style introduced by
$forums_array 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...
150
                $forum['sub'] = $forums_array[$key];
0 ignored issues
show
Coding Style introduced by
$forums_array 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...
151
            }
152
            $array_forum[$forum['cid']][$key] = $forum;
0 ignored issues
show
Coding Style introduced by
$array_forum 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...
153
        }
154
        ksort($array_forum);
0 ignored issues
show
Coding Style introduced by
$array_forum 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...
155
        unset($forums, $forums_array);
0 ignored issues
show
Coding Style introduced by
$forums_array 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...
156
157
        return $array_forum;
0 ignored issues
show
Coding Style introduced by
$array_forum 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...
158
    }
159
160
    /**
161
     * @param        $forum
162
     * @param  null  $criteria
163
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<array|integer>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
164
     */
165
    public function getAllTopics(&$forum, $criteria = null)
0 ignored issues
show
Coding Style introduced by
getAllTopics 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...
166
    {
167
        global $myts, $viewAllForums;
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...
168
        $startdate = '';
169
170
        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.render.php');
171
        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.session.php');
172
        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.time.php');
173
        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.read.php');
174
        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.topic.php');
175
176
        $criteria_vars = ['startdate', 'start', 'sort', 'order', 'type', 'status', 'excerpt'];
0 ignored issues
show
Coding Style introduced by
$criteria_vars 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...
177
        foreach ($criteria_vars as $var) {
0 ignored issues
show
Coding Style introduced by
$criteria_vars 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...
178
            ${$var} = $criteria[$var];
179
        }
180
181
        $topic_lastread = newbbGetCookie('LT', true);
0 ignored issues
show
Coding Style introduced by
$topic_lastread 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...
Unused Code introduced by
$topic_lastread 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...
182
        $criteria_forum = '';
0 ignored issues
show
Coding Style introduced by
$criteria_forum 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...
183
        if (is_object($forum)) {
184
            $criteria_forum = ' AND t.forum_id = ' . $forum->getVar('forum_id');
0 ignored issues
show
Coding Style introduced by
$criteria_forum 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...
185
            $hot_threshold  = $forum->getVar('hot_threshold');
0 ignored issues
show
Coding Style introduced by
$hot_threshold 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...
186 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
187
            $hot_threshold = 10;
0 ignored issues
show
Coding Style introduced by
$hot_threshold 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...
188
            if (is_array($forum) && count($forum) > 0) {
189
                $criteria_forum = ' AND t.forum_id IN (' . implode(',', array_keys($forum)) . ')';
0 ignored issues
show
Coding Style introduced by
$criteria_forum 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...
190
            } elseif (!empty($forum)) {
191
                $criteria_forum = ' AND t.forum_id =' . (int)$forum;
0 ignored issues
show
Coding Style introduced by
$criteria_forum 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
            }
193
        }
194
195
        $criteria_post    = $startdate ? ' p.post_time > ' . $startdate : ' 1 = 1 ';
0 ignored issues
show
Coding Style introduced by
$criteria_post 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
        $criteria_topic   = empty($type) ? '' : " AND t.type_id={$type}";
0 ignored issues
show
Coding Style introduced by
$criteria_topic 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...
Bug introduced by
The variable $type seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
197
        $criteria_extra   = '';
0 ignored issues
show
Coding Style introduced by
$criteria_extra 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...
198
        $criteria_approve = ' AND t.approved = 1';
0 ignored issues
show
Coding Style introduced by
$criteria_approve 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
        $post_on          = ' p.post_id = t.topic_last_post_id';
0 ignored issues
show
Coding Style introduced by
$post_on 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...
Unused Code introduced by
$post_on 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...
200
        $leftjoin         = ' LEFT JOIN ' . $this->db->prefix('newbb_posts') . ' p ON p.post_id = t.topic_last_post_id';
201
        $sort_array       = [];
0 ignored issues
show
Coding Style introduced by
$sort_array 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...
202
        switch ($status) {
0 ignored issues
show
Bug introduced by
The variable $status does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
203
            case 'digest':
204
                $criteria_extra = ' AND t.topic_digest = 1';
0 ignored issues
show
Coding Style introduced by
$criteria_extra 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...
205
                break;
206
207
            case 'unreplied':
208
                $criteria_extra = ' AND t.topic_replies < 1';
0 ignored issues
show
Coding Style introduced by
$criteria_extra 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...
209
                break;
210
211 View Code Duplication
            case 'unread':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
212
                if (empty($GLOBALS['xoopsModuleConfig']['read_mode'])) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
213
                } elseif (2 == $GLOBALS['xoopsModuleConfig']['read_mode']) {
214
                    // START irmtfan use read_uid to find the unread posts when the user is logged in
215
                    $read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
0 ignored issues
show
Coding Style introduced by
$read_uid 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...
216
                    if (!empty($read_uid)) {
0 ignored issues
show
Coding Style introduced by
$read_uid 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...
217
                        $leftjoin      .= ' LEFT JOIN ' . $this->db->prefix('newbb_reads_topic') . ' r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' ';
0 ignored issues
show
Coding Style introduced by
$read_uid 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...
218
                        $criteria_post .= ' AND (r.read_id IS NULL OR r.post_id < t.topic_last_post_id)';
0 ignored issues
show
Coding Style introduced by
$criteria_post 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...
219
                    } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
220
                    }
221
                    // END irmtfan use read_uid to find the unread posts when the user is logged in
222
                } elseif (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) {
223
                    // START irmtfan fix read_mode = 1 bugs - for all users (member and anon)
224
                    if ($time_criterion = max($GLOBALS['last_visit'], $startdate)) {
0 ignored issues
show
Coding Style introduced by
$time_criterion 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
                        $criteria_post  = ' p.post_time > ' . $time_criterion; // for all users
0 ignored issues
show
Coding Style introduced by
$criteria_post 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...
226
                        $topics         = [];
227
                        $topic_lastread = newbbGetCookie('LT', true);
0 ignored issues
show
Coding Style introduced by
$topic_lastread 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...
228
                        if (count($topic_lastread) > 0) {
0 ignored issues
show
Coding Style introduced by
$topic_lastread 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...
229
                            foreach ($topic_lastread as $id => $time) {
0 ignored issues
show
Coding Style introduced by
$topic_lastread 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...
Bug introduced by
The expression $topic_lastread of type array|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
230
                                if ($time > $time_criterion) {
0 ignored issues
show
Coding Style introduced by
$time_criterion 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...
231
                                    $topics[] = $id;
232
                                }
233
                            }
234
                        }
235
                        if (count($topics) > 0) {
236
                            $criteria_extra = ' AND t.topic_id NOT IN (' . implode(',', $topics) . ')';
0 ignored issues
show
Coding Style introduced by
$criteria_extra 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...
237
                        }
238
                    }
239
                    // END irmtfan fix read_mode = 1 bugs - for all users (member and anon)
240
                }
241
                break;
242
            case 'pending':
243
                $post_on          = ' p.topic_id = t.topic_id';
0 ignored issues
show
Coding Style introduced by
$post_on 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...
Unused Code introduced by
$post_on 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...
244
                $criteria_post    .= ' AND p.pid = 0';
0 ignored issues
show
Coding Style introduced by
$criteria_post 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...
245
                $criteria_approve = ' AND t.approved = 0';
0 ignored issues
show
Coding Style introduced by
$criteria_approve 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...
246
                break;
247
248
            case 'deleted':
249
                $criteria_approve = ' AND t.approved = -1';
0 ignored issues
show
Coding Style introduced by
$criteria_approve 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...
250
                break;
251
252
            case 'all': // For viewall.php; do not display sticky topics at first
253
            case 'active': // same as "all"
254
                break;
255
256
            default:
257
                if ($startdate > 0) {
258
                    $criteria_post = ' (p.post_time > ' . $startdate . ' OR t.topic_sticky=1)';
0 ignored issues
show
Coding Style introduced by
$criteria_post 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...
259
                }
260
                $sort_array[] = 't.topic_sticky DESC';
0 ignored issues
show
Coding Style introduced by
$sort_array 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...
261
                break;
262
        }
263
264
        $select = 't.*, ' . ' p.post_time as last_post_time, p.poster_name as last_poster_name, p.icon, p.post_id, p.uid';
265
        $from   = $this->db->prefix('newbb_topics') . ' t ' . $leftjoin;
266
        $where  = $criteria_post . $criteria_topic . $criteria_forum . $criteria_extra . $criteria_approve;
0 ignored issues
show
Coding Style introduced by
$criteria_post 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...
267
268
        if ($excerpt) {
0 ignored issues
show
Bug introduced by
The variable $excerpt does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
269
            $select .= ', p.post_karma, p.require_reply, pt.post_text';
270
            $from   .= ' LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' pt ON pt.post_id = t.topic_last_post_id';
271
        }
272
        if ('u.uname' === $sort) {
0 ignored issues
show
Bug introduced by
The variable $sort seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
273
            $sort = 't.topic_poster';
274
        }
275
276
        $sort_array[] = trim($sort . ' ' . $order);
0 ignored issues
show
Coding Style introduced by
$sort_array 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...
Bug introduced by
The variable $sort 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...
Bug introduced by
The variable $order does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
277
        $sortby       = implode(', ', array_filter($sort_array));
0 ignored issues
show
Coding Style introduced by
$sort_array 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...
278
        if (empty($sortby)) {
279
            $sortby = 't.topic_last_post_id DESC';
280
        }
281
282
        $sql = 'SELECT ' . $select . ' FROM ' . $from . ' WHERE ' . $where . ' ORDER BY ' . $sortby;
283
284
        if (!$result = $this->db->query($sql, $GLOBALS['xoopsModuleConfig']['topics_per_page'], $start)) {
0 ignored issues
show
Bug introduced by
The variable $start does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
285
            redirect_header('index.php', 2, _MD_NEWBB_ERROROCCURED);
286
        }
287
288
        $sticky  = 0;
289
        $topics  = [];
290
        $posters = [];
291
        $reads   = [];
292
        $types   = [];
0 ignored issues
show
Unused Code introduced by
$types 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...
293
294
        /** @var Newbb\TypeHandler $typeHandler */
295
        $typeHandler = Newbb\Helper::getInstance()->getHandler('Type');
296
        $typen       = $typeHandler->getByForum($forum->getVar('forum_id'));
297
        while ($myrow = $this->db->fetchArray($result)) {
298
            if ($myrow['topic_sticky']) {
299
                ++$sticky;
300
            }
301
302
            // ------------------------------------------------------
303
            // topic_icon: priority: sticky -> digest -> regular
304
305
            if ($myrow['topic_haspoll']) {
306
                if ($myrow['topic_sticky']) {
307
                    $topic_icon = newbbDisplayImage('topic_sticky', _MD_NEWBB_TOPICSTICKY) . '<br>' . newbbDisplayImage('poll', _MD_NEWBB_TOPICHASPOLL);
0 ignored issues
show
Coding Style introduced by
$topic_icon 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...
308
                } else {
309
                    $topic_icon = newbbDisplayImage('poll', _MD_NEWBB_TOPICHASPOLL);
0 ignored issues
show
Coding Style introduced by
$topic_icon 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...
310
                }
311
            } elseif ($myrow['topic_sticky']) {
312
                $topic_icon = newbbDisplayImage('topic_sticky', _MD_NEWBB_TOPICSTICKY);
0 ignored issues
show
Coding Style introduced by
$topic_icon 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...
313
            } elseif (!empty($myrow['icon'])) {
314
                $topic_icon = '<img src="' . XOOPS_URL . '/images/subject/' . htmlspecialchars($myrow['icon']) . '" alt="" />';
0 ignored issues
show
Coding Style introduced by
$topic_icon 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...
315
            } else {
316
                $topic_icon = '<img src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" />';
0 ignored issues
show
Coding Style introduced by
$topic_icon 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...
317
            }
318
319
            // ------------------------------------------------------
320
            // rating_img
321
            $rating = number_format($myrow['rating'] / 2, 0);
322
            // irmtfan - add alt key for rating
323 View Code Duplication
            if ($rating < 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
324
                $rating_img = newbbDisplayImage('blank');
0 ignored issues
show
Coding Style introduced by
$rating_img 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...
325
            } else {
326
                $rating_img = newbbDisplayImage('rate' . $rating, constant('_MD_NEWBB_RATE' . $rating));
0 ignored issues
show
Coding Style introduced by
$rating_img 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...
327
            }
328
            // ------------------------------------------------------
329
            // topic_page_jump
330
            $topic_page_jump      = '';
0 ignored issues
show
Coding Style introduced by
$topic_page_jump 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...
331
            $topic_page_jump_icon = '';
0 ignored issues
show
Coding Style introduced by
$topic_page_jump_icon 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...
Unused Code introduced by
$topic_page_jump_icon 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...
332
            $totalpages           = ceil(($myrow['topic_replies'] + 1) / $GLOBALS['xoopsModuleConfig']['posts_per_page']);
333 View Code Duplication
            if ($totalpages > 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
334
                $topic_page_jump .= '&nbsp;&nbsp;';
0 ignored issues
show
Coding Style introduced by
$topic_page_jump 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...
335
                $append          = false;
336
                for ($i = 1; $i <= $totalpages; ++$i) {
337
                    if ($i > 3 && $i < $totalpages) {
338
                        if (!$append) {
339
                            $topic_page_jump .= '...';
0 ignored issues
show
Coding Style introduced by
$topic_page_jump 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...
340
                            $append          = true;
341
                        }
342
                    } else {
343
                        $topic_page_jump .= '[<a href="' . XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'] . '&amp;start=' . (($i - 1) * $GLOBALS['xoopsModuleConfig']['posts_per_page']) . '">' . $i . '</a>]';
0 ignored issues
show
Coding Style introduced by
$topic_page_jump 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...
344
                        // irmtfan remove here and move
345
                        //$topic_page_jump_icon = "<a href='" . XOOPS_URL . "/modules/newbb/viewtopic.php?post_id=" . $myrow['post_id'] . "&amp;start=" . (($i - 1) * $GLOBALS['xoopsModuleConfig']['posts_per_page']) . "'>" . newbbDisplayImage('lastposticon',_MD_NEWBB_GOTOLASTPOST) . '</a>';
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% 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...
346
                    }
347
                }
348
            }
349
            // irmtfan - move here for both topics with and without pages
350
            $topic_page_jump_icon = "<a href='" . XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $myrow['post_id'] . "'>" . newbbDisplayImage('lastposticon', _MD_NEWBB_GOTOLASTPOST) . '</a>';
0 ignored issues
show
Coding Style introduced by
$topic_page_jump_icon 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...
351
352
            // ------------------------------------------------------
353
            // => topic array
354
            $forum_link = '';
0 ignored issues
show
Coding Style introduced by
$forum_link 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...
355
            if (!empty($viewAllForums[$myrow['forum_id']])) {
356
                $forum_link = '<a href="' . XOOPS_URL . '/modules/newbb/viewforum.php?forum=' . $myrow['forum_id'] . '">' . $viewAllForums[$myrow['forum_id']]['forum_name'] . '</a>';
0 ignored issues
show
Coding Style introduced by
$forum_link 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...
357
            }
358
359
            $topic_title = $myts->htmlSpecialChars($myrow['topic_title']);
0 ignored issues
show
Coding Style introduced by
$topic_title 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...
360
            // irmtfan remove here and move to for loop
361
            //if ($myrow['type_id'] > 0) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
362
            //$topic_title = '<span style="color:'.$typen[$myrow["type_id"]]["type_color"].'">['.$typen[$myrow["type_id"]]["type_name"].']</span> '.$topic_title.'';
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
363
            //}
364
            if ($myrow['topic_digest']) {
365
                $topic_title = "<span class='digest'>" . $topic_title . '</span>';
0 ignored issues
show
Coding Style introduced by
$topic_title 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...
366
            }
367
368
            if (0 == $excerpt) {
369
                $topic_excerpt = '';
0 ignored issues
show
Coding Style introduced by
$topic_excerpt 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...
370
            } elseif (($myrow['post_karma'] > 0 || $myrow['require_reply'] > 0) && !newbbIsAdmin($forum)) {
371
                $topic_excerpt = '';
0 ignored issues
show
Coding Style introduced by
$topic_excerpt 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...
372 View Code Duplication
            } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
373
                $topic_excerpt = xoops_substr(newbbHtml2text($myts->displayTarea($myrow['post_text'])), 0, $excerpt);
0 ignored issues
show
Coding Style introduced by
$topic_excerpt 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...
374
                $topic_excerpt = str_replace('[', '&#91;', $myts->htmlSpecialChars($topic_excerpt));
0 ignored issues
show
Coding Style introduced by
$topic_excerpt 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...
375
            }
376
            // START irmtfan move here
377
            $topics[$myrow['topic_id']] = [
378
                'topic_id'             => $myrow['topic_id'],
379
                'topic_icon'           => $topic_icon,
0 ignored issues
show
Coding Style introduced by
$topic_icon 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...
380
                'type_id'              => $myrow['type_id'],
381
                //'type_text'                 => $topic_prefix,/*irmtfan remove here and move to for loop*/
382
                'topic_title'          => $topic_title,
0 ignored issues
show
Coding Style introduced by
$topic_title 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...
383
                //'topic_link'                => XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'],
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% 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...
384
                'topic_link'           => 'viewtopic.php?topic_id=' . $myrow['topic_id'],
385
                'rating_img'           => $rating_img,
0 ignored issues
show
Coding Style introduced by
$rating_img 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...
386
                'topic_page_jump'      => $topic_page_jump,
0 ignored issues
show
Coding Style introduced by
$topic_page_jump 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...
387
                'topic_page_jump_icon' => $topic_page_jump_icon,
0 ignored issues
show
Coding Style introduced by
$topic_page_jump_icon 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...
388
                'topic_replies'        => $myrow['topic_replies'],
389
390
                'topic_digest' => $myrow['topic_digest'],
391
                //mb
392
393
                'topic_poster_uid'       => $myrow['topic_poster'],
394
                'topic_poster_name'      => $myts->htmlSpecialChars($myrow['poster_name'] ?: $GLOBALS['xoopsConfig']['anonymous']),
395
                'topic_views'            => $myrow['topic_views'],
396
                'topic_time'             => newbbFormatTimestamp($myrow['topic_time']),
397
                'topic_last_posttime'    => newbbFormatTimestamp($myrow['last_post_time']),
398
                'topic_last_poster_uid'  => $myrow['uid'],
399
                'topic_last_poster_name' => $myts->htmlSpecialChars($myrow['last_poster_name'] ?: $GLOBALS['xoopsConfig']['anonymous']),
400
                'topic_forum_link'       => $forum_link,
0 ignored issues
show
Coding Style introduced by
$forum_link 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...
401
                'topic_excerpt'          => $topic_excerpt,
0 ignored issues
show
Coding Style introduced by
$topic_excerpt 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...
402
                'stick'                  => empty($myrow['topic_sticky']),
403
                'stats'                  => [
404
                    $myrow['topic_status'],
405
                    $myrow['topic_digest'],
406
                    $myrow['topic_replies']
407
                ],
408
                /* irmtfan uncomment use ib the for loop*/
409
                //"topic_poster"              => $topic_poster,/*irmtfan remove here and move to for loop*/
410
                //"topic_last_poster"         => $topic_last_poster,/*irmtfan remove here and move to for loop*/
411
                //"topic_folder"              => newbbDisplayImage($topic_folder,$topic_folder_text),/*irmtfan remove here and move to for loop*/
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% 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...
412
            ];
413
            // END irmtfan move here
414
            /* users */
415
            $posters[$myrow['topic_poster']] = 1;
416
            $posters[$myrow['uid']]          = 1;
417
            // reads
418
            if (!empty($GLOBALS['xoopsModuleConfig']['read_mode'])) {
419
                $reads[$myrow['topic_id']] = (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) ? $myrow['last_post_time'] : $myrow['topic_last_post_id'];
420
            }
421
        }// irmtfan while end
422
        // START irmtfan move to a for loop
423
        $posters_name = newbbGetUnameFromIds(array_keys($posters), $GLOBALS['xoopsModuleConfig']['show_realname'], true);
0 ignored issues
show
Coding Style introduced by
$posters_name 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...
424
        //$topic_poster = newbbGetUnameFromId($myrow['topic_poster'], $GLOBALS['xoopsModuleConfig']['show_realname'], true);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
425
        //$topic_last_poster = newbbGetUnameFromId($myrow['uid'], $GLOBALS['xoopsModuleConfig']['show_realname'], true);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
426
        $topic_isRead = newbbIsRead('topic', $reads);
0 ignored issues
show
Coding Style introduced by
$topic_isRead 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...
427
        foreach (array_keys($topics) as $id) {
428
            $topics[$id]['topic_read'] = empty($topic_isRead[$id]) ? 0 : 1; // add topic-read/topic-new smarty variable
0 ignored issues
show
Coding Style introduced by
$topic_isRead 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...
429
            if (!empty($topics[$id]['type_id']) && isset($typen[$topics[$id]['type_id']])) {
430
                $topics[$id]['topic_title'] = getTopicTitle($topics[$id]['topic_title'], $typen[$topics[$id]['type_id']]['type_name'], $typen[$topics[$id]['type_id']]['type_color']);
431
            }
432
            //$topic_prefix =  (!empty($typen[$myrow['type_id']])) ? getTopicTitle("", $typen[$myrow['type_id']]["type_name"], $typen[$myrow['type_id']]["type_color"]) : "";
0 ignored issues
show
Unused Code Comprehensibility introduced by
82% 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...
433
            $topics[$id]['topic_poster']      = !empty($posters_name[$topics[$id]['topic_poster_uid']]) ? $posters_name[$topics[$id]['topic_poster_uid']] : $topics[$id]['topic_poster_name'];
0 ignored issues
show
Coding Style introduced by
$posters_name 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...
434
            $topics[$id]['topic_last_poster'] = !empty($posters_name[$topics[$id]['topic_last_poster_uid']]) ? $posters_name[$topics[$id]['topic_last_poster_uid']] : $topics[$id]['topic_last_poster_name'];
0 ignored issues
show
Coding Style introduced by
$posters_name 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...
435
436
            // ------------------------------------------------------
437
            // topic_folder: priority: newhot -> hot/new -> regular
438
            list($topic_status, $topic_digest, $topic_replies) = $topics[$id]['stats'];
0 ignored issues
show
Coding Style introduced by
$topic_status 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...
439
            if (1 == $topic_status) {
0 ignored issues
show
Coding Style introduced by
$topic_status 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...
440
                $topic_folder      = 'topic_locked';
0 ignored issues
show
Coding Style introduced by
$topic_folder 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...
441
                $topic_folder_text = _MD_NEWBB_TOPICLOCKED;
0 ignored issues
show
Coding Style introduced by
$topic_folder_text 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...
442
            } else {
443
                if ($topic_digest) {
0 ignored issues
show
Coding Style introduced by
$topic_digest 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...
444
                    $topic_folder      = 'topic_digest';
0 ignored issues
show
Coding Style introduced by
$topic_folder 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...
445
                    $topic_folder_text = _MD_NEWBB_TOPICDIGEST;
0 ignored issues
show
Coding Style introduced by
$topic_folder_text 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...
446
                } elseif ($topic_replies >= $hot_threshold) {
0 ignored issues
show
Coding Style introduced by
$topic_replies 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...
447
                    $topic_folder      = empty($topic_isRead[$id]) ? 'topic_hot_new' : 'topic_hot';
0 ignored issues
show
Coding Style introduced by
$topic_folder 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...
448
                    $topic_folder_text = empty($topic_isRead[$id]) ? _MD_NEWBB_MORETHAN : _MD_NEWBB_MORETHAN2;
0 ignored issues
show
Coding Style introduced by
$topic_folder_text 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...
449 View Code Duplication
                } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
450
                    $topic_folder      = empty($topic_isRead[$id]) ? 'topic_new' : 'topic';
0 ignored issues
show
Coding Style introduced by
$topic_folder 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...
451
                    $topic_folder_text = empty($topic_isRead[$id]) ? _MD_NEWBB_NEWPOSTS : _MD_NEWBB_NONEWPOSTS;
0 ignored issues
show
Coding Style introduced by
$topic_folder_text 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...
452
                }
453
            }
454
            $topics[$id]['topic_folder'] = newbbDisplayImage($topic_folder, $topic_folder_text);
0 ignored issues
show
Coding Style introduced by
$topic_folder 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...
455
            unset($topics[$id]['topic_poster_name'], $topics[$id]['topic_last_poster_name'], $topics[$id]['stats']);
456
        } // irmtfan end for loop
457
        // END irmtfan move to a for loop
458 View Code Duplication
        if (count($topics) > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
459
            $sql = ' SELECT DISTINCT topic_id FROM ' . $this->db->prefix('newbb_posts') . " WHERE attachment != ''" . ' AND topic_id IN (' . implode(',', array_keys($topics)) . ')';
460
            if ($result = $this->db->query($sql)) {
461
                while (list($topic_id) = $this->db->fetchRow($result)) {
0 ignored issues
show
Coding Style introduced by
$topic_id 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...
462
                    $topics[$topic_id]['attachment'] = '&nbsp;' . newbbDisplayImage('attachment', _MD_NEWBB_TOPICSHASATT);
0 ignored issues
show
Coding Style introduced by
$topic_id 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...
463
                }
464
            }
465
        }
466
467
        return [$topics, $sticky];
468
    }
469
470
    /**
471
     * @param $forum
472
     * @param $startdate
473
     * @param $type
474
     * @return null|int
475
     */
476
    public function getTopicCount(&$forum, $startdate, $type)
0 ignored issues
show
Coding Style introduced by
getTopicCount 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...
477
    {
478
        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.session.php');
479
480
        $criteria_extra   = '';
0 ignored issues
show
Coding Style introduced by
$criteria_extra 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...
481
        $criteria_approve = ' AND t.approved = 1'; // any others?
0 ignored issues
show
Coding Style introduced by
$criteria_approve 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...
482
        $leftjoin         = ' LEFT JOIN ' . $this->db->prefix('newbb_posts') . ' p ON p.post_id = t.topic_last_post_id';
483
        $criteria_post    = ' p.post_time > ' . $startdate;
0 ignored issues
show
Coding Style introduced by
$criteria_post 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...
484
        switch ($type) {
485
            case 'digest':
486
                $criteria_extra = ' AND topic_digest = 1';
0 ignored issues
show
Coding Style introduced by
$criteria_extra 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...
487
                break;
488
            case 'unreplied':
489
                $criteria_extra = ' AND topic_replies < 1';
0 ignored issues
show
Coding Style introduced by
$criteria_extra 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...
490
                break;
491 View Code Duplication
            case 'unread':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
492
                if (empty($GLOBALS['xoopsModuleConfig']['read_mode'])) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
493
                } elseif (2 == $GLOBALS['xoopsModuleConfig']['read_mode']) {
494
                    // START irmtfan use read_uid to find the unread posts when the user is logged in
495
496
                    $read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
0 ignored issues
show
Coding Style introduced by
$read_uid 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...
497
                    if (!empty($read_uid)) {
0 ignored issues
show
Coding Style introduced by
$read_uid 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...
498
                        $leftjoin      .= ' LEFT JOIN ' . $this->db->prefix('newbb_reads_topic') . ' r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' ';
0 ignored issues
show
Coding Style introduced by
$read_uid 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...
499
                        $criteria_post .= ' AND (r.read_id IS NULL OR r.post_id < t.topic_last_post_id)';
0 ignored issues
show
Coding Style introduced by
$criteria_post 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...
500
                    } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
501
                    }
502
                    // END irmtfan use read_uid to find the unread posts when the user is logged in
503
                } elseif (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) {
504
                    // START irmtfan fix read_mode = 1 bugs - for all users (member and anon)
505
                    if ($time_criterion = max($GLOBALS['last_visit'], $startdate)) {
0 ignored issues
show
Coding Style introduced by
$time_criterion 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...
506
                        $criteria_post  = ' p.post_time > ' . $time_criterion; // for all users
0 ignored issues
show
Coding Style introduced by
$criteria_post 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...
507
                        $topics         = [];
508
                        $topic_lastread = newbbGetCookie('LT', true);
0 ignored issues
show
Coding Style introduced by
$topic_lastread 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...
509
                        if (count($topic_lastread) > 0) {
0 ignored issues
show
Coding Style introduced by
$topic_lastread 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...
510
                            foreach ($topic_lastread as $id => $time) {
0 ignored issues
show
Coding Style introduced by
$topic_lastread 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...
Bug introduced by
The expression $topic_lastread of type array|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
511
                                if ($time > $time_criterion) {
0 ignored issues
show
Coding Style introduced by
$time_criterion 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...
512
                                    $topics[] = $id;
513
                                }
514
                            }
515
                        }
516
                        if (count($topics) > 0) {
517
                            $criteria_extra = ' AND t.topic_id NOT IN (' . implode(',', $topics) . ')';
0 ignored issues
show
Coding Style introduced by
$criteria_extra 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...
518
                        }
519
                    }
520
                    // END irmtfan fix read_mode = 1 bugs - for all users (member and anon)
521
                }
522
                break;
523
            case 'pending':
524
                $criteria_approve = ' AND t.approved = 0';
0 ignored issues
show
Coding Style introduced by
$criteria_approve 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...
525
                break;
526
            case 'deleted':
527
                $criteria_approve = ' AND t.approved = -1';
0 ignored issues
show
Coding Style introduced by
$criteria_approve 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...
528
                break;
529
            case 'all':
530
                break;
531
            default:
532
                $criteria_post = ' (p.post_time > ' . $startdate . ' OR t.topic_sticky=1)';
0 ignored issues
show
Coding Style introduced by
$criteria_post 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...
533
                break;
534
        }
535
        $criteria_forum = '';
0 ignored issues
show
Coding Style introduced by
$criteria_forum 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...
536
        if (is_object($forum)) {
537
            $criteria_forum = ' AND t.forum_id = ' . $forum->getVar('forum_id');
0 ignored issues
show
Coding Style introduced by
$criteria_forum 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...
538 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
539
            if (is_array($forum) && count($forum) > 0) {
540
                $criteria_forum = ' AND t.forum_id IN (' . implode(',', array_keys($forum)) . ')';
0 ignored issues
show
Coding Style introduced by
$criteria_forum 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...
541
            } elseif (!empty($forum)) {
542
                $criteria_forum = ' AND t.forum_id =' . (int)$forum;
0 ignored issues
show
Coding Style introduced by
$criteria_forum 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...
543
            }
544
        }
545
546
        $sql = 'SELECT COUNT(*) AS count FROM ' . $this->db->prefix('newbb_topics') . ' t ' . $leftjoin;
547
        $sql .= ' WHERE ' . $criteria_post . $criteria_forum . $criteria_extra . $criteria_approve;
0 ignored issues
show
Coding Style introduced by
$criteria_post 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...
548
        if (!$result = $this->db->query($sql)) {
549
            //xoops_error($this->db->error().'<br>'.$sql);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
550
            return null;
551
        }
552
        $myrow = $this->db->fetchArray($result);
553
        $count = $myrow['count'];
554
555
        return $count;
556
    }
557
558
    // get permission
559
560
    /**
561
     * @param         $forum
562
     * @param  string $type
563
     * @param  bool   $checkCategory
564
     * @return bool
565
     */
566
    public function getPermission($forum, $type = 'access', $checkCategory = true)
0 ignored issues
show
Coding Style introduced by
function getPermission() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

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...
567
    {
568
        global $xoopsModule;
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...
569
        static $_cachedPerms;
570
571
        if ('all' === $type) {
572
            return true;
573
        }
574
575
        include_once __DIR__ . '/../include/functions.user.php';
576
        if (newbbIsAdmin($forum)) {
577
            return true;
578
        }
579
        //if ($GLOBALS["xoopsUserIsAdmin"] && $xoopsModule->getVar("dirname") === "newbb") {
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
580
        //return true;
581
        //}
582
583
        if (!is_object($forum)) {
584
            $forum = $this->get($forum);
585
        }
586
587
        if (!empty($checkCategory)) {
588
            /** @var Newbb\CategoryHandler $categoryHandler */
589
            $categoryHandler = Newbb\Helper::getInstance()->getHandler('Category');
590
            $categoryPerm    = $categoryHandler->getPermission($forum->getVar('cat_id'));
591
            if (!$categoryPerm) {
592
                return false;
593
            }
594
        }
595
596
        $type = strtolower($type);
597
        // START irmtfan commented and removed
598
        //if ('moderate' === $type) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
599
        //require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.user.php');
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
600
        //$permission = newbbIsModerator($forum);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
601
        //} else {
602
        $forum_id = $forum->getVar('forum_id');
0 ignored issues
show
Coding Style introduced by
$forum_id 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...
603
        /** var Newbb\PermissionHandler $permHandler */
604
        $permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
605
        $permission  = $permHandler->getPermission('forum', $type, $forum_id);
0 ignored issues
show
Coding Style introduced by
$forum_id 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...
606
        //}
607
        // END irmtfan commented and removed
608
        return $permission;
609
    }
610
611
    /**
612
     * @param $forum
613
     * @return mixed
614
     */
615
    public function deletePermission(&$forum)
616
    {
617
        /** var Newbb\PermissionHandler $permHandler */
618
        $permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
619
620
        return $permHandler->deleteByForum($forum->getVar('forum_id'));
621
    }
622
623
    /**
624
     * @param $forum
625
     * @return mixed
626
     */
627
    public function applyPermissionTemplate(&$forum)
628
    {
629
        /** var Newbb\PermissionHandler $permHandler */
630
        $permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
631
632
        return $permHandler->applyTemplate($forum->getVar('forum_id'));
633
    }
634
635
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
51% 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...
636
    function isForum($forum)
637
    {
638
        $count = false;
639
        $sql = 'SELECT COUNT(*) as count FROM ' . $this->db->prefix("newbb_forums");
640
        $sql .= ' WHERE forum_id=' . $forum ;
641
        if ($result = $this->db->query($sql)) {
642
            $myrow = $this->db->fetchArray($result);
643
            $count = $myrow['count'];
644
        }
645
646
        return $count;
647
    }
648
    */
649
650
    /**
651
     * clean orphan forums from database
652
     * @param  string $table_link
653
     * @param  string $field_link
654
     * @param  string $field_object
655
     * @param  array  $forum_ids forum IDs
656
     * @return bool   true on success
657
     */
658
    // START irmtfan rewrite forum cleanOrphan function. add parent_forum and cat_id orphan check
659
    //    public function cleanOrphan(array $forum_ids = array())
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% 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...
660
    public function cleanOrphan($table_link = '', $field_link = '', $field_object = '', $forum_ids = [])
0 ignored issues
show
Coding Style introduced by
function cleanOrphan() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

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
$table_link 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...
661
    {
662
        // check parent_forum orphan forums
663
        if (empty($forum_ids)) {
0 ignored issues
show
Coding Style introduced by
$forum_ids 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...
664
            $forum_ids = $this->getIds();
0 ignored issues
show
Coding Style introduced by
$forum_ids 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...
665
        }
666
        if (empty($forum_ids)) {
0 ignored issues
show
Coding Style introduced by
$forum_ids 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...
667
            return false;
668
        }
669
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
670
            $sql =    "    UPDATE ".$GLOBALS['xoopsDB']->prefix("newbb_forums").
671
                    "    SET parent_forum = 0".
672
                    "    WHERE (parent_forum NOT IN ( ".$forum_ids."))".
673
                    "        OR parent_forum = forum_id";
674
        */
675
        $criteria = new \CriteriaCompo();
676
        $criteria->add(new \Criteria('parent_forum', '(' . implode(', ', $forum_ids) . ')', 'NOT IN'), 'AND');
0 ignored issues
show
Coding Style introduced by
$forum_ids 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...
677
        $criteria->add(new \Criteria('parent_forum', '`forum_id`', '='), 'OR');
678
        $b1 = $this->updateAll('parent_forum', 0, $criteria, true);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $b1. 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...
679
        // check cat_id orphan forums
680
        $categoryHandler = Newbb\Helper::getInstance()->getHandler('Category');
681
        $cat_ids         = $categoryHandler->getIds();
0 ignored issues
show
Coding Style introduced by
$cat_ids 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...
682
        if (empty($cat_ids)) {
0 ignored issues
show
Coding Style introduced by
$cat_ids 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...
683
            return false;
684
        }
685
        $criteria = new \CriteriaCompo();
686
        $criteria->add(new \Criteria('cat_id', '(' . implode(', ', $cat_ids) . ')', 'NOT IN'), 'AND');
0 ignored issues
show
Coding Style introduced by
$cat_ids 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...
687
        $b2 = $this->updateAll('cat_id', $cat_ids[0], $criteria, true);
0 ignored issues
show
Coding Style introduced by
$cat_ids 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 $b2. 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...
688
689
        return ($b1 && $b2);
690
    }
691
    // END irmtfan rewrite forum cleanOrphan function. add parent_forum and cat_id orphan check
692
693
    /**
694
     * forum data synchronization
695
     *
696
     * @param  mixed $object null for all forums; integer for forum_id; object for forum object
697
     * @return bool
698
     * @internal param int $mode 1 for stats only; 2 for forum index data only; 0 for both
699
     *
700
     */
701
    public function synchronization($object = null)
0 ignored issues
show
Coding Style introduced by
function synchronization() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

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...
702
    {
703
        if (empty($object)) {
704
            $forums = $this->getIds();
705
            $this->cleanOrphan('', '', '', $forums); // irmtfan - move cleanOrphan to synchronization function
706
            foreach ($forums as $id) {
707
                $this->synchronization($id);
708
            }
709
710
            return true;
711
        }
712
713
        if (!is_object($object)) {
714
            $object = $this->get((int)$object);
715
        }
716
717
        if (!$object->getVar('forum_id')) {
718
            return false;
719
        }
720
        $sql = 'SELECT MAX(post_id) AS last_post, COUNT(*) AS total FROM ' . $this->db->prefix('newbb_posts') . ' AS p LEFT JOIN  ' . $this->db->prefix('newbb_topics') . ' AS t ON p.topic_id=t.topic_id WHERE p.approved=1 AND t.approved=1 AND p.forum_id = ' . $object->getVar('forum_id');
721
722
        if ($result = $this->db->query($sql)) {
723
            $last_post = 0;
0 ignored issues
show
Coding Style introduced by
$last_post 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...
724
            $posts     = 0;
725
            if ($row = $this->db->fetchArray($result)) {
726
                $last_post = (int)$row['last_post'];
0 ignored issues
show
Coding Style introduced by
$last_post 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...
727
                $posts     = (int)$row['total'];
728
            }
729
            if ($object->getVar('forum_last_post_id') !== $last_post) {
0 ignored issues
show
Coding Style introduced by
$last_post 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...
730
                $object->setVar('forum_last_post_id', $last_post);
0 ignored issues
show
Coding Style introduced by
$last_post 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...
731
            }
732
            if ($object->getVar('forum_posts') !== $posts) {
733
                $object->setVar('forum_posts', $posts);
734
            }
735
        }
736
737
        $sql = 'SELECT COUNT(*) AS total FROM ' . $this->db->prefix('newbb_topics') . ' WHERE approved=1 AND forum_id = ' . $object->getVar('forum_id');
738
        if ($result = $this->db->query($sql)) {
739
            if ($row = $this->db->fetchArray($result)) {
740
                if ($object->getVar('forum_topics') !== $row['total']) {
741
                    $object->setVar('forum_topics', $row['total']);
742
                }
743
            }
744
        }
745
        $object->setDirty();
746
747
        return $this->insert($object, true);
748
    }
749
750
    /**
751
     * @param  null $passedSubForums
752
     * @return array
753
     */
754
    public function getSubforumStats($passedSubForums = null)
0 ignored issues
show
Coding Style introduced by
getSubforumStats 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...
755
    {
756
        $stats = [];
757
758
        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.forum.php');
759
760
        $subForumTree = newbbGetSubForum();
761
        if (empty($passedSubForums)) {
762
            $sub_forums = $subForumTree;
0 ignored issues
show
Coding Style introduced by
$sub_forums 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...
763
        } else {
764
            foreach ($passedSubForums as $id) {
765
                $sub_forums[$id] = isset($subForumTree[$id]) ? $subForumTree[$id] : null;
0 ignored issues
show
Coding Style introduced by
$sub_forums 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 Comprehensibility introduced by
$sub_forums was never initialized. Although not strictly required by PHP, it is generally a good practice to add $sub_forums = 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...
766
            }
767
        }
768
769
        $forums_id = [];
0 ignored issues
show
Coding Style introduced by
$forums_id 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...
770
        foreach (array_keys($sub_forums) as $id) {
0 ignored issues
show
Coding Style introduced by
$sub_forums 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...
Bug introduced by
The variable $sub_forums 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...
771
            if (empty($sub_forums[$id])) {
0 ignored issues
show
Coding Style introduced by
$sub_forums 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...
772
                continue;
773
            }
774
            $forums_id = array_merge($forums_id, $sub_forums[$id]);
0 ignored issues
show
Coding Style introduced by
$forums_id 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...
775
        }
776
        if (!$forums_id) {
0 ignored issues
show
Coding Style introduced by
$forums_id 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...
Bug Best Practice introduced by
The expression $forums_id of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
777
            return $stats;
778
        }
779
        $sql = '    SELECT forum_posts AS posts, forum_topics AS topics, forum_id AS id' . '    FROM ' . $this->table . '    WHERE forum_id IN (' . implode(', ', $forums_id) . ')';
0 ignored issues
show
Coding Style introduced by
$forums_id 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...
780
        if (!$result = $this->db->query($sql)) {
781
            return $stats;
782
        }
783
784
        $forum_stats = [];
0 ignored issues
show
Coding Style introduced by
$forum_stats 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...
785
        while ($row = $this->db->fetchArray($result)) {
786
            $forum_stats[$row['id']] = ['topics' => $row['topics'], 'posts' => $row['posts']];
0 ignored issues
show
Coding Style introduced by
$forum_stats 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...
787
        }
788
789
        foreach (array_keys($sub_forums) as $id) {
0 ignored issues
show
Coding Style introduced by
$sub_forums 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...
790
            if (empty($sub_forums[$id])) {
0 ignored issues
show
Coding Style introduced by
$sub_forums 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...
791
                continue;
792
            }
793
            $stats[$id] = ['topics' => 0, 'posts' => 0];
794
            foreach ($sub_forums[$id] as $fid) {
0 ignored issues
show
Coding Style introduced by
$sub_forums 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...
795
                $stats[$id]['topics'] += $forum_stats[$fid]['topics'];
0 ignored issues
show
Coding Style introduced by
$forum_stats 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...
796
                $stats[$id]['posts']  += $forum_stats[$fid]['posts'];
0 ignored issues
show
Coding Style introduced by
$forum_stats 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...
797
            }
798
        }
799
800
        return $stats;
801
    }
802
803
    /**
804
     * @param        $forums
805
     * @param  int   $length_title_index
806
     * @param  int   $count_subforum
807
     * @return array
808
     */
809
    public function &display($forums, $length_title_index = 30, $count_subforum = 1)
0 ignored issues
show
Coding Style introduced by
$length_title_index 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
display 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...
810
    {
811
        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...
812
813
        $posts       = [];
814
        $postsObject = [];
0 ignored issues
show
Unused Code introduced by
$postsObject 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...
815
        foreach (array_keys($forums) as $id) {
816
            $posts[] = $forums[$id]['forum_last_post_id'];
817
        }
818
        if (!empty($posts)) {
819
            $postHandler = Newbb\Helper::getInstance()->getHandler('Post');
820
            $tags_post   = ['uid', 'topic_id', 'post_time', 'poster_name', 'icon'];
0 ignored issues
show
Coding Style introduced by
$tags_post 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...
821
            if (!empty($length_title_index)) {
0 ignored issues
show
Coding Style introduced by
$length_title_index 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...
822
                $tags_post[] = 'subject';
0 ignored issues
show
Coding Style introduced by
$tags_post 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...
823
            }
824
            $posts = $postHandler->getAll(new \Criteria('post_id', '(' . implode(', ', $posts) . ')', 'IN'), $tags_post, false);
0 ignored issues
show
Coding Style introduced by
$tags_post 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...
825
        }
826
827
        // Get topic/post stats per forum
828
        $stats_forum = [];
0 ignored issues
show
Coding Style introduced by
$stats_forum 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...
829
830
        if (!empty($count_subforum)) {
0 ignored issues
show
Coding Style introduced by
$count_subforum 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...
831
            $stats_forum = $this->getSubforumStats(array_keys($forums)); // irmtfan uncomment to count sub forum posts/topics
0 ignored issues
show
Coding Style introduced by
$stats_forum 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...
832
        }
833
834
        $users  = [];
835
        $reads  = [];
836
        $topics = [];
0 ignored issues
show
Unused Code introduced by
$topics 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...
837
838
        foreach (array_keys($forums) as $id) {
839
            $forum =& $forums[$id];
840
841
            if (!$forum['forum_last_post_id']) {
842
                continue;
843
            }
844
            if (!$post = @$posts[$forum['forum_last_post_id']]) {
845
                $forum['forum_last_post_id'] = 0;
846
                continue;
847
            }
848
849
            $users[] = $post['uid'];
850
            if ($moderators[$id] = $forum['forum_moderator']) {
851
                $users = array_merge($users, $moderators[$id]);
0 ignored issues
show
Bug introduced by
The variable $moderators 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...
852
            }
853
854
            // reads
855
            if (!empty($GLOBALS['xoopsModuleConfig']['read_mode'])) {
856
                $reads[$id] = (1 == $GLOBALS['xoopsModuleConfig']['read_mode']) ? $post['post_time'] : $post['post_id'];
857
            }
858
        }
859
860
        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.user.php');
861
        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.time.php');
862
        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.render.php');
863
        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.read.php');
864
        $forum_isread = newbbIsRead('forum', $reads);
0 ignored issues
show
Coding Style introduced by
$forum_isread 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...
865
        $users_linked = newbbGetUnameFromIds(array_unique($users), !empty($GLOBALS['xoopsModuleConfig']['show_realname']), true);
0 ignored issues
show
Coding Style introduced by
$users_linked 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...
Documentation introduced by
!empty($GLOBALS['xoopsMo...fig']['show_realname']) is of type boolean, but the function expects a integer.

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...
866
867
        $forums_array   = [];
0 ignored issues
show
Coding Style introduced by
$forums_array 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...
868
        $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...
869
870
        foreach (array_keys($forums) as $id) {
871
            $forum =& $forums[$id];
872
873
            $_forum_data                 = [];
0 ignored issues
show
Coding Style introduced by
$_forum_data 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...
874
            $_forum_data['forum_order']  = $forum['forum_order'];
0 ignored issues
show
Coding Style introduced by
$_forum_data 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...
875
            $_forum_data['forum_id']     = $id;
0 ignored issues
show
Coding Style introduced by
$_forum_data 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...
876
            $_forum_data['forum_cid']    = $forum['cat_id'];
0 ignored issues
show
Coding Style introduced by
$_forum_data 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...
877
            $_forum_data['forum_name']   = $forum['forum_name'];
0 ignored issues
show
Coding Style introduced by
$_forum_data 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...
878
            $forumDescLength             = $GLOBALS['xoopsModuleConfig']['forum_desc_length'];
879
            $_forum_data['forum_desc']   = mb_strimwidth($forum['forum_desc'], 0, $forumDescLength, '...');
0 ignored issues
show
Coding Style introduced by
$_forum_data 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...
880
            $_forum_data['forum_topics'] = $forum['forum_topics'] + @$stats_forum[$id]['topics'];
0 ignored issues
show
Coding Style introduced by
$_forum_data 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...
881
            $_forum_data['forum_posts']  = $forum['forum_posts'] + @$stats_forum[$id]['posts'];
0 ignored issues
show
Coding Style introduced by
$_forum_data 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...
882
            //$_forum_data["forum_type"]= $forum['forum_type'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
82% 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...
883
884
            $forum_moderators = [];
0 ignored issues
show
Coding Style introduced by
$forum_moderators 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...
885
            if (!empty($moderators[$id])) {
886
                foreach (@$moderators[$id] as $moderator) {
887
                    $forum_moderators[] = @$users_linked[$moderator];
0 ignored issues
show
Coding Style introduced by
$forum_moderators 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...
888
                }
889
            }
890
            $_forum_data['forum_moderators'] = implode(', ', $forum_moderators);
0 ignored issues
show
Coding Style introduced by
$_forum_data 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...
891
892
            // irmtfan change if/endif to if{} method
893
            if ($post_id = $forum['forum_last_post_id']) {
0 ignored issues
show
Coding Style introduced by
$post_id 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...
894
                $post                               =& $posts[$post_id];
0 ignored issues
show
Coding Style introduced by
$post_id 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...
895
                $_forum_data['forum_lastpost_id']   = $post_id;
0 ignored issues
show
Coding Style introduced by
$_forum_data 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...
896
                $_forum_data['forum_lastpost_time'] = newbbFormatTimestamp($post['post_time']);
0 ignored issues
show
Coding Style introduced by
$_forum_data 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...
897
                if (!empty($users_linked[$post['uid']])) {
0 ignored issues
show
Coding Style introduced by
$users_linked 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...
898
                    $_forum_data['forum_lastpost_user'] = $users_linked[$post['uid']];
0 ignored issues
show
Coding Style introduced by
$_forum_data 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...
899
                } elseif ($poster_name = $post['poster_name']) {
0 ignored issues
show
Coding Style introduced by
$poster_name 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...
900
                    $_forum_data['forum_lastpost_user'] = $poster_name;
0 ignored issues
show
Coding Style introduced by
$_forum_data 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...
901
                } else {
902
                    $_forum_data['forum_lastpost_user'] = $name_anonymous;
0 ignored issues
show
Coding Style introduced by
$_forum_data 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...
903
                }
904
                if (!empty($length_title_index)) {
0 ignored issues
show
Coding Style introduced by
$length_title_index 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...
905
                    $subject = $post['subject'];
906
                    if ($length_title_index < 255) {
0 ignored issues
show
Coding Style introduced by
$length_title_index 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...
907
                        $subject = xoops_substr($subject, 0, $length_title_index);
0 ignored issues
show
Coding Style introduced by
$length_title_index 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...
908
                    }
909
                    $_forum_data['forum_lastpost_subject'] = $subject;
0 ignored issues
show
Coding Style introduced by
$_forum_data 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...
910
                }
911
                // irmtfan - remove icon_path and use newbbDisplayImage
912
                $_forum_data['forum_lastpost_icon'] = newbbDisplayImage('lastposticon', _MD_NEWBB_GOTOLASTPOST);
0 ignored issues
show
Coding Style introduced by
$_forum_data 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...
913
                // START irmtfan change the method to add read smarty
914
                if (empty($forum_isread[$id])) {
0 ignored issues
show
Coding Style introduced by
$forum_isread 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...
915
                    $_forum_data['forum_folder'] = newbbDisplayImage('forum_new', _MD_NEWBB_NEWPOSTS);
0 ignored issues
show
Coding Style introduced by
$_forum_data 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...
916
                    $_forum_data['forum_read']   = 0; // irmtfan add forum-read/forum-new smarty variable
0 ignored issues
show
Coding Style introduced by
$_forum_data 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...
917
                } else {
918
                    $_forum_data['forum_folder'] = newbbDisplayImage('forum', _MD_NEWBB_NONEWPOSTS);
0 ignored issues
show
Coding Style introduced by
$_forum_data 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...
919
                    $_forum_data['forum_read']   = 1; // irmtfan add forum-read/forum-new smarty variable
0 ignored issues
show
Coding Style introduced by
$_forum_data 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...
920
                }
921
                // END irmtfan change the method to add read smarty
922
            }
923
            $forums_array[$forum['parent_forum']][] = $_forum_data;
0 ignored issues
show
Coding Style introduced by
$forums_array 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...
924
        }
925
926
        return $forums_array;
0 ignored issues
show
Coding Style introduced by
$forums_array 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...
927
    }
928
929
    /**
930
     * get a hierarchical tree of forums
931
     *
932
     * {@link newbbTree}
933
     *
934
     * @param  int    $cat_id     category ID
935
     * @param  int    $pid        Top forum ID
936
     * @param  string $permission permission type
937
     * @param  string $prefix     prefix for display
938
     * @param  string $tags       variables to fetch
0 ignored issues
show
Documentation introduced by
Should the type for parameter $tags not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
939
     * @return array  associative array of category IDs and sanitized titles
940
     */
941 View Code Duplication
    public function &getTree($cat_id = 0, $pid = 0, $permission = 'access', $prefix = '--', $tags = null)
0 ignored issues
show
Coding Style introduced by
$cat_id 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...
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...
942
    {
943
        $pid         = (int)$pid;
944
        $perm_string = $permission;
0 ignored issues
show
Coding Style introduced by
$perm_string 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...
945
        if (!is_array($tags) || 0 === count($tags)) {
946
            $tags = ['forum_id', 'parent_forum', 'forum_name', 'forum_order', 'cat_id'];
947
        }
948
        $forumsObject = $this->getByPermission($cat_id, $perm_string, $tags);
0 ignored issues
show
Coding Style introduced by
$cat_id 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...
949
950
        require_once __DIR__ . '/tree.php';
951
        $forums_structured = [];
0 ignored issues
show
Coding Style introduced by
$forums_structured 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...
952
        foreach (array_keys($forumsObject) as $key) {
953
            $forums_structured[$forumsObject[$key]->getVar('cat_id')][$key] = $forumsObject[$key];
0 ignored issues
show
Coding Style introduced by
$forums_structured 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...
954
        }
955
956
        foreach (array_keys($forums_structured) as $cid) {
0 ignored issues
show
Coding Style introduced by
$forums_structured 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...
957
            $tree              = new ObjectTree($forums_structured[$cid]);
0 ignored issues
show
Coding Style introduced by
$forums_structured 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...
958
            $forum_array[$cid] = $tree->makeTree($prefix, $pid, $tags);
0 ignored issues
show
Coding Style introduced by
$forum_array 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 Comprehensibility introduced by
$forum_array was never initialized. Although not strictly required by PHP, it is generally a good practice to add $forum_array = 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...
959
            unset($tree);
960
        }
961
962
        return $forum_array;
0 ignored issues
show
Coding Style introduced by
$forum_array 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...
Bug introduced by
The variable $forum_array 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...
963
    }
964
965
    /**
966
     * get a hierarchical array tree of forums
967
     *
968
     * {@link newbbTree}
969
     *
970
     * @param  int     $cat_id     category ID
971
     * @param  int     $pid        Top forum ID
972
     * @param  string  $permission permission type
973
     * @param  string  $tags       variables to fetch
0 ignored issues
show
Documentation introduced by
Should the type for parameter $tags not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
974
     * @param  integer $depth      level of subcategories
975
     * @return array   associative array of category IDs and sanitized titles
976
     */
977 View Code Duplication
    public function &getArrayTree($cat_id = 0, $pid = 0, $permission = 'access', $tags = null, $depth = 0)
0 ignored issues
show
Coding Style introduced by
$cat_id 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...
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...
978
    {
979
        $pid         = (int)$pid;
980
        $perm_string = $permission;
0 ignored issues
show
Coding Style introduced by
$perm_string 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...
981
        if (!is_array($tags) || 0 === count($tags)) {
982
            $tags = ['forum_id', 'parent_forum', 'forum_name', 'forum_order', 'cat_id'];
983
        }
984
        $forumsObject = $this->getByPermission($cat_id, $perm_string, $tags);
0 ignored issues
show
Coding Style introduced by
$cat_id 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...
985
986
        require_once __DIR__ . '/tree.php';
987
        $forums_structured = [];
0 ignored issues
show
Coding Style introduced by
$forums_structured 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...
988
        foreach (array_keys($forumsObject) as $key) {
989
            $forumObject                                             =& $forumsObject[$key];
990
            $forums_structured[$forumObject->getVar('cat_id')][$key] = $forumsObject[$key];
0 ignored issues
show
Coding Style introduced by
$forums_structured 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...
991
        }
992
        foreach (array_keys($forums_structured) as $cid) {
0 ignored issues
show
Coding Style introduced by
$forums_structured 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...
993
            $tree              = new ObjectTree($forums_structured[$cid]);
0 ignored issues
show
Coding Style introduced by
$forums_structured 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...
994
            $forum_array[$cid] = $tree->makeArrayTree($pid, $tags, $depth);
0 ignored issues
show
Coding Style introduced by
$forum_array 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 Comprehensibility introduced by
$forum_array was never initialized. Although not strictly required by PHP, it is generally a good practice to add $forum_array = 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...
995
            unset($tree);
996
        }
997
998
        return $forum_array;
0 ignored issues
show
Coding Style introduced by
$forum_array 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...
Bug introduced by
The variable $forum_array 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...
999
    }
1000
1001
    /**
1002
     * @param $object
1003
     * @return array|null
1004
     */
1005
    public function &getParents($object)
0 ignored issues
show
Coding Style introduced by
getParents 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...
1006
    {
1007
        $ret = null;
1008
        if (!$object->getVar('forum_id')) {
1009
            return $ret;
1010
        }
1011
1012
        require_once $GLOBALS['xoops']->path('modules/newbb/include/functions.forum.php');
1013
        if (!$parents = newbbGetParentForum($object->getVar('forum_id'))) {
1014
            return $ret;
1015
        }
1016
        $parents_list = $this->getList(new \Criteria('forum_id', '(' . implode(', ', $parents) . ')', 'IN'));
0 ignored issues
show
Coding Style introduced by
$parents_list 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...
1017
        foreach ($parents as $key => $id) {
1018
            $ret[] = ['forum_id' => $id, 'forum_name' => $parents_list[$id]];
0 ignored issues
show
Coding Style introduced by
$parents_list 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...
1019
        }
1020
        unset($parents, $parents_list);
0 ignored issues
show
Coding Style introduced by
$parents_list 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...
1021
1022
        return $ret;
1023
    }
1024
1025
    // START irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums
1026
1027
    /**
1028
     * function for get forum Ids by positive and negative values
1029
     *
1030
     * @param  int|text $values : positive values = forums | negative values = cats | $values=0 = all valid forums, $permission , true/false $parse_cats
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $values a bit more specific; maybe use integer.
Loading history...
1031
     * @param  string   $permission
1032
     * @param  bool     $parse_cats
1033
     * @return array|mixed $validForums
1034
     */
1035
    public function getIdsByValues($values = 0, $permission = 'access', $parse_cats = true)
0 ignored issues
show
Coding Style introduced by
$parse_cats 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...
1036
    {
1037
        // Get all valid forums with this permission
1038
        $validForums = $this->getIdsByPermission($permission);
1039
        // if no value or value=0 return all valid forums
1040
        if (empty($values)) {
1041
            return $validForums;
1042
        }
1043
        $values = is_numeric($values) ? [$values] : $values;
1044
        //parse negative values to category IDs
1045
        $forums = [];
1046
        $cats   = [];
1047
        foreach ($values as $val) {
1048
            if (0 == $val) {
1049
                // value=0 => all valid forums
1050
                return $validForums;
1051
            } elseif ($val > 0) {
1052
                $forums[] = $val;
1053
            } else {
1054
                $cats[] = abs($val);
1055
            }
1056
        }
1057
        // if dont want to parse categories OR no cats return all forums
1058
        if (empty($parse_cats) || empty($cats)) {
0 ignored issues
show
Coding Style introduced by
$parse_cats 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...
1059
            return array_intersect($validForums, $forums);
1060
        }
1061
        // Get all forums by category IDs
1062
        $forumObjs = $this->getForumsByCategory($cats, $permission, true);
1063
        $forums    = array_merge($forums, array_keys($forumObjs));
1064
1065
        return array_intersect($validForums, $forums);
1066
    }
1067
    // END irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums
1068
}
1069