Skip to content

Commit

Permalink
Bring cyclomatic complexity down from 6 to 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Evers committed Jun 13, 2017
1 parent ff2319e commit 95b1684
Showing 1 changed file with 10 additions and 45 deletions.
55 changes: 10 additions & 45 deletions app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,20 +315,17 @@ protected function getMultilineFieldConfig($attributeCode, array $attributeConfi
*/
protected function getDefaultValue($attributeCode)
{
switch ($attributeCode) {
case 'prefix':
return $this->getDefaultPrefix();
case 'firstname':
return $this->getDefaultFirstname();
case 'lastname':
return $this->getDefaultLastname();
case 'suffix':
return $this->getDefaultSuffix();
case 'country_id':
return $this->directoryHelper->getDefaultCountry();
default:
return null;
if ($attributeCode === 'country_id') {
return $this->directoryHelper->getDefaultCountry();
}
if (!$this->getCustomer()) {
return null;
}
if (in_array($attributeCode, ['prefix', 'firstname', 'lastname', 'suffix'])) {
$methodName = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $attributeCode)));
return $this->getCustomer()->{$methodName}();
}
return null;
}

/**
Expand Down Expand Up @@ -387,36 +384,4 @@ protected function orderCountryOptions(array $countryOptions)
}
return array_merge($headOptions, $tailOptions);
}

/**
* @return null|string
*/
protected function getDefaultPrefix()
{
return $this->getCustomer() ? $this->getCustomer()->getPrefix() : null;
}

/**
* @return null|string
*/
protected function getDefaultFirstname()
{
return $this->getCustomer() ? $this->getCustomer()->getFirstname() : null;
}

/**
* @return null|string
*/
protected function getDefaultLastname()
{
return $this->getCustomer() ? $this->getCustomer()->getLastname() : null;
}

/**
* @return null|string
*/
protected function getDefaultSuffix()
{
return $this->getCustomer() ? $this->getCustomer()->getSuffix() : null;
}
}

0 comments on commit 95b1684

Please sign in to comment.