Tree::getAllPostArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace XoopsModules\Newbb;
4
5
//
6
// ------------------------------------------------------------------------ //
7
// XOOPS - PHP Content Management System                      //
8
// Copyright (c) 2000-2020 XOOPS.org                           //
9
// <https://xoops.org>                             //
10
// ------------------------------------------------------------------------ //
11
// This program is free software; you can redistribute it and/or modify     //
12
// it under the terms of the GNU General Public License as published by     //
13
// the Free Software Foundation; either version 2 of the License, or        //
14
// (at your option) any later version.                                      //
15
// //
16
// You may not change or alter any portion of this comment or credits       //
17
// of supporting developers from this source code or any supporting         //
18
// source code which is considered copyrighted (c) material of the          //
19
// original comment or credit authors.                                      //
20
// //
21
// This program is distributed in the hope that it will be useful,          //
22
// but WITHOUT ANY WARRANTY; without even the implied warranty of           //
23
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
24
// GNU General Public License for more details.                             //
25
// //
26
// You should have received a copy of the GNU General Public License        //
27
// along with this program; if not, write to the Free Software              //
28
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
29
// ------------------------------------------------------------------------ //
30
// Author: phppp (D.J., [email protected])                                  //
31
//  URL: https://xoops.org                                                    //
32
// Project: Article Project                                                 //
33
// ------------------------------------------------------------------------ //
34
35
36
require_once $GLOBALS['xoops']->path('class/xoopstree.php');
37
38
/**
39
 * Class Tree
40
 */
41
class Tree extends \XoopsTree
42
{
43
    /** @var string */
44
    private $prefix = '&nbsp;&nbsp;';
45
46
    /** @var string */
47
    private $increment = '&nbsp;&nbsp;';
48
49
    /** @var array */
50
    private $postArray = [];
51
52
    /**
53
     * @param string $table_name
54
     * @param string $id_name
55
     * @param string $pid_name
56
     */
57
    public function __construct($table_name, $id_name = 'post_id', $pid_name = 'pid')
58
    {
59
        parent::__construct($table_name, $id_name, $pid_name);
60
    }
61
62
    /**
63
     * @param string $val
64
     */
65
    public function setPrefix($val = '')
66
    {
67
        $this->prefix    = $val;
68
        $this->increment = $val;
69
    }
70
71
    /**
72
     * @param        $sel_id
73
     * @param string $order
74
     */
75
    public function getAllPostArray($sel_id, $order = '')
76
    {
77
        $this->postArray = $this->getAllChild($sel_id, $order);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getAllChild($sel_id, $order) can also be of type mixed. However, the property $postArray is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
78
    }
79
80
    /**
81
     * @param $postArray
82
     */
83
    public function setPostArray($postArray)
84
    {
85
        $this->postArray = $postArray;
86
    }
87
88
    // returns an array of first child objects for a given id($sel_id)
89
90
    /**
91
     * @param         $postTree_array
92
     * @param int     $pid
93
     * @param string  $prefix
94
     * @return bool
95
     */
96
    public function getPostTree(&$postTree_array, $pid = 0, $prefix = '&nbsp;&nbsp;')
97
    {
98
        if (!\is_array($postTree_array)) {
99
            $postTree_array = [];
100
        }
101
102
        $newPostArray = [];
103
        $prefix       .= $this->increment;
104
        foreach ($this->postArray as $post) {
105
            if ($post->getVar('pid') == $pid) {
106
                $postTree_array[] = [
107
                    'prefix'      => $prefix,
108
                    'icon'        => $post->getVar('icon'),
109
                    'post_time'   => $post->getVar('post_time'),
110
                    'post_id'     => $post->getVar('post_id'),
111
                    'forum_id'    => $post->getVar('forum_id'),
112
                    'subject'     => $post->getVar('subject'),
113
                    'poster_name' => $post->getVar('poster_name'),
114
                    'uid'         => $post->getVar('uid'),
115
                ];
116
                $this->getPostTree($postTree_array, $post->getVar('post_id'), $prefix);
117
            } else {
118
                $newPostArray[] = $post;
119
            }
120
        }
121
        $this->postArray = $newPostArray;
122
        unset($newPostArray);
123
124
        return true;
125
    }
126
}
127