| Conditions | 11 |
| Paths | 16 |
| Total Lines | 67 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 207 | public function getFields(Member $member = null) |
||
| 208 | { |
||
| 209 | $fields = parent::getEcommerceFields(); |
||
| 210 | $hasPreviousAddresses = false; |
||
| 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; |
||
| 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 | |||
| 285 |