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 | *@author nicolaas [at] sunnysideup.co.nz |
||
5 | * |
||
6 | **/ |
||
7 | |||
8 | class GSTTaxModifierOptions extends DataObject |
||
0 ignored issues
–
show
|
|||
9 | { |
||
10 | |||
11 | /** |
||
12 | * standard SS variable |
||
13 | * @var Array |
||
14 | */ |
||
15 | private static $db = array( |
||
0 ignored issues
–
show
|
|||
16 | "CountryCode" => "Varchar(3)", |
||
17 | "Code" => "Varchar(12)", |
||
18 | "Name" => "Varchar(175)", |
||
19 | "LegalNotice" => "Varchar(255)", |
||
20 | "InclusiveOrExclusive" => "Enum('Inclusive,Exclusive', 'Inclusive')", |
||
21 | "Rate" => "Double", |
||
22 | "DoesNotApplyToAllProducts" => "Boolean", |
||
23 | "AppliesToAllCountries" => "Boolean" |
||
24 | ); |
||
25 | |||
26 | /** |
||
27 | * standard SS variable |
||
28 | * @var Array |
||
29 | */ |
||
30 | private static $defaults = array( |
||
0 ignored issues
–
show
|
|||
31 | "InclusiveOrExclusive" => "Inclusive" |
||
32 | ); |
||
33 | |||
34 | /** |
||
35 | * standard SS variable |
||
36 | * @var Array |
||
37 | */ |
||
38 | private static $casting = array( |
||
0 ignored issues
–
show
|
|||
39 | "CountryName" => "Varchar", |
||
40 | "PercentageNice" => "Varchar" |
||
41 | ); |
||
42 | |||
43 | /** |
||
44 | * standard SS variable |
||
45 | * @var Array |
||
46 | */ |
||
47 | private static $indexes = array( |
||
0 ignored issues
–
show
|
|||
48 | "Code" => true |
||
49 | ); |
||
50 | |||
51 | /** |
||
52 | * standard SS variable |
||
53 | * @var Array |
||
54 | */ |
||
55 | private static $searchable_fields = array( |
||
0 ignored issues
–
show
|
|||
56 | "CountryCode" => "PartialMatchFilter", |
||
57 | "Code" => "PartialMatchFilter", |
||
58 | "Name" => "PartialMatchFilter" |
||
59 | ); |
||
60 | |||
61 | /** |
||
62 | * standard SS variable |
||
63 | * @var Array |
||
64 | */ |
||
65 | private static $field_labels = array( |
||
0 ignored issues
–
show
|
|||
66 | "CountryName" => "Country Name", |
||
67 | "CountryCode" => "Country Code", |
||
68 | "Code" => "Code for tax", |
||
69 | "Name" => "Name for tax", |
||
70 | "InclusiveOrExclusive" => "Inclusive/Exclusive", |
||
71 | "LegalNotice" => "Here you can put your GST number or VAT registration number", |
||
72 | "Rate" => "Rate (e.g. 0.125 = 12.5%)", |
||
73 | "PercentageNice" => "Percentage", |
||
74 | "DoesNotApplyToAllProducts" => "Added to individual products only" |
||
75 | ); |
||
76 | |||
77 | |||
78 | /** |
||
79 | * standard SS variable |
||
80 | * @var Array |
||
81 | */ |
||
82 | private static $summary_fields = array( |
||
0 ignored issues
–
show
|
|||
83 | "CountryName" => 'Country', |
||
84 | "Code" => 'Code', |
||
85 | "Name" => 'Title', |
||
86 | "InclusiveOrExclusive" => 'Type', |
||
87 | "PercentageNice" => 'Percentage' |
||
88 | ); |
||
89 | |||
90 | /** |
||
91 | * standard SS variable |
||
92 | * @var String |
||
93 | */ |
||
94 | private static $singular_name = "Tax Option"; |
||
0 ignored issues
–
show
|
|||
95 | public function i18n_singular_name() |
||
96 | { |
||
97 | return _t("GSTTaxModifierOptions.TAXOPTION", "Tax Option"); |
||
98 | } |
||
99 | |||
100 | |||
101 | /** |
||
102 | * standard SS variable |
||
103 | * @var String |
||
104 | */ |
||
105 | private static $plural_name = "Tax Options"; |
||
0 ignored issues
–
show
|
|||
106 | public function i18n_plural_name() |
||
107 | { |
||
108 | return _t("GSTTaxModifierOptions.TAXOPTIONS", "Tax Options"); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * standard SS method |
||
113 | * @param Member | NULL |
||
114 | * @return Boolean |
||
0 ignored issues
–
show
|
|||
115 | */ |
||
116 | View Code Duplication | public function canCreate($member = null) |
|
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. ![]() |
|||
117 | { |
||
118 | $extended = $this->extendedCan(__FUNCTION__, $member); |
||
119 | if ($extended !== null) { |
||
120 | return $extended; |
||
121 | } |
||
122 | if (Permission::checkMember($member, Config::inst()->get("EcommerceRole", "admin_permission_code"))) { |
||
123 | return true; |
||
124 | } |
||
125 | return parent::canCreate($member); |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * standard SS method |
||
130 | * @param Member | NULL |
||
131 | * @return Boolean |
||
0 ignored issues
–
show
|
|||
132 | */ |
||
133 | View Code Duplication | public function canView($member = null) |
|
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. ![]() |
|||
134 | { |
||
135 | $extended = $this->extendedCan(__FUNCTION__, $member); |
||
136 | if ($extended !== null) { |
||
137 | return $extended; |
||
138 | } |
||
139 | if (Permission::checkMember($member, Config::inst()->get("EcommerceRole", "admin_permission_code"))) { |
||
140 | return true; |
||
141 | } |
||
142 | return parent::canCreate($member); |
||
0 ignored issues
–
show
It seems like you call parent on a different method (
canCreate() instead of canView() ). Are you sure this is correct? If so, you might want to change this to $this->canCreate() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
143 | } |
||
144 | |||
145 | /** |
||
146 | * standard SS method |
||
147 | * @param Member | NULL |
||
148 | * @return Boolean |
||
0 ignored issues
–
show
|
|||
149 | */ |
||
150 | View Code Duplication | public function canEdit($member = null) |
|
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. ![]() |
|||
151 | { |
||
152 | $extended = $this->extendedCan(__FUNCTION__, $member); |
||
153 | if ($extended !== null) { |
||
154 | return $extended; |
||
155 | } |
||
156 | if (Permission::checkMember($member, Config::inst()->get("EcommerceRole", "admin_permission_code"))) { |
||
157 | return true; |
||
158 | } |
||
159 | return parent::canEdit($member); |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * standard SS method |
||
164 | * @param Member | NULL |
||
165 | * @return Boolean |
||
0 ignored issues
–
show
|
|||
166 | */ |
||
167 | View Code Duplication | public function canDelete($member = null) |
|
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. ![]() |
|||
168 | { |
||
169 | $extended = $this->extendedCan(__FUNCTION__, $member); |
||
170 | if ($extended !== null) { |
||
171 | return $extended; |
||
172 | } |
||
173 | if (Permission::checkMember($member, Config::inst()->get("EcommerceRole", "admin_permission_code"))) { |
||
174 | return true; |
||
175 | } |
||
176 | return parent::canDelete($member); |
||
177 | } |
||
178 | |||
179 | /** |
||
180 | * standard SS method |
||
181 | * @return FieldList |
||
182 | */ |
||
183 | public function getCMSFields() |
||
184 | { |
||
185 | $fields = parent::getCMSFields(); |
||
186 | $fieldLabels = $this->Config()->get("field_labels"); |
||
187 | $fields->replaceField("CountryCode", new DropDownField("CountryCode", $fieldLabels["CountryCode"], EcommerceCountry::get_country_dropdown())); |
||
188 | $InclusiveOrExclusive = "Inclusive"; |
||
0 ignored issues
–
show
$InclusiveOrExclusive 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 ![]() |
|||
189 | if ($this->EcomConfig()->ShopPricesAreTaxExclusive) { |
||
190 | $InclusiveOrExclusive = "Exclusive"; |
||
0 ignored issues
–
show
$InclusiveOrExclusive 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 ![]() |
|||
191 | } |
||
192 | $fields->replaceField("InclusiveOrExclusive", new ReadonlyField("InclusiveOrExclusive", "This tax is: ..., you can change this setting in the e-commerce configuration.")); |
||
193 | return $fields; |
||
194 | } |
||
195 | |||
196 | public function Title() |
||
197 | { |
||
198 | return $this->getTitle(); |
||
199 | } |
||
200 | public function getTitle() |
||
201 | { |
||
202 | if ($this->AppliesToAllCountries) { |
||
0 ignored issues
–
show
The property
AppliesToAllCountries does not exist on object<GSTTaxModifierOptions> . 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. ![]() |
|||
203 | $country = _t("GSTTExModifierOption.WORLDWIDE", "world-wide"); |
||
204 | } else { |
||
205 | $country = $this->CountryCode; |
||
0 ignored issues
–
show
The property
CountryCode does not exist on object<GSTTaxModifierOptions> . 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. ![]() |
|||
206 | } |
||
207 | return $this->Name." ($country, ".number_format($this->Rate * 100, 2) . '%)'; |
||
0 ignored issues
–
show
The property
Name does not exist on object<GSTTaxModifierOptions> . 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. ![]() The property
Rate does not exist on object<GSTTaxModifierOptions> . 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. ![]() |
|||
208 | } |
||
209 | |||
210 | /** |
||
211 | * standard SS method |
||
212 | */ |
||
213 | public function populateDefaults() |
||
214 | { |
||
215 | parent::populateDefaults(); |
||
216 | //can only run after first dev/build |
||
217 | if (Security::database_is_ready()) { |
||
218 | $controller = Controller::curr(); |
||
219 | if ($controller instanceof DatabaseAdmin) { |
||
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. ![]() |
|||
220 | //cant do this now. |
||
221 | } else { |
||
222 | if ($this->EcomConfig()->ShopPricesAreTaxExclusive) { |
||
223 | $this->InclusiveOrExclusive = "Exclusive"; |
||
0 ignored issues
–
show
The property
InclusiveOrExclusive does not exist on object<GSTTaxModifierOptions> . 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. ![]() |
|||
224 | } else { |
||
225 | $this->InclusiveOrExclusive = "Inclusive"; |
||
0 ignored issues
–
show
The property
InclusiveOrExclusive does not exist on object<GSTTaxModifierOptions> . 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. ![]() |
|||
226 | } |
||
227 | } |
||
228 | } |
||
229 | } |
||
230 | |||
231 | /** |
||
232 | * standard SS method |
||
233 | */ |
||
234 | public function onBeforeWrite() |
||
235 | { |
||
236 | parent::onBeforeWrite(); |
||
237 | if ($this->EcomConfig()->ShopPricesAreTaxExclusive) { |
||
238 | $this->InclusiveOrExclusive = "Exclusive"; |
||
0 ignored issues
–
show
The property
InclusiveOrExclusive does not exist on object<GSTTaxModifierOptions> . 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. ![]() |
|||
239 | } else { |
||
240 | $this->InclusiveOrExclusive = "Inclusive"; |
||
0 ignored issues
–
show
The property
InclusiveOrExclusive does not exist on object<GSTTaxModifierOptions> . 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. ![]() |
|||
241 | } |
||
242 | } |
||
243 | |||
244 | // /** |
||
245 | // * standard SS method |
||
246 | // */ |
||
247 | // public function requireDefaultRecords() |
||
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. ![]() |
|||
248 | // { |
||
249 | // parent::requireDefaultRecords(); |
||
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. ![]() |
|||
250 | // DB::query(" |
||
251 | // UPDATE \"GSTTaxModifierOptions\" |
||
252 | // SET \"InclusiveOrExclusive\" = 'Inclusive' |
||
253 | // WHERE \"InclusiveOrExclusive\" <> 'Exclusive'" |
||
254 | // ); |
||
255 | // } |
||
256 | |||
257 | /** |
||
258 | * returns the instance of EcommerceDBConfig |
||
259 | * |
||
260 | * @return EcommerceDBConfig |
||
261 | **/ |
||
262 | public function EcomConfig() |
||
263 | { |
||
264 | return EcommerceDBConfig::current_ecommerce_db_config(); |
||
265 | } |
||
266 | |||
267 | public function CountryName() |
||
268 | { |
||
269 | return $this->getCountryName(); |
||
270 | } |
||
271 | public function getCountryName() |
||
272 | { |
||
273 | return EcommerceCountry::find_title($this->CountryCode); |
||
0 ignored issues
–
show
The property
CountryCode does not exist on object<GSTTaxModifierOptions> . 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. ![]() |
|||
274 | } |
||
275 | |||
276 | public function PercentageNice() |
||
277 | { |
||
278 | return $this->getPercentageNice(); |
||
279 | } |
||
280 | public function getPercentageNice() |
||
281 | { |
||
282 | return DBField::create_field("Text", ($this->Rate * 100)."%"); |
||
0 ignored issues
–
show
The property
Rate does not exist on object<GSTTaxModifierOptions> . 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. ![]() |
|||
283 | } |
||
284 | } |
||
285 |
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.