Completed
Push — master ( 4e8684...61995d )
by Michael
08:37
created

NewbbTree   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 81
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setPrefix() 0 5 1
A getAllPostArray() 0 4 1
A setPostArray() 0 4 1
B getPostTree() 0 30 4
1
<?php
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 38 and the first side effect is on line 33.

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

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

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