Skip to content

Commit 95b1684

Browse files
author
Anton Evers
committed
Bring cyclomatic complexity down from 6 to 4
1 parent ff2319e commit 95b1684

1 file changed

Lines changed: 10 additions & 45 deletions

File tree

app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -315,20 +315,17 @@ protected function getMultilineFieldConfig($attributeCode, array $attributeConfi
315315
*/
316316
protected function getDefaultValue($attributeCode)
317317
{
318-
switch ($attributeCode) {
319-
case 'prefix':
320-
return $this->getDefaultPrefix();
321-
case 'firstname':
322-
return $this->getDefaultFirstname();
323-
case 'lastname':
324-
return $this->getDefaultLastname();
325-
case 'suffix':
326-
return $this->getDefaultSuffix();
327-
case 'country_id':
328-
return $this->directoryHelper->getDefaultCountry();
329-
default:
330-
return null;
318+
if ($attributeCode === 'country_id') {
319+
return $this->directoryHelper->getDefaultCountry();
320+
}
321+
if (!$this->getCustomer()) {
322+
return null;
331323
}
324+
if (in_array($attributeCode, ['prefix', 'firstname', 'lastname', 'suffix'])) {
325+
$methodName = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $attributeCode)));
326+
return $this->getCustomer()->{$methodName}();
327+
}
328+
return null;
332329
}
333330

334331
/**
@@ -387,36 +384,4 @@ protected function orderCountryOptions(array $countryOptions)
387384
}
388385
return array_merge($headOptions, $tailOptions);
389386
}
390-
391-
/**
392-
* @return null|string
393-
*/
394-
protected function getDefaultPrefix()
395-
{
396-
return $this->getCustomer() ? $this->getCustomer()->getPrefix() : null;
397-
}
398-
399-
/**
400-
* @return null|string
401-
*/
402-
protected function getDefaultFirstname()
403-
{
404-
return $this->getCustomer() ? $this->getCustomer()->getFirstname() : null;
405-
}
406-
407-
/**
408-
* @return null|string
409-
*/
410-
protected function getDefaultLastname()
411-
{
412-
return $this->getCustomer() ? $this->getCustomer()->getLastname() : null;
413-
}
414-
415-
/**
416-
* @return null|string
417-
*/
418-
protected function getDefaultSuffix()
419-
{
420-
return $this->getCustomer() ? $this->getCustomer()->getSuffix() : null;
421-
}
422387
}

0 commit comments

Comments
 (0)