| Conditions | 10 |
| Paths | 15 |
| Total Lines | 66 |
| 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 |
||
| 212 | public function getFields(Member $member = null) |
||
| 213 | { |
||
| 214 | $fields = parent::getEcommerceFields(); |
||
| 215 | $headerTitle = _t('BillingAddress.DELIVERY_AND_BILLING_ADDRESS', 'Delivery and Billing Address'); |
||
| 216 | $fields->push( |
||
| 217 | HeaderField::create( |
||
| 218 | 'BillingDetails', |
||
| 219 | $headerTitle, |
||
| 220 | 3 |
||
| 221 | ) |
||
| 222 | ->setAttribute('data-title-with-shipping-address', _t('BillingAddress.BILLING_ADDRESS_ONLY', 'Billing Address Only')) |
||
| 223 | ->setAttribute('data-title-with-shipping-address_default', $headerTitle) |
||
| 224 | ); |
||
| 225 | $fields->push(new TextField('Phone', _t('BillingAddress.PHONE', 'Phone'))); |
||
| 226 | $billingFields = new CompositeField(); |
||
| 227 | $hasPreviousAddresses = false; |
||
| 228 | if ($member && Member::currentUser()) { |
||
| 229 | if ($member->exists() && !$member->IsShopAdmin()) { |
||
| 230 | $this->FillWithLastAddressFromMember($member, true); |
||
| 231 | if (EcommerceConfig::get('BillingAddress', 'allow_selection_of_previous_addresses_in_checkout')) { |
||
| 232 | $addresses = $member->previousOrderAddresses($this->baseClassLinkingToOrder(), $this->ID, $onlyLastRecord = false, $keepDoubles = false); |
||
| 233 | //we want MORE than one here not just one. |
||
| 234 | if ($addresses->count() > 1) { |
||
| 235 | $fields->push( |
||
| 236 | SelectOrderAddressField::create( |
||
| 237 | 'SelectBillingAddressField', |
||
| 238 | _t('BillingAddress.SELECTBILLINGADDRESS', 'Select Billing Address'), |
||
| 239 | $addresses |
||
| 240 | ) |
||
| 241 | ); |
||
| 242 | $hasPreviousAddresses = true; |
||
| 243 | } |
||
| 244 | } |
||
| 245 | } |
||
| 246 | } |
||
| 247 | |||
| 248 | $mappingArray = $this->Config()->get('fields_to_google_geocode_conversion'); |
||
| 249 | if (is_array($mappingArray) && count($mappingArray)) { |
||
| 250 | if (!class_exists('GoogleAddressField')) { |
||
| 251 | user_error('You must install the Sunny Side Up google_address_field module OR remove entries from: BillingAddress.fields_to_google_geocode_conversion'); |
||
| 252 | } |
||
| 253 | $billingFields->push( |
||
| 254 | $billingEcommerceGeocodingField = GoogleAddressField::create( |
||
| 255 | 'BillingEcommerceGeocodingField', |
||
| 256 | _t('BillingAddress.FIND_ADDRESS', 'Find address'), |
||
| 257 | Session::get('BillingEcommerceGeocodingFieldValue') |
||
| 258 | ) |
||
| 259 | ); |
||
| 260 | $billingEcommerceGeocodingField->setFieldMap($mappingArray); |
||
| 261 | //$billingFields->push(new HiddenField('Address2', "NOT SET", "NOT SET")); |
||
| 262 | //$billingFields->push(new HiddenField('City', "NOT SET", "NOT SET")); |
||
| 263 | } |
||
| 264 | $billingFields->push(new TextField('Address', _t('BillingAddress.ADDRESS', 'Address'))); |
||
| 265 | $billingFields->push(new TextField('Address2', _t('BillingAddress.ADDRESS2', ''))); |
||
| 266 | $billingFields->push(new TextField('City', _t('BillingAddress.CITY', 'Town'))); |
||
| 267 | $billingFields->push($this->getPostalCodeField('PostalCode')); |
||
| 268 | $billingFields->push($this->getRegionField('RegionID', 'RegionCode')); |
||
| 269 | $billingFields->push($this->getCountryField('Country')); |
||
| 270 | $billingFields->addExtraClass('billingFields'); |
||
| 271 | $billingFields->addExtraClass('orderAddressHolder'); |
||
| 272 | $this->makeSelectedFieldsReadOnly($billingFields); |
||
| 273 | $fields->push($billingFields); |
||
| 274 | $this->extend('augmentEcommerceBillingAddressFields', $fields); |
||
| 275 | |||
| 276 | return $fields; |
||
| 277 | } |
||
| 278 | |||
| 298 |