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 | * @description: each order has a shipping address. |
||
5 | * |
||
6 | * |
||
7 | * |
||
8 | * @authors: Nicolaas [at] Sunny Side Up .co.nz |
||
9 | * @package: ecommerce |
||
10 | * @sub-package: address |
||
11 | * @inspiration: Silverstripe Ltd, Jeremy |
||
12 | **/ |
||
13 | class ShippingAddress extends OrderAddress |
||
14 | { |
||
15 | /** |
||
16 | * what variables are accessible through http://mysite.com/api/ecommerce/v1/ShippingAddress/. |
||
17 | * |
||
18 | * @var array |
||
19 | */ |
||
20 | private static $api_access = array( |
||
0 ignored issues
–
show
Comprehensibility
introduced
by
![]() |
|||
21 | 'view' => array( |
||
22 | 'ShippingPrefix', |
||
23 | 'ShippingFirstName', |
||
24 | 'ShippingSurname', |
||
25 | 'ShippingAddress', |
||
26 | 'ShippingAddress2', |
||
27 | 'ShippingCity', |
||
28 | 'ShippingPostalCode', |
||
29 | 'ShippingRegionCode', |
||
30 | 'ShippingCountry', |
||
31 | 'ShippingPhone', |
||
32 | ), |
||
33 | ); |
||
34 | |||
35 | /** |
||
36 | * standard SS variable. |
||
37 | * |
||
38 | * @return array |
||
39 | */ |
||
40 | private static $db = array( |
||
0 ignored issues
–
show
|
|||
41 | 'ShippingPrefix' => 'Varchar(10)', |
||
42 | 'ShippingFirstName' => 'Varchar(100)', |
||
43 | 'ShippingSurname' => 'Varchar(100)', |
||
44 | 'ShippingAddress' => 'Varchar(200)', |
||
45 | 'ShippingAddress2' => 'Varchar(255)', |
||
46 | 'ShippingCity' => 'Varchar(100)', |
||
47 | 'ShippingPostalCode' => 'Varchar(30)', |
||
48 | 'ShippingRegionCode' => 'Varchar(100)', |
||
49 | 'ShippingCountry' => 'Varchar(4)', |
||
50 | 'ShippingPhone' => 'Varchar(100)', |
||
51 | 'Obsolete' => 'Boolean', |
||
52 | 'OrderID' => 'Int', ////NOTE: we have this here for faster look-ups and to make addresses behave similar to has_many dataobjects |
||
53 | ); |
||
54 | |||
55 | /** |
||
56 | * standard SS static definition. |
||
57 | **/ |
||
58 | private static $has_one = array( |
||
0 ignored issues
–
show
|
|||
59 | 'ShippingRegion' => 'EcommerceRegion', |
||
60 | ); |
||
61 | |||
62 | /** |
||
63 | * standard SS static definition. |
||
64 | **/ |
||
65 | private static $belongs_to = array( |
||
0 ignored issues
–
show
|
|||
66 | 'Order' => 'Order', |
||
67 | ); |
||
68 | |||
69 | /** |
||
70 | * standard SS static definition. |
||
71 | */ |
||
72 | private static $default_sort = [ |
||
0 ignored issues
–
show
|
|||
73 | 'ID' => 'DESC' |
||
74 | ]; |
||
75 | |||
76 | /** |
||
77 | * standard SS variable. |
||
78 | * |
||
79 | * @return array |
||
80 | */ |
||
81 | private static $indexes = array( |
||
0 ignored issues
–
show
|
|||
82 | 'Obsolete' => true, |
||
83 | 'OrderID' => true, |
||
84 | 'ShippingCountry' => true |
||
85 | ); |
||
86 | |||
87 | /** |
||
88 | * standard SS variable. |
||
89 | * |
||
90 | * @return array |
||
91 | */ |
||
92 | private static $casting = array( |
||
0 ignored issues
–
show
|
|||
93 | 'ShippingFullCountryName' => 'Varchar(200)', |
||
94 | ); |
||
95 | |||
96 | /** |
||
97 | * standard SS variable. |
||
98 | * |
||
99 | * @return array |
||
100 | */ |
||
101 | private static $searchable_fields = array( |
||
0 ignored issues
–
show
|
|||
102 | 'OrderID' => array( |
||
103 | 'field' => 'NumericField', |
||
104 | 'title' => 'Order Number', |
||
105 | ), |
||
106 | 'ShippingSurname' => 'PartialMatchFilter', |
||
107 | 'ShippingAddress' => 'PartialMatchFilter', |
||
108 | 'ShippingCity' => 'PartialMatchFilter', |
||
109 | 'ShippingCountry' => 'PartialMatchFilter', |
||
110 | 'Obsolete', |
||
111 | ); |
||
112 | |||
113 | /** |
||
114 | * standard SS variable. |
||
115 | * |
||
116 | * @return array |
||
117 | */ |
||
118 | private static $summary_fields = array( |
||
0 ignored issues
–
show
|
|||
119 | 'Order.Title', |
||
120 | 'ShippingFirstName', |
||
121 | 'ShippingSurname', |
||
122 | 'ShippingCity', |
||
123 | 'ShippingPostalCode', |
||
124 | 'ShippingCountry', |
||
125 | 'ShippingPhone' |
||
126 | ); |
||
127 | |||
128 | public function fieldLabels($includerelations = true) |
||
129 | { |
||
130 | $billingAddress = Injector::inst()->get('BillingAddress'); |
||
131 | $shippingLabels = parent::fieldLabels($includerelations); |
||
132 | $billingLabels = $billingAddress->fieldLabels($includerelations); |
||
133 | $summaryFields = $this->stat('field_labels'); |
||
134 | foreach ($shippingLabels as $shippingKey => $shippingLabel) { |
||
0 ignored issues
–
show
The expression
$shippingLabels of type array|string is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
135 | if (! isset($summaryFields[$shippingKey])) { |
||
136 | $billingKey = str_replace('Shipping', '', $shippingKey); |
||
137 | if (isset($billingLabels[$billingKey])) { |
||
138 | $shippingLabels[$shippingKey] = $billingLabels[$billingKey]; |
||
139 | } |
||
140 | } |
||
141 | } |
||
142 | |||
143 | return $shippingLabels; |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * standard SS variable. |
||
148 | * |
||
149 | * @return string |
||
150 | */ |
||
151 | private static $singular_name = 'Shipping Address'; |
||
0 ignored issues
–
show
|
|||
152 | public function i18n_singular_name() |
||
153 | { |
||
154 | return _t('ShippingAddress.SHIPPINGADDRESS', 'Shipping Address'); |
||
155 | } |
||
156 | |||
157 | /** |
||
158 | * standard SS variable. |
||
159 | * |
||
160 | * @return string |
||
161 | */ |
||
162 | private static $plural_name = 'Shipping Addresses'; |
||
0 ignored issues
–
show
|
|||
163 | public function i18n_plural_name() |
||
164 | { |
||
165 | return _t('ShippingAddress.SHIPPINGADDRESSES', 'Shipping Addresses'); |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * Standard SS variable. |
||
170 | * |
||
171 | * @var string |
||
172 | */ |
||
173 | private static $description = 'The address for delivery of the order.'; |
||
174 | |||
175 | /** |
||
176 | *@return FieldList |
||
177 | **/ |
||
178 | public function getCMSFields() |
||
179 | { |
||
180 | $fields = parent::getCMSFields(); |
||
181 | $fields->replaceField('OrderID', new ReadonlyField('OrderID')); |
||
182 | |||
183 | return $fields; |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * returns the full name for the shipping country code saved. |
||
188 | * |
||
189 | * @return string |
||
190 | **/ |
||
191 | public function ShippingFullCountryName() |
||
192 | { |
||
193 | return $this->getShippingFullCountryName(); |
||
194 | } |
||
195 | public function getShippingFullCountryName() |
||
196 | { |
||
197 | return EcommerceCountry::find_title($this->ShippingCountry); |
||
0 ignored issues
–
show
The property
ShippingCountry does not exist on object<ShippingAddress> . 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. ![]() |
|||
198 | } |
||
199 | |||
200 | /** |
||
201 | * Puts together the fields for the Order Form (and other front-end purposes). |
||
202 | * |
||
203 | * @param Member $member |
||
0 ignored issues
–
show
Should the type for parameter
$member not be null|Member ?
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. ![]() |
|||
204 | * |
||
205 | * @return FieldList |
||
206 | **/ |
||
207 | public function getFields(Member $member = null) |
||
208 | { |
||
209 | $fields = parent::getEcommerceFields(); |
||
0 ignored issues
–
show
It seems like you call parent on a different method (
getEcommerceFields() instead of getFields() ). Are you sure this is correct? If so, you might want to change this to $this->getEcommerceFields() .
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 ![]() |
|||
210 | $hasPreviousAddresses = false; |
||
0 ignored issues
–
show
$hasPreviousAddresses 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 ![]() |
|||
211 | if (EcommerceConfig::get('OrderAddress', 'use_separate_shipping_address')) { |
||
212 | $shippingFieldsHeader = new CompositeField( |
||
213 | new HeaderField('SendGoodsToADifferentAddress', _t('ShippingAddress.SENDGOODSTODIFFERENTADDRESS', 'Delivery Address'), 3), |
||
214 | new LiteralField('ShippingNote', '<p class="message warning" id="ShippingNote">'._t('ShippingAddress.SHIPPINGNOTE', 'Your goods will be sent to the address below.').'</p>') |
||
215 | ); |
||
216 | |||
217 | if ($member && Member::currentUser()) { |
||
218 | if ($member->exists() && !$member->IsShopAdmin()) { |
||
219 | $this->FillWithLastAddressFromMember($member, true); |
||
220 | if (EcommerceConfig::get('ShippingAddress', 'allow_selection_of_previous_addresses_in_checkout')) { |
||
221 | $addresses = $member->previousOrderAddresses($this->baseClassLinkingToOrder(), $this->ID, $onlyLastRecord = false, $keepDoubles = false); |
||
222 | //we want MORE than one here not just one. |
||
223 | if ($addresses->count() > 1) { |
||
224 | $hasPreviousAddresses = true; |
||
0 ignored issues
–
show
$hasPreviousAddresses 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 ![]() |
|||
225 | $shippingFieldsHeader->push(SelectOrderAddressField::create('SelectShippingAddressField', _t('ShippingAddress.SELECTBILLINGADDRESS', 'Select Shipping Address'), $addresses)); |
||
226 | } |
||
227 | } |
||
228 | } |
||
229 | $shippingFields = new CompositeField( |
||
230 | new TextField('ShippingFirstName', _t('ShippingAddress.FIRSTNAME', 'First Name')), |
||
231 | new TextField('ShippingSurname', _t('ShippingAddress.SURNAME', 'Surname')) |
||
232 | ); |
||
233 | } else { |
||
234 | $shippingFields = new CompositeField( |
||
235 | new TextField('ShippingFirstName', _t('ShippingAddress.FIRSTNAME', 'First Name')), |
||
236 | new TextField('ShippingSurname', _t('ShippingAddress.SURNAME', 'Surname')) |
||
237 | ); |
||
238 | } |
||
239 | $shippingFields->push(new TextField('ShippingPhone', _t('ShippingAddress.PHONE', 'Phone'))); |
||
240 | $mappingArray = $this->Config()->get('fields_to_google_geocode_conversion'); |
||
241 | if (is_array($mappingArray) && count($mappingArray)) { |
||
242 | if (!class_exists('GoogleAddressField')) { |
||
243 | user_error('You must install the Sunny Side Up google_address_field module OR remove entries from: ShippingAddress.fields_to_google_geocode_conversion'); |
||
244 | } |
||
245 | $shippingFields->push( |
||
246 | $shippingEcommerceGeocodingField = new GoogleAddressField( |
||
247 | 'ShippingEcommerceGeocodingField', |
||
248 | _t('ShippingAddress.Find_Address', 'Find address'), |
||
249 | Session::get('ShippingEcommerceGeocodingFieldValue') |
||
250 | ) |
||
251 | ); |
||
252 | $shippingEcommerceGeocodingField->setFieldMap($mappingArray); |
||
253 | //$shippingFields->push(new HiddenField('ShippingAddress2')); |
||
254 | //$shippingFields->push(new HiddenField('ShippingCity')); |
||
255 | } else { |
||
256 | } |
||
257 | $shippingFields->push(new TextField('ShippingAddress', _t('ShippingAddress.ADDRESS', 'Address'))); |
||
258 | $shippingFields->push(new TextField('ShippingAddress2', _t('ShippingAddress.ADDRESS2', ''))); |
||
259 | $shippingFields->push(new TextField('ShippingCity', _t('ShippingAddress.CITY', 'Town'))); |
||
260 | $shippingFields->push($this->getRegionField('ShippingRegionID', 'ShippingRegionCode')); |
||
261 | $shippingFields->push($this->getPostalCodeField('ShippingPostalCode')); |
||
262 | $shippingFields->push($this->getCountryField('ShippingCountry')); |
||
263 | $this->makeSelectedFieldsReadOnly($shippingFields); |
||
264 | $shippingFieldsHeader->addExtraClass('shippingFieldsHeader'); |
||
265 | $shippingFields->addExtraClass('orderAddressHolder'); |
||
266 | $fields->push($shippingFieldsHeader); |
||
267 | $shippingFields->addExtraClass('shippingFields'); |
||
268 | $fields->push($shippingFields); |
||
269 | } |
||
270 | $this->extend('augmentEcommerceShippingAddressFields', $shippingFields); |
||
271 | |||
272 | return $fields; |
||
273 | } |
||
274 | |||
275 | /** |
||
276 | * Return which shipping fields should be required on {@link OrderFormAddress}. |
||
277 | * |
||
278 | * @return array |
||
279 | */ |
||
280 | public function getRequiredFields() |
||
281 | { |
||
282 | return $this->Config()->get('required_fields'); |
||
283 | } |
||
284 | } |
||
285 |