Passed
Pull Request — master (#70)
by Pierre-Henry
03:15
created

Tree   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 84
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setPrefix() 0 4 1
A setPostArray() 0 3 1
A getPostTree() 0 29 4
A getAllPostArray() 0 3 1
1
<?php namespace XoopsModules\Newbb;
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 39 and the first side effect is on line 34.

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

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

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

Loading history...
2
3
//
4
// ------------------------------------------------------------------------ //
5
// XOOPS - PHP Content Management System                      //
6
// Copyright (c) 2000-2016 XOOPS.org                           //
7
// <https://xoops.org/>                             //
8
// ------------------------------------------------------------------------ //
9
// This program is free software; you can redistribute it and/or modify     //
10
// it under the terms of the GNU General Public License as published by     //
11
// the Free Software Foundation; either version 2 of the License, or        //
12
// (at your option) any later version.                                      //
13
// //
14
// You may not change or alter any portion of this comment or credits       //
15
// of supporting developers from this source code or any supporting         //
16
// source code which is considered copyrighted (c) material of the          //
17
// original comment or credit authors.                                      //
18
// //
19
// This program is distributed in the hope that it will be useful,          //
20
// but WITHOUT ANY WARRANTY; without even the implied warranty of           //
21
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
22
// GNU General Public License for more details.                             //
23
// //
24
// You should have received a copy of the GNU General Public License        //
25
// along with this program; if not, write to the Free Software              //
26
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
27
// ------------------------------------------------------------------------ //
28
// Author: phppp (D.J., [email protected])                                  //
29
//  URL: https://xoops.org                                                    //
30
// Project: Article Project                                                 //
31
// ------------------------------------------------------------------------ //
32
33
// defined('XOOPS_ROOT_PATH') || die('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...
34
require_once $GLOBALS['xoops']->path('class/xoopstree.php');
35
36
/**
37
 * Class Newbbtree
38
 */
39
class Tree extends \XoopsTree
0 ignored issues
show
Bug introduced by
The type XoopsTree was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
40
{
41
    /** @var string */
42
    private $prefix = '&nbsp;&nbsp;';
43
44
    /** @var string */
45
    private $increment = '&nbsp;&nbsp;';
46
47
    /** @var array */
48
    private $postArray = [];
49
50
    /**
51
     * @param string $table_name
52
     * @param string $id_name
53
     * @param string $pid_name
54
     */
55
    public function __construct($table_name, $id_name = 'post_id', $pid_name = 'pid')
56
    {
57
        parent::__construct($table_name, $id_name, $pid_name);
58
    }
59
60
    /**
61
     * @param string $val
62
     */
63
    public function setPrefix($val = '')
64
    {
65
        $this->prefix    = $val;
66
        $this->increment = $val;
67
    }
68
69
    /**
70
     * @param        $sel_id
71
     * @param string $order
72
     */
73
    public function getAllPostArray($sel_id, $order = '')
74
    {
75
        $this->postArray = $this->getAllChild($sel_id, $order);
76
    }
77
78
    /**
79
     * @param $postArray
80
     */
81
    public function setPostArray($postArray)
82
    {
83
        $this->postArray = $postArray;
84
    }
85
86
    // returns an array of first child objects for a given id($sel_id)
87
88
    /**
89
     * @param         $postTree_array
90
     * @param  int    $pid
91
     * @param  string $prefix
92
     * @return bool
93
     */
94
    public function getPostTree(&$postTree_array, $pid = 0, $prefix = '&nbsp;&nbsp;')
95
    {
96
        if (!is_array($postTree_array)) {
97
            $postTree_array = [];
98
        }
99
100
        $newPostArray = [];
101
        $prefix       .= $this->increment;
102
        foreach ($this->postArray as $post) {
103
            if ($post->getVar('pid') == $pid) {
104
                $postTree_array[] = [
105
                    'prefix'      => $prefix,
106
                    'icon'        => $post->getVar('icon'),
107
                    'post_time'   => $post->getVar('post_time'),
108
                    'post_id'     => $post->getVar('post_id'),
109
                    'forum_id'    => $post->getVar('forum_id'),
110
                    'subject'     => $post->getVar('subject'),
111
                    'poster_name' => $post->getVar('poster_name'),
112
                    'uid'         => $post->getVar('uid')
113
                ];
114
                $this->getPostTree($postTree_array, $post->getVar('post_id'), $prefix);
115
            } else {
116
                $newPostArray[] = $post;
117
            }
118
        }
119
        $this->postArray = $newPostArray;
120
        unset($newPostArray);
121
122
        return true;
123
    }
124
}
125