|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Newbb; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* You may not change or alter any portion of this comment or credits |
|
7
|
|
|
* of supporting developers from this source code or any supporting source code |
|
8
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @copyright XOOPS Project (https://xoops.org)/ |
|
17
|
|
|
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
|
18
|
|
|
* @author phppp (D.J., [email protected]) |
|
19
|
|
|
* @author XOOPS Development Team |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
use XoopsTree; |
|
23
|
|
|
|
|
24
|
|
|
require_once $GLOBALS['xoops']->path('class/xoopstree.php'); |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Class Tree |
|
28
|
|
|
*/ |
|
29
|
|
|
class Tree extends XoopsTree |
|
30
|
|
|
{ |
|
31
|
|
|
/** @var string */ |
|
32
|
|
|
private string $prefix = ' '; |
|
33
|
|
|
/** @var string */ |
|
34
|
|
|
private string $increment = ' '; |
|
35
|
|
|
/** @var array */ |
|
36
|
|
|
private array $postArray = []; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param string $table_name |
|
40
|
|
|
* @param string $id_name |
|
41
|
|
|
* @param string $pid_name |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct($table_name, $id_name = 'post_id', $pid_name = 'pid') |
|
44
|
|
|
{ |
|
45
|
|
|
parent::__construct($table_name, $id_name, $pid_name); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param string $val |
|
50
|
|
|
*/ |
|
51
|
|
|
public function setPrefix(string $val = ''): void |
|
52
|
|
|
{ |
|
53
|
|
|
$this->prefix = $val; |
|
54
|
|
|
$this->increment = $val; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param int $sel_id |
|
59
|
|
|
* @param string $order |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getAllPostArray(int $sel_id, string $order = ''): void |
|
62
|
|
|
{ |
|
63
|
|
|
$this->postArray = $this->getAllChild($sel_id, $order); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param array $postArray |
|
68
|
|
|
*/ |
|
69
|
|
|
public function setPostArray(array $postArray): void |
|
70
|
|
|
{ |
|
71
|
|
|
$this->postArray = $postArray; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
// returns an array of first child objects for a given id($sel_id) |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param mixed $postTree_array |
|
78
|
|
|
* @param int $pid |
|
79
|
|
|
* @param string $prefix |
|
80
|
|
|
* @return bool |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getPostTree(&$postTree_array, int $pid = 0, string $prefix = ' '): bool |
|
83
|
|
|
{ |
|
84
|
|
|
if (!\is_array($postTree_array)) { |
|
85
|
|
|
$postTree_array = []; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
$newPostArray = []; |
|
89
|
|
|
$prefix .= $this->increment; |
|
90
|
|
|
foreach ($this->postArray as $post) { |
|
91
|
|
|
if ($post->getVar('pid') == $pid) { |
|
92
|
|
|
$postTree_array[] = [ |
|
93
|
|
|
'prefix' => $prefix, |
|
94
|
|
|
'icon' => $post->getVar('icon'), |
|
95
|
|
|
'post_time' => $post->getVar('post_time'), |
|
96
|
|
|
'post_id' => $post->getVar('post_id'), |
|
97
|
|
|
'forum_id' => $post->getVar('forum_id'), |
|
98
|
|
|
'subject' => $post->getVar('subject'), |
|
99
|
|
|
'poster_name' => $post->getVar('poster_name'), |
|
100
|
|
|
'uid' => $post->getVar('uid'), |
|
101
|
|
|
]; |
|
102
|
|
|
$this->getPostTree($postTree_array, $post->getVar('post_id'), $prefix); |
|
103
|
|
|
} else { |
|
104
|
|
|
$newPostArray[] = $post; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
$this->postArray = $newPostArray; |
|
108
|
|
|
unset($newPostArray); |
|
109
|
|
|
|
|
110
|
|
|
return true; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
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
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. 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.