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

TopicRenderer::renderTopics()   F

Complexity

Conditions 46
Paths > 20000

Size

Total Lines 264
Code Lines 143

Duplication

Lines 42
Ratio 15.91 %

Importance

Changes 0
Metric Value
cc 46
eloc 143
nc 228268090
nop 1
dl 42
loc 264
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 5.0x,  the forum module for XOOPS project
5
 *
6
 * @copyright      XOOPS Project (https://xoops.org)
7
 * @license        GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
8
 * @author         Taiwen Jiang (phppp or D.J.) <[email protected]>
9
 * @since          4.00
10
 * @package        module::newbb
11
 */
12
13
use Xmf\Request;
14
use XoopsModules\Newbb;
15
16
// 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...
17
18
/**
19
 * Topic Renderer
20
 *
21
 * @author    D.J. (phppp)
22
 * @copyright copyright &copy; Xoops Project
23
 * @package   module::newbb
24
 *
25
 */
26
class TopicRenderer
27
{
28
    /**
29
     * reference to an object handler
30
     */
31
    public $handler;
32
33
    /**
34
     * reference to moduleConfig
35
     */
36
    public $config;
37
38
    /**
39
     * Requested page
40
     */
41
    public $page = 'list.topic.php';
42
43
    /**
44
     * query variables
45
     */
46
    public $args = ['forum', 'uid', 'lastposter', 'type', 'status', 'mode', 'sort', 'order', 'start', 'since'];
47
    public $vars = [];
48
49
    /**
50
     * For multiple forums
51
     */
52
    public $is_multiple = false;
0 ignored issues
show
Coding Style introduced by
$is_multiple 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...
53
54
    /**
55
     * force to parse vars (run against static vars) irmtfan
56
     */
57
    public $force = false;
58
59
    /**
60
     * Vistitor's level: 0 - anonymous; 1 - user; 2 - moderator or admin
61
     */
62
    public $userlevel = 0;
63
64
    /**
65
     * Current user has no access to current page
66
     */
67
    public $noperm = false;
68
69
    /**
70
     *
71
     */
72
    public $query = [];
73
74
    /**
75
     * Constructor
76
     */
77
    //    public function TopicRenderer()
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
78
    public function __construct()
79
    {
80
        $this->handler = Newbb\Helper::getInstance()->getHandler('Topic');
81
    }
82
83
    /**
84
     * Access the only instance of this class
85
     * @return TopicRenderer
86
     */
87
    public static function getInstance()
88
    {
89
        static $instance;
90
        if (null === $instance) {
91
            $instance = new static();
92
        }
93
94
        return $instance;
95
    }
96
97
    public function init()
98
    {
99
        $this->noperm = false;
100
        $this->query  = [];
101
    }
102
103
    /**
104
     * @param $var
105
     * @param $val
106
     * @return array|int|string
107
     */
108
    public function setVar($var, $val)
109
    {
110
        switch ($var) {
111
            case 'forum':
112
                if (is_numeric($val)) {
113
                    $val = (int)$val;
114
                    // START irmtfan - if the forum is array
115
                } elseif (is_array($val)) {
116
                    $val = implode('|', $val);
117
                    //} elseif (!empty($val)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% 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...
118
                    //    $val = implode("|", array_map("intval", explode(", ", $val)));
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
119
                }
120
                // END irmtfan - if the forum is array
121
                break;
122
123
            case 'type':
124
            case 'mode':
125
            case 'order':
126
            case 'start':
127
            case 'since':
128
                $val = (int)$val;
129
                break;
130
131
            case 'uid': // irmtfan add multi topic poster
132
            case 'lastposter': // irmtfan add multi lastposter
133
                break;
134
135
            case 'status':
136
                // START irmtfan to accept multiple status
137
                $val = is_array($val) ? $val : [$val];
138
                $val = implode(',', $val);
139
                //$val = (in_array($val, array_keys($this->getStatus( $this->userlevel ))) ) ? $val : "all"; //irmtfan no need to check if status is empty or not
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...
140
                //if ($val === "all" && !$this->is_multiple) $val = ""; irmtfan commented because it is done in sort
141
                // END irmtfan to accept multiple status
142
                break;
143
144
            default:
145
                break;
146
        }
147
148
        return $val;
149
    }
150
151
    /**
152
     * @param array $vars
153
     */
154
    public function setVars(array $vars = [])
155
    {
156
        $this->init();
157
158
        foreach ($vars as $var => $val) {
159
            if (!in_array($var, $this->args)) {
160
                continue;
161
            }
162
            $this->vars[$var] = $this->setVar($var, $val);
163
        }
164
        $this->parseVars();
165
    }
166
167
    /**
168
     * @param null $status
169
     */
170
    public function myParseStatus($status = null)
0 ignored issues
show
Coding Style introduced by
myParseStatus 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...
171
    {
172
        switch ($status) {
173
            case 'digest':
174
                $this->query['where'][] = 't.topic_digest = 1';
175
                break;
176
177
            case 'undigest':
178
                $this->query['where'][] = 't.topic_digest = 0';
179
                break;
180
181
            case 'sticky':
182
                $this->query['where'][] = 't.topic_sticky = 1';
183
                break;
184
185
            case 'unsticky':
186
                $this->query['where'][] = 't.topic_sticky = 0';
187
                break;
188
189
            case 'lock':
190
                $this->query['where'][] = 't.topic_status = 1';
191
                break;
192
193
            case 'unlock':
194
                $this->query['where'][] = 't.topic_status = 0';
195
                break;
196
197
            case 'poll':
198
                $this->query['where'][] = 't.topic_haspoll = 1';
199
                break;
200
201
            case 'unpoll':
202
                $this->query['where'][] = 't.topic_haspoll = 0';
203
                break;
204
205
            case 'voted':
206
                $this->query['where'][] = 't.votes > 0';
207
                break;
208
209
            case 'unvoted':
210
                $this->query['where'][] = 't.votes < 1';
211
                break;
212
213
            case 'replied':
214
                $this->query['where'][] = 't.topic_replies > 0';
215
                break;
216
217
            case 'unreplied':
218
                $this->query['where'][] = 't.topic_replies < 1';
219
                break;
220
221
            case 'viewed':
222
                $this->query['where'][] = 't.topic_views > 0';
223
                break;
224
225
            case 'unviewed':
226
                $this->query['where'][] = 't.topic_views < 1';
227
                break;
228
229
            case 'read':
230
                // Skip
231
                if (empty($this->config['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...
232
                    // Use database
233 View Code Duplication
                } elseif (2 == $this->config['read_mode']) {
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...
234
                    // START irmtfan use read_uid to find the unread posts when the user is logged in
235
                    $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...
236
                    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...
237
                        $this->query['join'][]  = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_reads_topic') . ' AS 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...
238
                        $this->query['where'][] = 'r.post_id = t.topic_last_post_id';
239
                    } 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...
240
                    }
241
                    // END irmtfan change criteria to get from uid p.uid = last post submit user id
242
                    // User cookie
243
                } elseif (1 == $this->config['read_mode']) {
244
                    // START irmtfan fix read_mode = 1 bugs - for all users (member and anon)
245
                    $startdate = !empty($this->vars['since']) ? (time() - newbbGetSinceTime($this->vars['since'])) : 0;
246
                    if ($lastvisit = max($GLOBALS['last_visit'], $startdate)) {
247
                        $readmode1query = '';
248
                        if ($lastvisit > $startdate) {
249
                            $readmode1query = 'p.post_time < ' . $lastvisit;
250
                        }
251
                        $topics         = [];
252
                        $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...
253 View Code Duplication
                        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...
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...
254
                            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...
255
                                if ($time > $lastvisit) {
256
                                    $topics[] = $id;
257
                                }
258
                            }
259
                        }
260
                        if (count($topics) > 0) {
261
                            $topicquery = ' t.topic_id IN (' . implode(',', $topics) . ')';
262
                            // because it should be OR
263
                            $readmode1query = !empty($readmode1query) ? '(' . $readmode1query . ' OR ' . $topicquery . ')' : $topicquery;
264
                        }
265
                        $this->query['where'][] = $readmode1query;
266
                    }
267
                    // END irmtfan fix read_mode = 1 bugs - for all users (member and anon)
268
                }
269
                break;
270
271
            case 'unread':
272
                // Skip
273
                if (empty($this->config['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...
274
                    // Use database
275 View Code Duplication
                } elseif (2 == $this->config['read_mode']) {
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...
276
                    // START irmtfan use read_uid to find the unread posts when the user is logged in
277
                    $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...
278
                    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...
279
                        $this->query['join'][]  = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_reads_topic') . ' AS 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...
280
                        $this->query['where'][] = '(r.read_id IS NULL OR r.post_id < t.topic_last_post_id)';
281
                    } 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...
282
                    }
283
                    // END irmtfan change criteria to get from uid p.uid = last post submit user id
284
                    // User cookie
285
                } elseif (1 == $this->config['read_mode']) {
286
                    // START irmtfan fix read_mode = 1 bugs - for all users (member and anon)
287
                    $startdate = !empty($this->vars['since']) ? (time() - newbbGetSinceTime($this->vars['since'])) : 0;
288
                    if ($lastvisit = max($GLOBALS['last_visit'], $startdate)) {
289
                        if ($lastvisit > $startdate) {
290
                            $this->query['where'][] = 'p.post_time > ' . $lastvisit;
291
                        }
292
                        $topics         = [];
293
                        $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...
294 View Code Duplication
                        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...
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...
295
                            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...
296
                                if ($time > $lastvisit) {
297
                                    $topics[] = $id;
298
                                }
299
                            }
300
                        }
301
                        if (count($topics) > 0) {
302
                            $this->query['where'][] = ' t.topic_id NOT IN (' . implode(',', $topics) . ')';
303
                        }
304
                    }
305
                    // END irmtfan fix read_mode = 1 bugs - for all users (member and anon)
306
                }
307
                break;
308
309 View Code Duplication
            case 'pending':
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...
310
                if ($this->userlevel < 2) {
311
                    $this->noperm = true;
312
                } else {
313
                    $this->query['where'][] = 't.approved = 0';
314
                }
315
                break;
316
317 View Code Duplication
            case 'deleted':
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...
318
                if ($this->userlevel < 2) {
319
                    $this->noperm = true;
320
                } else {
321
                    $this->query['where'][] = 't.approved = -1';
322
                }
323
                break;
324
325
            case 'all': // For viewall.php; do not display sticky topics at first
326
            case 'active': // same as 'all'
327
                $this->query['where'][] = 't.approved = 1';
328
                break;
329
330
            default: // irmtfan do nothing
331
                break;
332
        }
333
    }
334
335
    /**
336
     * @param $var
337
     * @param $val
338
     */
339
    public function parseVar($var, $val)
0 ignored issues
show
Coding Style introduced by
parseVar 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...
340
    {
341
        switch ($var) {
342
            case 'forum':
343
                /** @var Newbb\ForumHandler $forumHandler */
344
                $forumHandler = Newbb\Helper::getInstance()->getHandler('Forum');
345
                // START irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums
346
                // Get accessible forums
347
                $accessForums = $forumHandler->getIdsByValues(array_map('intval', @explode('|', $val)));
348
                // Filter specified forums if any
349
                //if (!empty($val) && $_forums = @explode('|', $val)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
350
                //$accessForums = array_intersect($accessForums, array_map('intval', $_forums));
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
351
                //}
352
                $this->vars['forum'] = $this->setVar('forum', $accessForums);
353
                // END irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums
354
355
                if (empty($accessForums)) {
356
                    $this->noperm = true;
357
                    // irmtfan - it just return return the forum_id only when the forum_id is the first allowed forum - no need for this code implode is enough removed.
358
                    //} elseif (count($accessForums) === 1) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% 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...
359
                    //$this->query["where"][] = "t.forum_id = " . $accessForums[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...
360
                } else {
361
                    $this->query['where'][] = 't.forum_id IN ( ' . implode(', ', $accessForums) . ' )';
362
                }
363
                break;
364
365 View Code Duplication
            case 'uid': // irmtfan add multi topic poster
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...
366
                if ($val !== -1) {
367
                    $val                    = implode(',', array_map('intval', explode(',', $val)));
368
                    $this->query['where'][] = 't.topic_poster IN ( ' . $val . ' )';
369
                }
370
                break;
371 View Code Duplication
            case 'lastposter': // irmtfan add multi lastposter
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...
372
                if ($val !== -1) {
373
                    $val                    = implode(',', array_map('intval', explode(',', $val)));
374
                    $this->query['where'][] = 'p.uid IN ( ' . $val . ' )';
375
                }
376
                break;
377
378
            case 'since':
379
                if (!empty($val)) {
380
                    // START irmtfan if unread && read_mode = 1 and last_visit > startdate do not add where query | to accept multiple status
381
                    $startdate = time() - newbbGetSinceTime($val);
382
                    if (in_array('unread', explode(',', $this->vars['status'], true)) && 1 == $this->config['read_mode']
383
                        && $GLOBALS['last_visit'] > $startdate) {
384
                        break;
385
                    }
386
                    // irmtfan digest_time | to accept multiple status
387
                    if (in_array('digest', explode(',', $this->vars['status'], true))) {
388
                        $this->query['where'][] = 't.digest_time > ' . $startdate;
389
                    }
390
                    // irmtfan - should be >= instead of =
391
                    $this->query['where'][] = 'p.post_time >= ' . $startdate;
392
                    // END irmtfan if unread && read_mode = 1 and last_visit > startdate do not add where query
393
                }
394
                break;
395
396
            case 'type':
397
                if (!empty($val)) {
398
                    $this->query['where'][] = 't.type_id = ' . $val;
399
                }
400
                break;
401
402
            case 'status':
403
                // START irmtfan to accept multiple status
404
                $val = explode(',', $val);
405
                // irmtfan - add 'all' to always parse t.approved = 1
406
                if (0 === count(array_intersect($val, ['all', 'active', 'pending', 'deleted']))) {
407
                    $val[] = 'all';
408
                }
409
                foreach ($val as $key => $status) {
410
                    $this->myParseStatus($status);
411
                }
412
                // END irmtfan to accept multiple status
413
                break;
414
415
            case 'sort':
416
                if ($sort = $this->getSort($val, 'sort')) {
417
                    $this->query['sort'][] = $sort . (empty($this->vars['order']) ? ' DESC' : ' ASC');
418
                } else { // irmtfan if sort is not in the list
419
                    $this->query['sort'][] = 't.topic_last_post_id' . (empty($this->vars['order']) ? ' DESC' : ' ASC');
420
                }
421
                break;
422
423
            default:
424
                break;
425
        }
426
    }
427
428
    /**
429
     * @return bool
430
     */
431
    public function parseVars()
0 ignored issues
show
Coding Style introduced by
function parseVars() 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...
432
    {
433
        static $parsed;
434
        // irmtfan - force to parse vars (run against static vars)
435
        if (isset($parsed) && !$this->force) {
436
            return true;
437
        }
438
439
        if (!isset($this->vars['forum'])) {
440
            $this->vars['forum'] = null;
441
        }
442
        //irmtfan parse status for rendering topic correctly - if empty($_GET(status)) it will show all topics include deleted and pendings. 'all' instead of all
443
        if (!isset($this->vars['status'])) {
444
            $this->vars['status'] = 'all';
445
        }
446
        // irmtfan if sort is not set or is empty get a default sort- if empty($_GET(sort)) | if sort=null eg: /list.topic.php?sort=
447
        if (empty($this->vars['sort'])) {
448
            $this->vars['sort'] = 'lastpost';
449
        } // use lastpost instead of sticky
450
451
        foreach ($this->vars as $var => $val) {
452
            $this->parseVar($var, $val);
453
            if (empty($val)) {
454
                unset($this->vars[$var]);
455
            }
456
        }
457
        $parsed = true;
458
459
        return true;
460
    }
461
462
    /**
463
     * @param  null $header
464
     * @param  null $var
465
     * @return array|null
466
     */
467
    public function getSort($header = null, $var = null)
468
    {
469
        $headers = [
470
            'topic'           => [
471
                'title' => _MD_NEWBB_TOPICS,
472
                'sort'  => 't.topic_title'
473
            ],
474
            'forum'           => [
475
                'title' => _MD_NEWBB_FORUM,
476
                'sort'  => 't.forum_id'
477
            ],
478
            'poster'          => [
479
                'title' => _MD_NEWBB_TOPICPOSTER, /*irmtfan _MD_NEWBB_POSTER to _MD_NEWBB_TOPICPOSTER*/
480
                'sort'  => 't.topic_poster'
481
            ],
482
            'replies'         => [
483
                'title' => _MD_NEWBB_REPLIES,
484
                'sort'  => 't.topic_replies'
485
            ],
486
            'views'           => [
487
                'title' => _MD_NEWBB_VIEWS,
488
                'sort'  => 't.topic_views'
489
            ],
490
            'lastpost'        => [ // irmtfan show topic_page_jump_icon smarty
491
                                   'title' => _MD_NEWBB_LASTPOST,
492
                                   /*irmtfan _MD_NEWBB_DATE to _MD_NEWBB_LASTPOSTTIME again change to _MD_LASTPOST*/
493
                                   'sort'  => 't.topic_last_post_id'
494
            ],
495
            // START irmtfan add more sorts
496
            'lastposttime'    => [ // irmtfan same as lastpost
497
                                   'title' => _MD_NEWBB_LASTPOSTTIME,
498
                                   'sort'  => 't.topic_last_post_id'
499
            ],
500
            'lastposter'      => [ // irmtfan
501
                                   'title' => _MD_NEWBB_POSTER,
502
                                   'sort'  => 'p.uid',// poster uid
503
            ],
504
            'lastpostmsgicon' => [ // irmtfan
505
                                   'title' => _MD_NEWBB_MESSAGEICON,
506
                                   'sort'  => 'p.icon',// post message icon
507
            ],
508
            'ratings'         => [
509
                'title' => _MD_NEWBB_RATINGS,
510
                'sort'  => 't.rating', // irmtfan t.topic_rating to t.rating
511
            ],
512
            'votes'           => [
513
                'title' => _MD_NEWBB_VOTES,
514
                'sort'  => 't.votes'
515
            ],
516
            'publish'         => [
517
                'title' => _MD_NEWBB_TOPICTIME,
518
                'sort'  => 't.topic_id'
519
            ],
520
            'digest'          => [
521
                'title' => _MD_NEWBB_DIGEST,
522
                'sort'  => 't.digest_time'
523
            ],
524
            'sticky'          => [
525
                'title' => _MD_NEWBB_STICKY,
526
                'sort'  => 't.topic_sticky'
527
            ],
528
            'lock'            => [
529
                'title' => _MD_NEWBB_LOCK,
530
                'sort'  => 't.topic_status'
531
            ],
532
            'poll'            => [
533
                'title' => _MD_NEWBB_POLL_POLL,
534
                'sort'  => 't.poll_id'
535
            ]
536
        ];
537
        $types   = $this->getTypes();
538
        if (!empty($types)) {
539
            $headers['type'] = [
540
                'title' => _MD_NEWBB_TYPE,
541
                'sort'  => 't.type_id'
542
            ];
543
        }
544
        if (2 == $this->userlevel) {
545
            $headers['approve'] = [
546
                'title' => _MD_NEWBB_APPROVE,
547
                'sort'  => 't.approved'
548
            ];
549
        }
550
        // END irmtfan add more sorts
551
        if (empty($header) && empty($var)) {
552
            return $headers;
553
        }
554
        if (!empty($var) && !empty($header)) {
555
            return @$headers[$header][$var];
556
        }
557
        if (empty($var)) {
558
            return @$headers[$header];
559
        }
560
        $ret = null;
561
        foreach (array_keys($headers) as $key) {
562
            $ret[$key] = @$headers[$key][$var];
563
        }
564
565
        return $ret;
566
    }
567
568
    // START irmtfan add Display topic headers function
569
570
    /**
571
     * @param  null $header
572
     * @return array
573
     */
574
    public function getHeader($header = null)
575
    {
576
        $headersSort = $this->getSort('', 'title');
577
        // additional headers - important: those cannot be in sort anyway
578
        $headers = array_merge($headersSort, [
579
            'attachment' => _MD_NEWBB_TOPICSHASATT, // show attachment smarty
580
            'read'       => _MD_NEWBB_MARK_UNREAD . '|' . _MD_NEWBB_MARK_READ, // read/unread show topic_folder smarty
581
            'pagenav'    => _MD_NEWBB_PAGENAV_DISPLAY, // show topic_page_jump smarty - sort by topic_replies?
582
        ]);
583
584
        return $this->getFromKeys($headers, $header);
585
    }
586
587
    // END irmtfan add Display topic headers function
588
589
    /**
590
     * @param  null $type
591
     * @param  null $status
592
     * @return array
593
     */
594
    public function getStatus($type = null, $status = null)
595
    {
596
        $links       = [
597
            //""            => "", /* irmtfan remove empty array */
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...
598
            'all'       => _ALL,
599
            'digest'    => _MD_NEWBB_DIGEST,
600
            'undigest'  => _MD_NEWBB_UNDIGEST, // irmtfan add
601
            'sticky'    => _MD_NEWBB_STICKY, // irmtfan add
602
            'unsticky'  => _MD_NEWBB_UNSTICKY, // irmtfan add
603
            'lock'      => _MD_NEWBB_LOCK, // irmtfan add
604
            'unlock'    => _MD_NEWBB_UNLOCK, // irmtfan add
605
            'poll'      => _MD_NEWBB_TOPICHASPOLL, // irmtfan add
606
            'unpoll'    => _MD_NEWBB_TOPICHASNOTPOLL, // irmtfan add
607
            'voted'     => _MD_NEWBB_VOTED, // irmtfan add
608
            'unvoted'   => _MD_NEWBB_UNVOTED, // irmtfan add
609
            'viewed'    => _MD_NEWBB_VIEWED, // irmtfan add
610
            'unviewed'  => _MD_NEWBB_UNVIEWED, // irmtfan add
611
            'replied'   => _MD_NEWBB_REPLIED, // irmtfan add
612
            'unreplied' => _MD_NEWBB_UNREPLIED,
613
            'read'      => _MD_NEWBB_READ, // irmtfan add
614
            'unread'    => _MD_NEWBB_UNREAD
615
        ];
616
        $links_admin = [
0 ignored issues
show
Coding Style introduced by
$links_admin 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...
617
            'active'  => _MD_NEWBB_TYPE_ADMIN,
618
            'pending' => _MD_NEWBB_TYPE_PENDING,
619
            'deleted' => _MD_NEWBB_TYPE_DELETED
620
        ];
621
622
        // all status, for admin
623
        if ($type > 1) {
624
            $links = array_merge($links, $links_admin);// irmtfan to accept multiple status
0 ignored issues
show
Coding Style introduced by
$links_admin 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...
625
        }
626
627
        return $this->getFromKeys($links, $status); // irmtfan to accept multiple status
628
    }
629
630
    /**
631
     * @param \Smarty $xoopsTpl
632
     * @throws \RuntimeException
633
     */
634
    public function buildSelection(\Smarty $xoopsTpl)
635
    {
636
        $selection         = ['action' => $this->page];
637
        $selection['vars'] = $this->vars;
638
        include_once __DIR__ . '/../include/functions.forum.php';
639
        $forum_selected     = empty($this->vars['forum']) ? null : explode('|', @$this->vars['forum']);
0 ignored issues
show
Coding Style introduced by
$forum_selected 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...
640
        $selection['forum'] = '<select name="forum[]" multiple="multiple">';
641
        $selection['forum'] .= '<option value="0">' . _MD_NEWBB_ALL . '</option>';
642
        $selection['forum'] .= newbbForumSelectBox($forum_selected);
0 ignored issues
show
Coding Style introduced by
$forum_selected 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...
643
        $selection['forum'] .= '</select>';
644
645
        $sort_selected     = $this->vars['sort'];
0 ignored issues
show
Coding Style introduced by
$sort_selected 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...
646
        $sorts             = $this->getSort('', 'title');
647
        $selection['sort'] = "<select name='sort'>";
648
        if (!is_array($sorts)) {
649
            throw new \RuntimeException('$sorts must be an array.');
650
        }
651
        foreach ($sorts as $sort => $title) {
652
            $selection['sort'] .= "<option value='" . $sort . "' " . (($sort == $sort_selected) ? " selected='selected'" : '') . '>' . $title . '</option>';
0 ignored issues
show
Coding Style introduced by
$sort_selected 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...
653
        }
654
        $selection['sort'] .= '</select>';
655
656
        $selection['order'] = "<select name='order'>";
657
        $selection['order'] .= "<option value='0' " . (empty($this->vars['order']) ? " selected='selected'" : '') . '>' . _DESCENDING . '</option>';
658
        $selection['order'] .= "<option value='1' " . (!empty($this->vars['order']) ? " selected='selected'" : '') . '>' . _ASCENDING . '</option>';
659
        $selection['order'] .= '</select>';
660
661
        $since              = isset($this->vars['since']) ? $this->vars['since'] : $this->config['since_default'];
662
        $selection['since'] = newbbSinceSelectBox($since);
663
664
        $xoopsTpl->assign_by_ref('selection', $selection);
665
    }
666
667
    /**
668
     * @param \Smarty $xoopsTpl
669
     */
670
    public function buildSearch(\Smarty $xoopsTpl)
671
    {
672
        $search             = [];
673
        $search['forum']    = @$this->vars['forum'];
674
        $search['since']    = @$this->vars['since'];
675
        $search['searchin'] = 'both';
676
677
        $xoopsTpl->assign_by_ref('search', $search);
678
    }
679
680
    /**
681
     * @param \Smarty $xoopsTpl
682
     * @throws \RuntimeException
683
     */
684
    public function buildHeaders(\Smarty $xoopsTpl)
685
    {
686
        $args = [];
687
        foreach ($this->vars as $var => $val) {
688
            if ('sort' === $var || 'order' === $var) {
689
                continue;
690
            }
691
            $args[] = "{$var}={$val}";
692
        }
693
694
        $headers = $this->getSort('', 'title');
695
        if (!is_array($headers)) {
696
            throw new \RuntimeException('$headers must be an array.');
697
        }
698
        foreach ($headers as $header => $title) {
699
            $_args = ["sort={$header}"];
0 ignored issues
show
Coding Style introduced by
$_args 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...
700
            if (@$this->vars['sort'] == $header) {
701
                $_args[] = 'order=' . ((@$this->vars['order'] + 1) % 2);
0 ignored issues
show
Coding Style introduced by
$_args 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...
702
            }
703
            $headers_data[$header]['title'] = $title;
0 ignored issues
show
Coding Style introduced by
$headers_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...
Coding Style Comprehensibility introduced by
$headers_data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $headers_data = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
704
            $headers_data[$header]['link']  = $this->page . '?' . implode('&amp;', array_merge($args, $_args));
0 ignored issues
show
Coding Style introduced by
$headers_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...
705
        }
706
        $xoopsTpl->assign_by_ref('headers', $headers_data);
0 ignored issues
show
Coding Style introduced by
$headers_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...
Bug introduced by
The variable $headers_data does not seem to be defined for all execution paths leading up to this point.

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
707
    }
708
709
    /**
710
     * @param \Smarty $xoopsTpl
711
     */
712
    public function buildFilters(\Smarty $xoopsTpl)
713
    {
714
        $args = [];
715
        foreach ($this->vars as $var => $val) {
716
            if ('status' === $var) {
717
                continue;
718
            }
719
            $args[] = "{$var}={$val}";
720
        }
721
722
        $links = $this->getStatus($this->userlevel);
723
724
        $status = [];
725 View Code Duplication
        foreach ($links as $link => $title) {
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...
726
            $_args                  = ["status={$link}"];
0 ignored issues
show
Coding Style introduced by
$_args 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
            $status[$link]['title'] = $title;
728
            $status[$link]['link']  = $this->page . '?' . implode('&amp;', array_merge($args, $_args));
0 ignored issues
show
Coding Style introduced by
$_args 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...
729
        }
730
        $xoopsTpl->assign_by_ref('filters', $status);
731
    }
732
733
    /**
734
     * @param  null $type_id
735
     * @return mixed
736
     */
737
    public function getTypes($type_id = null)
0 ignored issues
show
Coding Style introduced by
$type_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...
738
    {
739
        static $types;
740
        if (!isset($types)) {
741
            /** @var Newbb\TypeHandler $typeHandler */
742
            $typeHandler = Newbb\Helper::getInstance()->getHandler('Type');
743
744
            $types = $typeHandler->getByForum(explode('|', @$this->vars['forum']));
745
        }
746
747
        if (empty($type_id)) {
0 ignored issues
show
Coding Style introduced by
$type_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...
748
            return $types;
749
        }
750
751
        return @$types[$type_id];
0 ignored issues
show
Coding Style introduced by
$type_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...
752
    }
753
754
    /**
755
     * @param  \Smarty $xoopsTpl
756
     * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|null?

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

Loading history...
757
     */
758
    public function buildTypes(\Smarty $xoopsTpl)
759
    {
760
        $status = '';
761
        if (!$types = $this->getTypes()) {
762
            return true;
763
        }
764
765
        $args = [];
766
        foreach ($this->vars as $var => $val) {
767
            if ('type' === $var) {
768
                continue;
769
            }
770
            $args[] = "{$var}={$val}";
771
        }
772
773 View Code Duplication
        foreach ($types as $id => $type) {
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...
774
            $_args                = ["type={$id}"];
0 ignored issues
show
Coding Style introduced by
$_args 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
            $status[$id]['title'] = $type['type_name'];
776
            $status[$id]['link']  = $this->page . '?' . implode('&amp;', array_merge($args, $_args));
0 ignored issues
show
Coding Style introduced by
$_args 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...
777
        }
778
        $xoopsTpl->assign_by_ref('types', $status);
779
    }
780
781
    /**
782
     * @param  \Smarty $xoopsTpl
783
     * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|null?

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

Loading history...
784
     */
785
    public function buildCurrent(\Smarty $xoopsTpl)
786
    {
787
        if (empty($this->vars['status']) && !$this->is_multiple) {
788
            return true;
789
        }
790
791
        $args = [];
792
        foreach ($this->vars as $var => $val) {
793
            $args[] = "{$var}={$val}";
794
        }
795
796
        $status          = [];
797
        $status['title'] = implode(',', $this->getStatus($this->userlevel, $this->vars['status'])); // irmtfan to accept multiple status
798
        //$status['link'] = $this->page.(empty($this->vars['status']) ? '' : '?status='.$this->vars['status']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% 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...
799
        $status['link'] = $this->page . (empty($args) ? '' : '?' . implode('&amp;', $args));
800
801
        $xoopsTpl->assign_by_ref('current', $status);
802
    }
803
804
    /**
805
     * @param \Smarty $xoopsTpl
806
     */
807
    public function buildPagenav(\Smarty $xoopsTpl)
0 ignored issues
show
Coding Style introduced by
buildPagenav 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...
808
    {
809
        $count_topic = $this->getCount();
0 ignored issues
show
Coding Style introduced by
$count_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...
810
        if ($count_topic > $this->config['topics_per_page']) {
0 ignored issues
show
Coding Style introduced by
$count_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...
811
            $args = [];
812
            foreach ($this->vars as $var => $val) {
813
                if ('start' === $var) {
814
                    continue;
815
                }
816
                $args[] = "{$var}={$val}";
817
            }
818
            require_once $GLOBALS['xoops']->path('class/pagenav.php');
819
            $nav = new \XoopsPageNav($count_topic, $this->config['topics_per_page'], @$this->vars['start'], 'start', implode('&amp;', $args));
0 ignored issues
show
Coding Style introduced by
$count_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...
820
            if (isset($GLOBALS['xoopsModuleConfig']['do_rewrite'])) {
821
                $nav->url = formatURL(Request::getString('SERVER_NAME', '', 'SERVER')) . ' /' . $nav->url;
822
            }
823
            if ('select' === $this->config['pagenav_display']) {
824
                $navi = $nav->renderSelect();
825
            } elseif ('image' === $this->config['pagenav_display']) {
0 ignored issues
show
Unused Code Bug introduced by
The strict comparison === seems to always evaluate to false as the types of 'image' (string) and $this->config['pagenav_display'] (integer) can never be identical. Maybe you want to use a loose comparison == instead?
Loading history...
826
                $navi = $nav->renderImageNav(4);
827
            } else {
828
                $navi = $nav->renderNav(4);
829
            }
830
            $xoopsTpl->assign('pagenav', $navi);
831
        } else {
832
            $xoopsTpl->assign('pagenav', '');
833
        }
834
    }
835
836
    /**
837
     * @return int
838
     */
839
    public function getCount()
840
    {
841
        if ($this->noperm) {
842
            return 0;
843
        }
844
845
        $selects = [];
846
        $froms   = [];
847
        $joins   = [];
848
        $wheres  = [];
849
850
        // topic fields
851
        $selects[] = 'COUNT(*)';
852
853
        $froms[]  = $this->handler->db->prefix('newbb_topics') . ' AS t ';
854
        $joins[]  = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_posts') . ' AS p ON p.post_id = t.topic_last_post_id';
855
        $wheres[] = '1 = 1';
856
857
        $sql = '    SELECT ' . implode(', ', $selects) . '     FROM ' . implode(', ', $froms) . '        ' . implode(' ', $joins) . (!empty($this->query['join']) ? '        ' . implode(' ', $this->query['join']) : '') . // irmtfan bug fix: Undefined index: join when post_excerpt = 0
858
               '     WHERE ' . implode(' AND ', $wheres) . '        AND ' . @implode(' AND ', @$this->query['where']);
859
860
        if (!$result = $this->handler->db->query($sql)) {
861
            return 0;
862
        }
863
        list($count) = $this->handler->db->fetchRow($result);
864
865
        return $count;
866
    }
867
868
    /**
869
     * @param  \Smarty $xoopsTpl
0 ignored issues
show
Documentation introduced by
Should the type for parameter $xoopsTpl not be null|\Smarty?

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...
870
     * @return array|void
871
     */
872
    public function renderTopics(\Smarty $xoopsTpl = null)
0 ignored issues
show
Coding Style introduced by
renderTopics 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...
873
    {
874
        $myts = \MyTextSanitizer::getInstance(); // irmtfan Instanciate
875
876
        $ret = [];
877
        //$this->parseVars();
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...
878
879
        if ($this->noperm) {
880
            if (is_object($xoopsTpl)) {
881
                $xoopsTpl->assign_by_ref('topics', $ret);
882
883
                return;
884
            }
885
886
            return $ret;
887
        }
888
889
        $selects = [];
890
        $froms   = [];
891
        $joins   = [];
892
        $wheres  = [];
893
894
        // topic fields
895
        $selects[] = 't.*';
896
        // post fields
897
        $selects[] = 'p.post_time as last_post_time, p.poster_name as last_poster_name, p.icon, p.post_id, p.uid';
898
899
        $froms[]  = $this->handler->db->prefix('newbb_topics') . ' AS t ';
900
        $joins[]  = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_posts') . ' AS p ON p.post_id = t.topic_last_post_id';
901
        $wheres[] = '1 = 1';
902
903
        if (!empty($this->config['post_excerpt'])) {
904
            $selects[]             = 'p.post_karma, p.require_reply, pt.post_text';
905
            $this->query['join'][] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_posts_text') . ' AS pt ON pt.post_id = t.topic_last_post_id';
906
        }
907
        //if (empty($this->query["sort"])) $this->query["sort"][] = 't.topic_last_post_id DESC'; // irmtfan commented no need
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
908
909
        $sql = '    SELECT ' . implode(', ', $selects) . '     FROM ' . implode(', ', $froms) . '        ' . implode(' ', $joins) . (!empty($this->query['join']) ? '        ' . implode(' ', $this->query['join']) : '') . // irmtfan bug fix: Undefined index join when post_excerpt = 0
910
               '     WHERE ' . implode(' AND ', $wheres) . '        AND ' . @implode(' AND ', @$this->query['where']) . '     ORDER BY ' . implode(', ', $this->query['sort']);
911
912
        if (!$result = $this->handler->db->query($sql, $this->config['topics_per_page'], @$this->vars['start'])) {
913
            if (is_object($xoopsTpl)) {
914
                $xoopsTpl->assign_by_ref('topics', $ret);
915
916
                return;
917
            }
918
919
            return $ret;
920
        }
921
922
        include_once __DIR__ . '/../include/functions.render.php';
923
        include_once __DIR__ . '/../include/functions.session.php';
924
        include_once __DIR__ . '/../include/functions.time.php';
925
        include_once __DIR__ . '/../include/functions.read.php';
926
        include_once __DIR__ . '/../include/functions.topic.php';
927
928
        $sticky    = 0;
929
        $topics    = [];
930
        $posters   = [];
931
        $reads     = [];
932
        $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...
933
        $forums    = [];
934
        $anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']);
935
936
        while ($myrow = $this->handler->db->fetchArray($result)) {
937
            if ($myrow['topic_sticky']) {
938
                ++$sticky;
939
            }
940
941
            // ------------------------------------------------------
942
            // START irmtfan remove topic_icon hardcode smarty
943
            // topic_icon: just regular topic_icon
944 View Code Duplication
            if (!empty($myrow['icon'])) {
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...
945
                $topic_icon = '<img align="middle" 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...
946
            } else {
947
                $topic_icon = '<img align="middle" 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...
948
            }
949
            // END irmtfan remove topic_icon hardcode smarty
950
951
            // ------------------------------------------------------
952
            // rating_img
953
            $rating = number_format($myrow['rating'] / 2, 0);
954
            // irmtfan - add alt key for rating
955 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...
956
                $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...
957
            } else {
958
                $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...
959
            }
960
961
            // ------------------------------------------------------
962
            // topic_page_jump
963
            $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...
964
            $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...
965
            $totalpages           = ceil(($myrow['topic_replies'] + 1) / $this->config['posts_per_page']);
966 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...
967
                $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...
968
                $append          = false;
969
                for ($i = 1; $i <= $totalpages; ++$i) {
970
                    if ($i > 3 && $i < $totalpages) {
971
                        if (!$append) {
972
                            $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...
973
                            $append          = true;
974
                        }
975
                    } else {
976
                        $topic_page_jump .= '[<a href="' . XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'] . '&amp;start=' . (($i - 1) * $this->config['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...
977
                        // irmtfan remove here and move
978
                        //$topic_page_jump_icon = "<a href='" . XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id=" . $myrow['topic_id'] . "&amp;start=" . (($i - 1) * $this->config['posts_per_page']) . "" . "'>" . newbbDisplayImage('document',_MD_NEWBB_GOTOLASTPOST) . '</a>';
0 ignored issues
show
Unused Code Comprehensibility introduced by
41% 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...
979
                    }
980
                }
981
            }
982
            // irmtfan - move here for both topics with and without pages - change topic_id to post_id
983
            $topic_page_jump_icon = "<a href='" . XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $myrow['topic_last_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...
984
985
            // ------------------------------------------------------
986
            // => topic array
987
988
            $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...
989
            // irmtfan use topic_title_excerpt for block topic title length
990
            $topic_title_excerpt = $topic_title;
0 ignored issues
show
Coding Style introduced by
$topic_title_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...
991
            if (!empty($this->config['topic_title_excerpt'])) {
992
                $topic_title_excerpt = xoops_substr($topic_title, 0, $this->config['topic_title_excerpt']);
0 ignored issues
show
Coding Style introduced by
$topic_title_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...
993
            }
994
            // irmtfan hardcode class commented
995
            //if ($myrow['topic_digest']) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% 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...
996
            //   $topic_title = "<span class='digest'>" . $topic_title . "</span>";
997
            //}
998
999
            if (empty($this->config['post_excerpt'])) {
1000
                $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...
1001
            } elseif (($myrow['post_karma'] > 0 || $myrow['require_reply'] > 0) && !newbbIsAdmin($myrow['forum_id'])) {
1002
                $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...
1003 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...
1004
                $topic_excerpt = xoops_substr(newbbHtml2text($myts->displayTarea($myrow['post_text'])), 0, $this->config['post_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...
1005
                $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...
1006
            }
1007
1008
            $topics[$myrow['topic_id']] = [
1009
                'topic_id'               => $myrow['topic_id'],
1010
                '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...
1011
                'type_id'                => $myrow['type_id'],
1012
                'topic_title_excerpt'    => $topic_title_excerpt,
0 ignored issues
show
Coding Style introduced by
$topic_title_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...
1013
                //irmtfan use topic_title_excerpt
1014
                //'topic_link'    => XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'], // . '&amp;forum=' . $myrow['forum_id'], // irmtfan comment
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% 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...
1015
                'topic_link'             => 'viewtopic.php?topic_id=' . $myrow['topic_id'],
1016
                // irmtfan remove hardcode link
1017
                '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...
1018
                'votes'                  => $myrow['votes'],
1019
                //irmtfan added
1020
                '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...
1021
                '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...
1022
                'topic_replies'          => $myrow['topic_replies'],
1023
                'topic_poster_uid'       => $myrow['topic_poster'],
1024
                'topic_poster_name'      => !empty($myrow['poster_name']) ? $myts->htmlSpecialChars($myrow['poster_name']) : $anonymous,
1025
                'topic_views'            => $myrow['topic_views'],
1026
                'topic_time'             => newbbFormatTimestamp($myrow['topic_time']),
1027
                'topic_last_post_id'     => $myrow['topic_last_post_id'],
1028
                //irmtfan added
1029
                'topic_last_posttime'    => newbbFormatTimestamp($myrow['last_post_time']),
1030
                'topic_last_poster_uid'  => $myrow['uid'],
1031
                'topic_last_poster_name' => !empty($myrow['last_poster_name']) ? $myts->htmlSpecialChars($myrow['last_poster_name']) : $anonymous,
1032
                'topic_forum'            => $myrow['forum_id'],
1033
                '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...
1034
                'sticky'                 => $myrow['topic_sticky'] ? newbbDisplayImage('topic_sticky', _MD_NEWBB_TOPICSTICKY) : '',
1035
                // irmtfan bug fixed
1036
                'lock'                   => $myrow['topic_status'] ? newbbDisplayImage('topic_locked', _MD_NEWBB_TOPICLOCK) : '',
1037
                //irmtfan added
1038
                'digest'                 => $myrow['topic_digest'] ? newbbDisplayImage('topic_digest', _MD_NEWBB_TOPICDIGEST) : '',
1039
                //irmtfan added
1040
                'poll'                   => $myrow['topic_haspoll'] ? newbbDisplayImage('poll', _MD_NEWBB_TOPICHASPOLL) : '',
1041
                //irmtfan added
1042
                'approve'                => $myrow['approved'],
1043
                //irmtfan added
1044
            ];
1045
1046
            /* users */
1047
            $posters[$myrow['topic_poster']] = 1;
1048
            $posters[$myrow['uid']]          = 1;
1049
            // reads
1050
            if (!empty($this->config['read_mode'])) {
1051
                $reads[$myrow['topic_id']] = (1 == $this->config['read_mode']) ? $myrow['last_post_time'] : $myrow['topic_last_post_id'];
1052
            }
1053
            // types
1054
            if (!empty($myrow['type_id'])) {
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...
1055
                //$types[$myrow['type_id']] = 1;
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...
1056
            }
1057
            // forums
1058
            $forums[$myrow['forum_id']] = 1;
1059
        }
1060
        $posters_name = newbbGetUnameFromIds(array_keys($posters), $this->config['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...
1061
        $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...
1062
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
1063
        $type_list = array();
1064
        if (count($types) > 0) {
1065
            $typeHandler =  Newbb\Helper::getInstance()->getHandler('Type');
1066
            $type_list = $typeHandler->getAll(new \Criteria("type_id", "(".implode(", ", array_keys($types)).")", "IN"), null, false);
1067
        }
1068
        */
1069
        $type_list = $this->getTypes();
0 ignored issues
show
Coding Style introduced by
$type_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...
1070
        /** @var Newbb\ForumHandler $forumHandler */
1071
        $forumHandler = Newbb\Helper::getInstance()->getHandler('Forum');
1072
1073
        if (count($forums) > 0) {
1074
            $forum_list = $forumHandler->getAll(new \Criteria('forum_id', '(' . implode(', ', array_keys($forums)) . ')', 'IN'), ['forum_name', 'hot_threshold'], false);
0 ignored issues
show
Coding Style introduced by
$forum_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...
1075
        } else {
1076
            $forum_list = $forumHandler->getAll();
0 ignored issues
show
Coding Style introduced by
$forum_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...
1077
        }
1078
1079
        foreach (array_keys($topics) as $id) {
1080
            $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...
1081
            $topics[$id]['topic_forum_link'] = '<a href="' . XOOPS_URL . '/modules/newbb/viewforum.php?forum=' . $topics[$id]['topic_forum'] . '">' . $forum_list[$topics[$id]['topic_forum']]['forum_name'] . '</a>';
0 ignored issues
show
Coding Style introduced by
$forum_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...
1082
1083
            //irmtfan use topic_title_excerpt -- add else
1084
            if (!empty($topics[$id]['type_id']) && isset($type_list[$topics[$id]['type_id']])) {
0 ignored issues
show
Coding Style introduced by
$type_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...
1085
                $topics[$id]['topic_title'] = getTopicTitle($topics[$id]['topic_title_excerpt'], $type_list[$topics[$id]['type_id']]['type_name'], $type_list[$topics[$id]['type_id']]['type_color']);
0 ignored issues
show
Coding Style introduced by
$type_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...
1086
            } else {
1087
                $topics[$id]['topic_title'] = $topics[$id]['topic_title_excerpt'];
1088
            }
1089
            $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...
1090
            $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...
1091
            // ------------------------------------------------------
1092
            // START irmtfan remove hardcodes from topic_folder smarty
1093
            // topic_folder: priority: newhot -> hot/new -> regular
1094
            //list($topic_status, $topic_digest, $topic_replies) = $topics[$id]["stats"]; irmtfan
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...
1095
            // START irmtfan - add topic_folder_text for alt
1096
            //if ($topics[$id]["lock"] === 1) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% 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...
1097
            //    $topic_folder = 'topic_locked';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
1098
            //    $topic_folder_text = _MD_NEWBB_TOPICLOCKED;
1099
            //} else {
1100
            //if ($topic_digest) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
1101
            //    $topic_folder = 'topic_digest';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
1102
            //    $topic_folder_text = _MD_NEWBB_TOPICDIGEST;
1103
            if ($topics[$id]['topic_replies'] >= $forum_list[$topics[$id]['topic_forum']]['hot_threshold']) {
0 ignored issues
show
Coding Style introduced by
$forum_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...
1104
                $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...
1105
                $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...
1106 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...
1107
                $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...
1108
                $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...
1109
            }
1110
            //}
1111
            // END irmtfan remove hardcodes from topic_folder smarty
1112
            $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...
1113
            // END irmtfan - add topic_folder_text for alt
1114
1115
            unset($topics[$id]['topic_poster_name'], $topics[$id]['topic_last_poster_name']);// irmtfan remove $topics[$id]["stats"] because it is not exist now
1116
        }
1117
1118 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...
1119
            $sql = ' SELECT DISTINCT topic_id FROM ' . $this->handler->db->prefix('newbb_posts') . " WHERE attachment != ''" . ' AND topic_id IN (' . implode(',', array_keys($topics)) . ')';
1120
            if ($result = $this->handler->db->query($sql)) {
1121
                while (list($topic_id) = $this->handler->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...
1122
                    $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...
1123
                }
1124
            }
1125
        }
1126
1127
        if (is_object($xoopsTpl)) {
1128
            $xoopsTpl->assign_by_ref('sticky', $sticky);
1129
            $xoopsTpl->assign_by_ref('topics', $topics);
1130
1131
            return;
1132
        }
1133
1134
        return [$topics, $sticky];
1135
    }
1136
1137
    // START irmtfan to create an array from selected keys of an array
1138
1139
    /**
1140
     * @param        $array
1141
     * @param  null  $keys
1142
     * @return array
1143
     */
1144
    public function getFromKeys($array, $keys = null)
1145
    {
1146
        if (empty($keys)) {
1147
            return $array;
1148
        } // all keys
1149
        $keyarr = is_string($keys) ? explode(',', $keys) : $keys;
1150
        $keyarr = array_intersect(array_keys($array), $keyarr); // keys should be in array
1151
        $ret    = [];
1152
        foreach ($keyarr as $key) {
1153
            $ret[$key] = $array[$key];
1154
        }
1155
1156
        return $ret;
1157
    }
1158
    // END irmtfan to create an array from selected keys of an array
1159
}
1160