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 | |||
4 | class EVCPage extends Page |
||
0 ignored issues
–
show
|
|||
5 | { |
||
6 | } |
||
7 | |||
8 | |||
9 | class EVCPage_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. ![]() |
|||
10 | { |
||
11 | private static $allowed_actions = array( |
||
0 ignored issues
–
show
|
|||
12 | "show" => true, |
||
13 | "save" => true, |
||
14 | "retrieve" => true, |
||
15 | "reset" => true, |
||
16 | "previous" => true, |
||
17 | "lock" => true |
||
18 | ); |
||
19 | |||
20 | public function init() |
||
21 | { |
||
22 | parent::init(); |
||
23 | Requirements::javascript("framework/thirdparty/jquery/jquery.js"); |
||
24 | if(Director::isLive()) { |
||
25 | Requirements::themedCSS('ElectricVehicleCalculator.min', 'electric-vehicle-calculator'); |
||
26 | // Requirements::javascript("https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.bundle.min.js"); |
||
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. ![]() |
|||
27 | Requirements::javascript("electric-vehicle-calculator/thirdparty/chartjs/Chart.min.js"); |
||
28 | Requirements::javascript("electric-vehicle-calculator/javascript/ElectricVehicleCalculator.min.js"); |
||
29 | } else { |
||
30 | Requirements::themedCSS('ElectricVehicleCalculator', 'electric-vehicle-calculator'); |
||
31 | Requirements::javascript("electric-vehicle-calculator/thirdparty/chartjs/Chart.min.js"); |
||
32 | // Requirements::javascript("https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.bundle.min.js"); |
||
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. ![]() |
|||
33 | Requirements::javascript("electric-vehicle-calculator/javascript/ElectricVehicleCalculator.js"); |
||
34 | } |
||
35 | } |
||
36 | |||
37 | protected $evcDataSet = null; |
||
38 | |||
39 | public function index() |
||
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 ![]() |
|||
40 | { |
||
41 | $code = Session::get("EVCLastCode"); |
||
42 | $this->evcDataSet = EVCDataSet::find_or_create($code, true); |
||
43 | if (!$code) { |
||
44 | $code = $this->evcDataSet->Code; |
||
0 ignored issues
–
show
The property
Code does not exist on object<EVCDataSet> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
45 | Session::set("EVCLastCode", $code); |
||
46 | } |
||
47 | return $this->redirect($this->evcDataSet->MyLink($this, "show")); |
||
48 | } |
||
49 | |||
50 | function BackgroundImage() |
||
0 ignored issues
–
show
|
|||
51 | { |
||
52 | if(rand(0,1) == 1) { |
||
53 | $v = '/electric-vehicle-calculator/images/nz-road1.jpg'; |
||
54 | } else { |
||
55 | $v = '/electric-vehicle-calculator/images/nz-road2.jpg'; |
||
56 | } |
||
57 | return Controller::join_links ( |
||
58 | Director::absoluteBaseURL(), |
||
59 | $v |
||
60 | ); |
||
61 | } |
||
62 | |||
63 | public function HasCustomTitle() |
||
64 | { |
||
65 | if ($this->evcDataSet && $this->evcDataSet->Title) { |
||
66 | return true; |
||
67 | } |
||
68 | } |
||
69 | |||
70 | View Code Duplication | public function Title() |
|
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. ![]() |
|||
71 | { |
||
72 | if ($this->HasCustomTitle()) { |
||
73 | return Convert::raw2xml(urldecode($this->evcDataSet->Title)); |
||
0 ignored issues
–
show
The property
Title does not exist on object<EVCDataSet> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
74 | } |
||
75 | return Convert::raw2xml($this->Title); |
||
76 | } |
||
77 | |||
78 | View Code Duplication | public function MetaTitle() |
|
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. ![]() |
|||
79 | { |
||
80 | if ($this->HasCustomTitle()) { |
||
81 | return Convert::raw2xml(urldecode($this->evcDataSet->Title)); |
||
0 ignored issues
–
show
The property
Title does not exist on object<EVCDataSet> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
82 | } |
||
83 | return Convert::raw2xml($this->MetaTitle); |
||
84 | } |
||
85 | |||
86 | public function show($request) |
||
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 ![]() |
|||
87 | { |
||
88 | $code = $request->param("ID"); |
||
89 | $this->evcDataSet = EVCDataSet::find_or_create($code, false); |
||
90 | if ($this->evcDataSet && $this->evcDataSet->exists()) { |
||
91 | Requirements::javascript('electric-vehicle-calculator/javascript/ElectricVehicleCalculator.js'); |
||
92 | $link = $this->Link(); |
||
93 | if($link === '/') { |
||
94 | $link = '/home/'; |
||
95 | } |
||
96 | //Requirements::javascript("assets/evc/translations.js"); |
||
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. ![]() |
|||
97 | Requirements::customScript(" |
||
98 | EVC.serverInteraction.baseLink = '".$link."'; |
||
99 | EVC.serverInteraction.serverKey = '".$this->evcDataSet->Code."'; |
||
0 ignored issues
–
show
The property
Code does not exist on object<EVCDataSet> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
100 | ", "EVCSetBasics"); |
||
101 | Requirements::customScript($this->evcDataSet->returnValuesAsJS(), "EVCreturnValuesAsJS"); |
||
102 | return array(); |
||
103 | } else { |
||
104 | return $this->httpError(404); |
||
105 | } |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * returns empty string on error... |
||
110 | * ajax method ... |
||
111 | * @return string |
||
112 | */ |
||
113 | public function save($request) |
||
114 | { |
||
115 | $code = $request->param("ID"); |
||
116 | $this->evcDataSet = EVCDataSet::find_or_create($code, true); |
||
117 | //save it |
||
118 | $key = Convert::raw2sql($request->getVar("key")); |
||
119 | $value = Convert::raw2sql($request->getVar("value")); |
||
120 | if ($newCode = $this->evcDataSet->setValue($key, $value)) { |
||
0 ignored issues
–
show
It seems like
$key defined by \Convert::raw2sql($request->getVar('key')) on line 118 can also be of type array ; however, EVCDataSet::setValue() does only seem to accept string , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() It seems like
$value defined by \Convert::raw2sql($request->getVar('value')) on line 119 can also be of type array ; however, EVCDataSet::setValue() does only seem to accept string , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
121 | Session::set("EVCLastCode", $newCode); |
||
122 | Session::save(); |
||
123 | return $newCode; |
||
124 | } |
||
125 | } |
||
126 | |||
127 | public function retrieve($request) |
||
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 | $code = $request->param("ID"); |
||
130 | $this->evcDataSet = EVCDataSet::find_or_create($code, false); |
||
131 | if ($this->evcDataSet && $this->evcDataSet->exists() && $this->evcDataSet->Data) { |
||
0 ignored issues
–
show
The property
Data does not exist on object<EVCDataSet> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
132 | Session::set("EVCLastCode", $this->evcDataSet->Code); |
||
0 ignored issues
–
show
The property
Code does not exist on object<EVCDataSet> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
133 | Session::save(); |
||
134 | return $this->redirect($this->evcDataSet->MyLink($this, "show")); |
||
135 | } else { |
||
136 | return $this->httpError(404); |
||
137 | } |
||
138 | } |
||
139 | |||
140 | public function reset($request) |
||
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 ![]() |
|||
141 | { |
||
142 | Session::set("EVCLastCode", ""); |
||
143 | Session::clear("EVCLastCode"); |
||
144 | Session::save(); |
||
145 | return $this->redirect($this->Link()); |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * ajax method ... |
||
150 | * |
||
151 | */ |
||
152 | public function lock($request) |
||
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 ![]() |
|||
153 | { |
||
154 | $code = $request->param("ID"); |
||
155 | $this->evcDataSet = EVCDataSet::find_or_create($code, false); |
||
156 | $title = $request->getVar("title"); |
||
157 | if ($title && $this->evcDataSet && $this->evcDataSet->exists()) { |
||
158 | if ($title == "ignore") { |
||
0 ignored issues
–
show
This
if statement is empty and can be removed.
This check looks for the bodies of These if (rand(1, 6) > 3) {
//print "Check failed";
} else {
print "Check succeeded";
}
could be turned into if (rand(1, 6) <= 3) {
print "Check succeeded";
}
This is much more concise to read. ![]() |
|||
159 | //no need to do anything |
||
160 | } else { |
||
161 | $this->evcDataSet = $this->evcDataSet->getCopyIfNeeded(); |
||
162 | $this->evcDataSet->Locked = true; |
||
0 ignored issues
–
show
The property
Locked does not exist on object<EVCDataSet> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
163 | $this->evcDataSet->Title = Convert::raw2sql(urldecode($title)); |
||
0 ignored issues
–
show
The property
Title does not exist on object<EVCDataSet> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
164 | $this->evcDataSet->write(); |
||
165 | } |
||
166 | return $this->evcDataSet->MyLink($this, "retrieve"); |
||
167 | } |
||
168 | return "ERROR!"; |
||
169 | } |
||
170 | |||
171 | public function EVCDataSet() |
||
172 | { |
||
173 | return $this->evcDataSet; |
||
174 | } |
||
175 | |||
176 | public function IsLocked() |
||
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 ![]() |
|||
177 | { |
||
178 | return $this->evcDataSet->Locked; |
||
0 ignored issues
–
show
The property
Locked does not exist on object<EVCDataSet> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
179 | } |
||
180 | |||
181 | |||
182 | protected $previousCalculations = null; |
||
183 | |||
184 | public function previous($request) |
||
185 | { |
||
186 | $this->previousCalculations = PaginatedList::create(EVCDataSet::get()->filter(array("Locked" => 1))->where("Title IS NOT NULL AND Title <> ''")); |
||
187 | $this->previousCalculations->setPageLength(100); |
||
188 | return array(); |
||
189 | } |
||
190 | |||
191 | public function PreviousCalculations() |
||
192 | { |
||
193 | return $this->previousCalculations; |
||
194 | } |
||
195 | } |
||
196 |
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.