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 CustomerGalleryPage extends Page |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
4 | { |
|||||||||||
5 | private static $icon = 'mysite/images/treeicons/CustomerGalleryPage'; |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
6 | ||||||||||||
7 | private static $description = 'Gallery of Customer Feedback and Images'; |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
8 | ||||||||||||
9 | private static $can_be_root = false; |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
10 | ||||||||||||
11 | private static $allow_children = 'none'; |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
12 | ||||||||||||
13 | public function canCreate($member = null) |
|||||||||||
14 | { |
|||||||||||
15 | return CustomerGalleryPage::get()->count() ? true : false; |
|||||||||||
16 | } |
|||||||||||
17 | ||||||||||||
18 | public function getCMSFields() |
|||||||||||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
||||||||||||
19 | { |
|||||||||||
20 | $fields = parent::getCMSFields(); |
|||||||||||
21 | $fields->removeByName('FolderID'); |
|||||||||||
22 | $fields->removeByName('Extensions'); |
|||||||||||
23 | return $fields; |
|||||||||||
24 | } |
|||||||||||
25 | } |
|||||||||||
26 | ||||||||||||
27 | class CustomerGalleryPage_Controller extends Page_Controller |
|||||||||||
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. ![]() |
||||||||||||
28 | { |
|||||||||||
29 | private static $allowed_actions = array( |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
30 | "show", |
|||||||||||
31 | "Form" |
|||||||||||
32 | ); |
|||||||||||
33 | ||||||||||||
34 | protected $filter = '', $filterType = '', $filterValue = '', $join = ''; |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
35 | ||||||||||||
36 | public function init() |
|||||||||||
37 | { |
|||||||||||
38 | parent::init(); |
|||||||||||
39 | PrettyPhoto::include_code(); |
|||||||||||
40 | Requirements::javascript("mysite/javascript/MediaArticles.js"); |
|||||||||||
41 | } |
|||||||||||
42 | ||||||||||||
43 | public function PhotoUploadPage() |
|||||||||||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
||||||||||||
44 | { |
|||||||||||
45 | return PhotoUploadPage::get()->First(); |
|||||||||||
46 | } |
|||||||||||
47 | ||||||||||||
48 | ||||||||||||
49 | public function HasFilter() |
|||||||||||
50 | { |
|||||||||||
51 | return $this->filter ? true : false; |
|||||||||||
52 | } |
|||||||||||
53 | ||||||||||||
54 | public function Location() |
|||||||||||
55 | { |
|||||||||||
56 | $countries = DB::query("SELECT DISTINCT(\"PictureLocation\") FROM \"CustomerImage\" WHERE \"CustomerImage\".\"Status\" = 'Approved' ORDER BY \"PictureLocation\" ")->keyedColumn(); |
|||||||||||
57 | return $this->makeDos("location", $countries); |
|||||||||||
58 | } |
|||||||||||
59 | ||||||||||||
60 | /* |
|||||||||||
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. ![]() |
||||||||||||
61 | function MyPictures() { |
|||||||||||
62 | $mypictures = array(); |
|||||||||||
63 | $member = Member::currentUser(); |
|||||||||||
64 | if($member) { |
|||||||||||
65 | $dos = CustomerImage::get()->filter(array("Status" => 'Approved', "OwnerID" => $member->ID)); |
|||||||||||
66 | if($dos->count()) { |
|||||||||||
67 | foreach($dos as $do) { |
|||||||||||
68 | $mypictures[$member->ID] = "My pictures (".$dos->count().")"; |
|||||||||||
69 | } |
|||||||||||
70 | return $this->makeDos("mypictures", $mypictures); |
|||||||||||
71 | } |
|||||||||||
72 | } |
|||||||||||
73 | } |
|||||||||||
74 | */ |
|||||||||||
75 | ||||||||||||
76 | public function Product() |
|||||||||||
77 | { |
|||||||||||
78 | $stage = Versioned::current_stage(); |
|||||||||||
79 | $productTable = "SiteTree"; |
|||||||||||
80 | if ($stage) { |
|||||||||||
81 | $productTable .= "_".$stage; |
|||||||||||
82 | } |
|||||||||||
83 | $row = DB::query("SELECT DISTINCT(\"ProductPageID\") AS ProductPageID FROM \"CustomerImage\" INNER JOIN \"$productTable\" ON \"$productTable\".\"ID\" = \"CustomerImage\".\"ProductPageID\" WHERE \"CustomerImage\".\"Status\" = 'Approved' ORDER BY \"$productTable\".\"Title\""); |
|||||||||||
84 | $newArray = array(); |
|||||||||||
85 | foreach ($row as $dataArray) { |
|||||||||||
86 | $page = SiteTree::get()->byID($dataArray["ProductPageID"]); |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
87 | if ($page) { |
|||||||||||
88 | $key = $page->ID; |
|||||||||||
89 | $value = $page->Title; |
|||||||||||
90 | } |
|||||||||||
91 | $newArray[$key] = $value; |
|||||||||||
0 ignored issues
–
show
The variable
$key does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() The variable
$value does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
||||||||||||
92 | } |
|||||||||||
93 | return $this->makeDos("product", $newArray); |
|||||||||||
94 | } |
|||||||||||
95 | ||||||||||||
96 | public function Years() |
|||||||||||
97 | { |
|||||||||||
98 | $years = DB::query("SELECT DISTINCT(YEAR(\"Created\")) FROM \"CustomerImage\" INNER JOIN \"File\" ON \"File\".\"ID\" = \"CustomerImage\".\"ID\" WHERE \"CustomerImage\".\"Status\" = 'Approved' ORDER BY \"Created\" DESC")->keyedColumn(); |
|||||||||||
99 | return $this->makeDos("year", $years); |
|||||||||||
100 | } |
|||||||||||
101 | ||||||||||||
102 | protected function makeDos($title, $data) |
|||||||||||
103 | { |
|||||||||||
104 | $dos = new ArrayList(); |
|||||||||||
105 | //sort($data); |
|||||||||||
106 | if ($data && count($data)) { |
|||||||||||
107 | foreach ($data as $key => $value) { |
|||||||||||
108 | if ($key && $value) { |
|||||||||||
109 | $key = urlencode(preg_replace("/[^a-zA-Z0-9\s]/", "", $key)); |
|||||||||||
110 | $do = new DataObject(); |
|||||||||||
111 | $do->Code = $key; |
|||||||||||
112 | $do->Name = $value; |
|||||||||||
113 | $do->LinkingMode = (($this->filterType == $title) && ($this->filterValue == $key)) ? "current" : "link"; |
|||||||||||
114 | $do->filter = (($this->filterType == $title) && ($this->filterValue == $key)) ? "alwaysfilter" : "filter"; |
|||||||||||
115 | $do->Link = $this->Link("show/$title/".$key."/"); |
|||||||||||
116 | $dos->push($do); |
|||||||||||
117 | } |
|||||||||||
118 | } |
|||||||||||
119 | } |
|||||||||||
120 | if ($dos->count()) { |
|||||||||||
121 | return $dos; |
|||||||||||
122 | } |
|||||||||||
123 | return null; |
|||||||||||
124 | } |
|||||||||||
125 | ||||||||||||
126 | ||||||||||||
127 | public function Items($limit = 0) |
|||||||||||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
||||||||||||
128 | { |
|||||||||||
129 | if ($this->SortBy == 'Title') { |
|||||||||||
130 | $sort = array("File.Title", "ASC"); |
|||||||||||
131 | } elseif ($this->SortBy == 'UploadDate ASC') { |
|||||||||||
132 | $sort = array("File.Created", "ASC"); |
|||||||||||
133 | } elseif ($this->SortBy == 'UploadDate DESC') { |
|||||||||||
134 | $sort = array("File.Created", "DESC"); |
|||||||||||
135 | } else { |
|||||||||||
136 | $sort = array(); |
|||||||||||
137 | } |
|||||||||||
138 | if ($this->filter) { |
|||||||||||
139 | $this->filter .= " AND "; |
|||||||||||
140 | } |
|||||||||||
141 | $this->filter .= "\"CustomerImage\".\"Status\" = 'Approved' "; |
|||||||||||
142 | return CustomerImage::get()->where($this->filter)->sort($sort)->limit($limit); |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
143 | } |
|||||||||||
144 | ||||||||||||
145 | ||||||||||||
146 | ||||||||||||
147 | public function Form() |
|||||||||||
148 | { |
|||||||||||
149 | $fields = new FieldList( |
|||||||||||
150 | new TextField('Keyword', 'Keyword(s)', $this->value) |
|||||||||||
151 | //$date = new DateField('Date') |
|||||||||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
50% 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. ![]() |
||||||||||||
152 | ); |
|||||||||||
153 | //$date->setConfig('showcalendar', true); |
|||||||||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
80% 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. ![]() |
||||||||||||
154 | $actions = new FieldList(new FormAction('search', 'Search')); |
|||||||||||
0 ignored issues
–
show
'search' is of type string , but the function expects a object<The> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
||||||||||||
155 | return new Form($this, 'Form', $fields, $actions); |
|||||||||||
156 | } |
|||||||||||
157 | ||||||||||||
158 | ||||||||||||
159 | public function search($data, $form) |
|||||||||||
160 | { |
|||||||||||
161 | user_error("Not yet updated to 3.0"); |
|||||||||||
162 | $this->value = $data['Keyword']; |
|||||||||||
163 | $data = Convert::raw2sql($data); |
|||||||||||
164 | if ($data['Keyword']) { |
|||||||||||
165 | $stage = Versioned::current_stage(); |
|||||||||||
166 | $productTable = "SiteTree"; |
|||||||||||
167 | if ($stage) { |
|||||||||||
168 | $productTable .= "_".$stage; |
|||||||||||
169 | } |
|||||||||||
170 | $kwords = trim($data['Keyword']); |
|||||||||||
171 | $kwordsKWArray=split(" ", $kwords);//Breaking the string to array of words |
|||||||||||
172 | // Now let us generate the sql |
|||||||||||
173 | $kwordsFilter = array(); |
|||||||||||
174 | while (list($key, $val) = each($kwordsKWArray)) { |
|||||||||||
0 ignored issues
–
show
The assignment to
$key is unused. Consider omitting it like so list($first,,$third) .
This checks looks for assignemnts to variables using the Consider the following code example. <?php
function returnThreeValues() {
return array('a', 'b', 'c');
}
list($a, $b, $c) = returnThreeValues();
print $a . " - " . $c;
Only the variables Instead, the list call could have been. list($a,, $c) = returnThreeValues();
![]() |
||||||||||||
175 | $val = trim($val); |
|||||||||||
176 | if ($val<>" " and strlen($val) > 0) { |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
and instead of && is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
177 | $kwordsFilter[] = " \"Member\".\"ScreenName\" LIKE '%$val%' OR \"$productTable\".\"Title\" LIKE '%$val%' OR \"PictureLocation\" LIKE '%$val%' "; |
|||||||||||
178 | } |
|||||||||||
179 | } |
|||||||||||
180 | $this->filter = " (". implode(" AND ", $kwordsFilter).") "; |
|||||||||||
181 | $this->join .= " LEFT JOIN \"$productTable\" ON \"ProductPageID\" = \"$productTable\".\"ID\" " ; |
|||||||||||
182 | $this->join .= " INNER JOIN \"Member\" ON \"OwnerID\" = \"Member\".\"ID\" " ; |
|||||||||||
183 | } |
|||||||||||
184 | return array(); |
|||||||||||
185 | } |
|||||||||||
186 | ||||||||||||
187 | public function show($request) |
|||||||||||
188 | { |
|||||||||||
189 | $action = $request->param("ID"); |
|||||||||||
190 | $value = Convert::raw2sql($request->param("OtherID")); |
|||||||||||
191 | switch ($action) { |
|||||||||||
192 | case "year": |
|||||||||||
193 | $where = "Year(\"File\".\"Created\") = '$value'"; |
|||||||||||
194 | break; |
|||||||||||
195 | case "location": |
|||||||||||
196 | $where = "\"PictureLocation\" = '$value'"; |
|||||||||||
197 | break; |
|||||||||||
198 | case "product": |
|||||||||||
199 | $where = "\"ProductPageID\" = '$value'"; |
|||||||||||
200 | break; |
|||||||||||
201 | case "mypictures": |
|||||||||||
202 | $where = "\"OwnerID\" = '$value'"; |
|||||||||||
203 | break; |
|||||||||||
204 | default: |
|||||||||||
205 | $where = ""; |
|||||||||||
206 | } |
|||||||||||
207 | $this->filter = $where; |
|||||||||||
208 | $this->filterType = $action; |
|||||||||||
209 | $this->filterValue = $value; |
|||||||||||
210 | return array(); |
|||||||||||
211 | } |
|||||||||||
212 | } |
|||||||||||
213 |
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.