Skip to content

Commit 71d242c

Browse files
committed
GraphQL-57: Fix cyclomatic complexity in addressDataProvider
1 parent bfd4fc1 commit 71d242c

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

app/code/Magento/CustomerGraphQl/Model/Resolver/Address/AddressDataProvider.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ public function __construct(
5959
$this->customerFactory = $customerFactory;
6060
}
6161

62+
/**
63+
* Curate shipping and billing default options
64+
*
65+
* @param array $address
66+
* @param AddressInterface $addressObject
67+
* @return null
68+
*/
69+
private function curateAddressDefaultValues(array $address, AddressInterface $addressObject) : array
70+
{
71+
$customerModel = $this->customerFactory->create();
72+
$this->customerResourceModel->load($customerModel, $addressObject->getCustomerId());
73+
$address[CustomerInterface::DEFAULT_BILLING] =
74+
($addressObject->getId() == $customerModel->getDefaultBillingAddress()->getId()) ? true : false;
75+
$address[CustomerInterface::DEFAULT_SHIPPING] =
76+
($addressObject->getId() == $customerModel->getDefaultShippingAddress()->getId()) ? true : false;
77+
return $address;
78+
}
79+
6280
/**
6381
* Transform single customer address data from object to in array format
6482
*
@@ -72,12 +90,7 @@ public function processCustomerAddress(AddressInterface $addressObject) : array
7290
AddressRepositoryInterface::class,
7391
'getById'
7492
);
75-
$customerModel = $this->customerFactory->create();
76-
$this->customerResourceModel->load($customerModel, $addressObject->getCustomerId());
77-
$address[CustomerInterface::DEFAULT_BILLING] =
78-
($addressObject->getId() == $customerModel->getDefaultBillingAddress()->getId()) ? true : false;
79-
$address[CustomerInterface::DEFAULT_SHIPPING] =
80-
($addressObject->getId() == $customerModel->getDefaultShippingAddress()->getId()) ? true : false;
93+
$address = $this->curateAddressDefaultValues($address, $addressObject);
8194

8295
if (isset($address[CustomAttributesDataInterface::EXTENSION_ATTRIBUTES_KEY])) {
8396
$address = array_merge($address, $address[CustomAttributesDataInterface::EXTENSION_ATTRIBUTES_KEY]);

0 commit comments

Comments
 (0)