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 |
||
2 | |||
3 | class SiteTreeListboxField extends ListboxField |
||
0 ignored issues
–
show
|
|||
4 | { |
||
5 | |||
6 | /** |
||
7 | * |
||
8 | * @var Int |
||
9 | */ |
||
10 | protected $siteTreeParentID = 0; |
||
11 | |||
12 | /** |
||
13 | * |
||
14 | * @var Array |
||
15 | */ |
||
16 | protected $arrayOfAllowedIDs = array(); |
||
17 | |||
18 | /** |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $classNamesForItems = array("SiteTree"); |
||
23 | |||
24 | /** |
||
25 | * |
||
26 | * @var Array |
||
27 | */ |
||
28 | protected $siteTreeParentAllChildren = array(); |
||
29 | |||
30 | /** |
||
31 | * Creates a new dropdown field. |
||
32 | * |
||
33 | * @param string $name The field name |
||
34 | * @param string $title The field title |
||
35 | * @param array $source An map of the dropdown items |
||
36 | * @param string|array $value You can pass an array of values or a single value like a drop down to be selected |
||
37 | * @param int $size Optional size of the select element |
||
0 ignored issues
–
show
Should the type for parameter
$size not be integer|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. ![]() |
|||
38 | * @param form The parent form |
||
39 | */ |
||
40 | public function __construct($name, $title = '', $source = array(), $value = '', $size = null) |
||
41 | { |
||
42 | parent::__construct($name, $title, $source, $value, $size, true); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * |
||
47 | * @param Int $id |
||
48 | */ |
||
49 | public function setSiteTreeParentID($id) |
||
50 | { |
||
51 | $this->siteTreeParentID = $id; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * |
||
56 | * @param Int $id |
||
57 | * @param Int | string $array |
||
58 | */ |
||
59 | public function setSiteTreeParentAndChildClassNames($id, $array) |
||
60 | { |
||
61 | $this->siteTreeParentID = $id; |
||
62 | $this->setClassNamesForItems($array); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * |
||
67 | * @param Array | str $array |
||
68 | */ |
||
69 | public function setClassNamesForItems($array) |
||
70 | { |
||
71 | unset($this->classNamesForItems); |
||
72 | if (is_array($array)) { |
||
73 | $this->classNamesForItems = $array; |
||
74 | } else { |
||
75 | $this->classNamesForItems = array($array); |
||
76 | } |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * |
||
81 | * @param String $str |
||
82 | */ |
||
83 | public function addClassNameForItems($str) |
||
84 | { |
||
85 | $this->classNamesForItems[] = $str; |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * |
||
90 | * @param Array | SS_Map |
||
91 | */ |
||
92 | public function setSource($source) |
||
93 | { |
||
94 | if ($source instanceof SS_Map) { |
||
95 | $source = $source->toArray(); |
||
96 | } |
||
97 | if ($source) { |
||
98 | $hasCommas = array_filter( |
||
99 | array_keys($source), |
||
100 | create_function('$key', 'return strpos($key, ",") !== FALSE;') |
||
0 ignored issues
–
show
The use of
create_function is highly discouraged, better use a closure.
// Instead of
$function = create_function('$a, $b', 'return $a + $b');
// Better use
$function = function($a, $b) { return $a + $b; }
![]() |
|||
101 | ); |
||
102 | if ($hasCommas) { |
||
0 ignored issues
–
show
The expression
$hasCommas of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||
103 | throw new InvalidArgumentException('No commas allowed in $source keys'); |
||
104 | } |
||
105 | } |
||
106 | parent::setSource($source); |
||
107 | return $this; |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * |
||
112 | * @return Array |
||
0 ignored issues
–
show
|
|||
113 | */ |
||
114 | public function getSource() |
||
115 | { |
||
116 | $source = parent::getSource(); |
||
117 | //debug::log("original source count ".implode($this->classNamesForItems)." ".$this->siteTreeParentID.": ".count($source)); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
60% 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. ![]() |
|||
118 | if ($this->siteTreeParentID) { |
||
119 | $arrayItems = array(); |
||
0 ignored issues
–
show
$arrayItems 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 ![]() |
|||
120 | $allChildrenForSiteTreeParent = $this->getAllChildrenForSiteTreeParent($this->siteTreeParentID); |
||
121 | //debug::log("new source count: ".count($allChildrenForSiteTreeParent)); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% 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. ![]() |
|||
122 | $finalSource = array(); |
||
123 | foreach ($source as $sourceKey => $sourceValue) { |
||
124 | if (isset($allChildrenForSiteTreeParent[$sourceKey])) { |
||
125 | $finalSource[$sourceKey] = $sourceValue; |
||
126 | } |
||
127 | } |
||
128 | } else { |
||
129 | $finalSource = $source; |
||
130 | } |
||
131 | //debug::log("final source count: ".count($finalSource)); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% 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. ![]() |
|||
132 | return $finalSource; |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * @param Int |
||
137 | * @return Array |
||
138 | */ |
||
139 | View Code Duplication | private function getAllChildrenForSiteTreeParent($parentID) |
|
0 ignored issues
–
show
This method seems to be duplicated in 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. ![]() |
|||
140 | { |
||
141 | $children = SiteTree::get()->filter(array("ParentID" => $parentID)); |
||
142 | if ($children && $children->count()) { |
||
143 | foreach ($children as $child) { |
||
144 | foreach ($this->classNamesForItems as $matchingCLassName) { |
||
145 | //debug::log("has child"); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
72% 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. ![]() |
|||
146 | if ($child instanceof $matchingCLassName) { |
||
147 | //debug::log("we now have ".count($this->siteTreeParentAllChildren)." children"); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
63% 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. ![]() |
|||
148 | $this->siteTreeParentAllChildren[$child->ID] = $child->ID; |
||
149 | } |
||
150 | } |
||
151 | $this->getAllChildrenForSiteTreeParent($child->ID); |
||
152 | } |
||
153 | } |
||
154 | return $this->siteTreeParentAllChildren; |
||
155 | } |
||
156 | } |
||
157 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.