This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | /* |
||
3 | You may not change or alter any portion of this comment or credits |
||
4 | of supporting developers from this source code or any supporting source code |
||
5 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
6 | |||
7 | This program is distributed in the hope that it will be useful, |
||
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
10 | */ |
||
11 | |||
12 | /** |
||
13 | * XOOPS tree class |
||
14 | * |
||
15 | * @copyright XOOPS Project https://xoops.org/ |
||
16 | * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
||
17 | * @package class |
||
18 | * @since 2.0.0 |
||
19 | * @author Kazumi Ono (http://www.myweb.ne.jp/, http://jp.xoops.org/) |
||
20 | * @author Edited by John Mordo (jlm69) |
||
21 | * @version $Id$ |
||
22 | */ |
||
23 | |||
24 | defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
||
25 | |||
26 | /** |
||
27 | * A tree structures with {@link XoopsObject}s as nodes |
||
28 | * |
||
29 | * @package kernel |
||
30 | * @subpackage core |
||
31 | * @author Kazumi Ono <[email protected]> |
||
32 | */ |
||
33 | class AlumniObjectTree extends XoopsObjectTree |
||
0 ignored issues
–
show
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. ![]() |
|||
34 | { |
||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | private $_parentId; |
||
0 ignored issues
–
show
$_parentId 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. ![]() |
|||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | private $_myId; |
||
0 ignored issues
–
show
$_myId 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. ![]() |
|||
44 | |||
45 | /** |
||
46 | * @var null|string |
||
47 | */ |
||
48 | private $_rootId = null; |
||
0 ignored issues
–
show
$_rootId 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. ![]() |
|||
49 | |||
50 | /** |
||
51 | * @var array |
||
52 | */ |
||
53 | private $_tree = []; |
||
0 ignored issues
–
show
$_tree 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. ![]() |
|||
54 | |||
55 | /** |
||
56 | * @var array |
||
57 | */ |
||
58 | private $_objects; |
||
0 ignored issues
–
show
$_objects 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. ![]() |
|||
59 | |||
60 | /** |
||
61 | * Constructor |
||
62 | * |
||
63 | * @param array $objectArr Array of {@link XoopsObject}s |
||
64 | * @param string $myId field name of object ID |
||
65 | * @param string $parentId field name of parent object ID |
||
66 | * @param string $rootId field name of root object ID |
||
0 ignored issues
–
show
Should the type for parameter
$rootId not be string|null ?
This check looks for 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. ![]() |
|||
67 | */ |
||
68 | public function __construct(&$objectArr, $myId, $parentId, $rootId = null) |
||
69 | { |
||
70 | $this->_objects = $objectArr; |
||
71 | $this->_myId = $myId; |
||
72 | $this->_parentId = $parentId; |
||
73 | if (null !== $rootId) { |
||
74 | $this->_rootId = $rootId; |
||
75 | } |
||
76 | $this->_initialize(); |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * Initialize the object |
||
81 | * |
||
82 | * @access private |
||
83 | */ |
||
84 | private function _initialize() |
||
0 ignored issues
–
show
function _initialize() 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. ![]() |
|||
85 | { |
||
86 | /* @var $object XoopsObject */ |
||
87 | foreach ($this->_objects as $object) { |
||
88 | $key1 = $object->getVar($this->_myId); |
||
89 | $this->_tree[$key1]['obj'] = $object; |
||
90 | $key2 = $object->getVar($this->_parentId); |
||
91 | $this->_tree[$key1]['parent'] = $key2; |
||
92 | $this->_tree[$key2]['child'][] = $key1; |
||
93 | if (null !== $this->_rootId) { |
||
94 | $this->_tree[$key1]['root'] = $object->getVar($this->_rootId); |
||
95 | } |
||
96 | } |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Get the tree |
||
101 | * |
||
102 | * @return array Associative array comprising the tree |
||
103 | */ |
||
104 | public function alumni_getTree() |
||
0 ignored issues
–
show
function alumni_getTree() 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. ![]() |
|||
105 | { |
||
106 | return $this->_tree; |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * returns an object from the tree specified by its id |
||
111 | * |
||
112 | * @param string $key ID of the object to retrieve |
||
113 | * @return XoopsObject Object within the tree |
||
114 | */ |
||
115 | public function alumni_getByKey($key) |
||
0 ignored issues
–
show
function alumni_getByKey() 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. ![]() |
|||
116 | { |
||
117 | return $this->_tree[$key]['obj']; |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * returns an array of all the first child object of an object specified by its id |
||
122 | * |
||
123 | * @param string $key ID of the parent object |
||
124 | * @return array Array of children of the parent |
||
125 | */ |
||
126 | public function alumni_getFirstChild($key) |
||
0 ignored issues
–
show
function alumni_getFirstChild() 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. ![]() |
|||
127 | { |
||
128 | $ret = []; |
||
129 | if (isset($this->_tree[$key]['child'])) { |
||
130 | foreach ($this->_tree[$key]['child'] as $childkey) { |
||
131 | $ret[$childkey] = $this->_tree[$childkey]['obj']; |
||
132 | } |
||
133 | } |
||
134 | |||
135 | return $ret; |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * returns an array of all child objects of an object specified by its id |
||
140 | * |
||
141 | * @param string $key ID of the parent |
||
142 | * @param array $ret (Empty when called from client) Array of children from previous recursions. |
||
143 | * @return array Array of child nodes. |
||
144 | */ |
||
145 | public function alumni_getAllChild($key, $ret = []) |
||
0 ignored issues
–
show
function alumni_getAllChild() 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. ![]() |
|||
146 | { |
||
147 | if (isset($this->_tree[$key]['child'])) { |
||
148 | foreach ($this->_tree[$key]['child'] as $childkey) { |
||
149 | $ret[$childkey] = $this->_tree[$childkey]['obj']; |
||
150 | $children = $this->alumni_getAllChild($childkey, $ret); |
||
151 | foreach (array_keys($children) as $newkey) { |
||
152 | $ret[$newkey] = $children[$newkey]; |
||
153 | } |
||
154 | } |
||
155 | } |
||
156 | |||
157 | return $ret; |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * returns an array of all parent objects. |
||
162 | * the key of returned array represents how many levels up from the specified object |
||
163 | * |
||
164 | * @param string $key ID of the child object |
||
165 | * @param array $ret (empty when called from outside) Result from previous recursions |
||
166 | * @param int $uplevel (empty when called from outside) level of recursion |
||
167 | * @return array Array of parent nodes. |
||
168 | */ |
||
169 | public function alumni_getAllParent($key, $ret = [], $uplevel = 1) |
||
0 ignored issues
–
show
function alumni_getAllParent() 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. ![]() |
|||
170 | { |
||
171 | if (isset($this->_tree[$key]['parent']) && isset($this->_tree[$this->_tree[$key]['parent']]['obj'])) { |
||
172 | $ret[$uplevel] = $this->_tree[$this->_tree[$key]['parent']]['obj']; |
||
173 | $parents = $this->alumni_getAllParent($this->_tree[$key]['parent'], $ret, $uplevel + 1); |
||
174 | foreach (array_keys($parents) as $newkey) { |
||
175 | $ret[$newkey] = $parents[$newkey]; |
||
176 | } |
||
177 | } |
||
178 | |||
179 | return $ret; |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * Make options for a select box from |
||
184 | * |
||
185 | * @param string $fieldName Name of the member variable from the |
||
186 | * node objects that should be used as the title for the options. |
||
187 | * @param string $selected Value to display as selected |
||
188 | * @param int $key ID of the object to display as the root of select options |
||
189 | * @param string $ret (reference to a string when called from outside) Result from previous recursions |
||
190 | * @param string $prefix_orig String to indent items at deeper levels |
||
191 | * @param string $prefix_curr String to indent the current item |
||
192 | * |
||
193 | * @return void |
||
194 | */ |
||
195 | private function alumni_makeSelBoxOptions($fieldName, $selected, $key, &$ret, $prefix_orig, $prefix_curr = '') |
||
0 ignored issues
–
show
function alumni_makeSelBoxOptions() 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. ![]() $prefix_orig 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. ![]() |
|||
196 | { |
||
197 | if ($key > 0) { |
||
198 | /* @var $object XoopsObject */ |
||
199 | $object = $this->_tree[$key]['obj']; |
||
200 | $value = $object->getVar($this->_myId); |
||
201 | $ret .= '<option value="' . $value . '"'; |
||
202 | if ($value == $selected) { |
||
203 | $ret .= ' selected="selected"'; |
||
204 | } |
||
205 | $ret .= '>' . $prefix_curr . $object->getVar($fieldName) . '</option>'; |
||
0 ignored issues
–
show
$prefix_curr 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. ![]() |
|||
206 | $prefix_curr .= $prefix_orig; |
||
0 ignored issues
–
show
$prefix_curr 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. ![]() |
|||
207 | } |
||
208 | View Code Duplication | if (isset($this->_tree[$key]['child']) && !empty($this->_tree[$key]['child'])) { |
|
0 ignored issues
–
show
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. ![]() |
|||
209 | foreach ($this->_tree[$key]['child'] as $childkey) { |
||
210 | $this->alumni_makeSelBoxOptions($fieldName, $selected, $childkey, $ret, $prefix_orig, $prefix_curr); |
||
0 ignored issues
–
show
$prefix_orig 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. ![]() |
|||
211 | } |
||
212 | } |
||
213 | } |
||
214 | |||
215 | /** |
||
216 | * Make a select box with options from the tree |
||
217 | * |
||
218 | * @param $name |
||
219 | * @param string $fieldName Name of the member variable from the |
||
220 | * node objects that should be used as the title for the options. |
||
221 | * @param string $prefix String to indent deeper levels |
||
222 | * @param string $selected Value to display as selected |
||
223 | * @param bool $addEmptyOption Set TRUE to add an empty option with value "0" at the top of the hierarchy |
||
224 | * @param integer $key ID of the object to display as the root of select options |
||
225 | * @param string $extra |
||
226 | * @return string HTML select box |
||
227 | */ |
||
228 | public function alumni_makeSelBox($name, $fieldName, $prefix = '-', $selected = '', $addEmptyOption = false, $key = 0, $extra = '') |
||
0 ignored issues
–
show
function alumni_makeSelBox() 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. ![]() |
|||
229 | { |
||
230 | $xoops = Xoops::getInstance(); |
||
0 ignored issues
–
show
$xoops 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 ![]() |
|||
231 | $ret = '<select name="' . $name . '" id="' . $name . '" ' . $extra . '>'; |
||
232 | if (false != $addEmptyOption) { |
||
0 ignored issues
–
show
|
|||
233 | $ret .= '<option value="0">' . XoopsLocale::ALL . '</option>'; |
||
234 | } |
||
235 | $this->alumni_makeSelBoxOptions($fieldName, $selected, $key, $ret, $prefix); |
||
236 | |||
237 | return $ret . '</select>'; |
||
238 | } |
||
239 | |||
240 | /** |
||
241 | * Make options for a array |
||
242 | * |
||
243 | * @param string $fieldName Name of the member variable from the |
||
244 | * node objects that should be used as the column. |
||
245 | * @param string $prefix String to indent deeper levels |
||
246 | * @param integer $key ID of the object to display as the root of the array |
||
247 | * @return array |
||
248 | */ |
||
249 | public function alumni_makeArrayTree($fieldName, $prefix = '-', $key = 0) |
||
0 ignored issues
–
show
function alumni_makeArrayTree() 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. ![]() |
|||
250 | { |
||
251 | $ret = []; |
||
252 | $this->alumni_makeArrayTreeOptions($fieldName, $key, $ret, $prefix); |
||
253 | |||
254 | return $ret; |
||
255 | } |
||
256 | |||
257 | /** |
||
258 | * Make a array with options from the tree |
||
259 | * |
||
260 | * @param string $fieldName Name of the member variable from the |
||
261 | * node objects that should be used as the column. |
||
262 | * @param integer $key ID of the object to display as the root of the array |
||
263 | * @param $ret |
||
264 | * @param string $prefix_orig String to indent deeper levels (origin) |
||
265 | * @param string $prefix_curr String to indent deeper levels (current) |
||
266 | * |
||
267 | * @return void |
||
268 | */ |
||
269 | public function alumni_makeArrayTreeOptions($fieldName, $key, &$ret, $prefix_orig, $prefix_curr = '') |
||
0 ignored issues
–
show
function alumni_makeArrayTreeOptions() 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. ![]() $prefix_orig 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. ![]() |
|||
270 | { |
||
271 | if ($key > 0) { |
||
272 | $value = $this->_tree[$key]['obj']->getVar($this->_myId); |
||
273 | $ret[$value] = $prefix_curr . $this->_tree[$key]['obj']->getVar($fieldName); |
||
0 ignored issues
–
show
$prefix_curr 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. ![]() |
|||
274 | $prefix_curr .= $prefix_orig; |
||
0 ignored issues
–
show
$prefix_curr 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. ![]() |
|||
275 | } |
||
276 | View Code Duplication | if (isset($this->_tree[$key]['child']) && !empty($this->_tree[$key]['child'])) { |
|
0 ignored issues
–
show
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. ![]() |
|||
277 | foreach ($this->_tree[$key]['child'] as $childkey) { |
||
278 | $this->alumni_makeArrayTreeOptions($fieldName, $childkey, $ret, $prefix_orig, $prefix_curr); |
||
0 ignored issues
–
show
$prefix_orig 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. ![]() |
|||
279 | } |
||
280 | } |
||
281 | } |
||
282 | } |
||
283 |
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.