| Conditions | 5 | 
| Paths | 8 | 
| Total Lines | 59 | 
| Code Lines | 41 | 
| 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 declare(strict_types=1);  | 
            ||
| 62 | #[Route(path: '/store-api/account/address', name: 'store-api.account.address.create', methods: ['POST'], defaults: ['addressId' => null, '_loginRequired' => true, '_loginRequiredAllowGuest' => true])]  | 
            ||
| 63 |     #[Route(path: '/store-api/account/address/{addressId}', name: 'store-api.account.address.update', methods: ['PATCH'], defaults: ['_loginRequired' => true, '_loginRequiredAllowGuest' => true])] | 
            ||
| 64 | public function upsert(?string $addressId, RequestDataBag $data, SalesChannelContext $context, CustomerEntity $customer): UpsertAddressRouteResponse  | 
            ||
| 65 |     { | 
            ||
| 66 |         if (!$addressId) { | 
            ||
| 67 | $isCreate = true;  | 
            ||
| 68 | $addressId = Uuid::randomHex();  | 
            ||
| 69 |         } else { | 
            ||
| 70 | $this->validateAddress($addressId, $context, $customer);  | 
            ||
| 71 | $isCreate = false;  | 
            ||
| 72 | }  | 
            ||
| 73 | |||
| 74 |         if (!$data->get('salutationId')) { | 
            ||
| 75 |             $data->set('salutationId', $this->getDefaultSalutationId($context)); | 
            ||
| 76 | }  | 
            ||
| 77 | |||
| 78 |         $accountType = $data->get('accountType', CustomerEntity::ACCOUNT_TYPE_PRIVATE); | 
            ||
| 79 | $definition = $this->getValidationDefinition($data, $accountType, $isCreate, $context);  | 
            ||
| 80 | $this->validator->validate(array_merge(['id' => $addressId], $data->all()), $definition);  | 
            ||
| 81 | |||
| 82 | $addressData = [  | 
            ||
| 83 |             'salutationId' => $data->get('salutationId'), | 
            ||
| 84 |             'firstName' => $data->get('firstName'), | 
            ||
| 85 |             'lastName' => $data->get('lastName'), | 
            ||
| 86 |             'street' => $data->get('street'), | 
            ||
| 87 |             'city' => $data->get('city'), | 
            ||
| 88 |             'zipcode' => $data->get('zipcode'), | 
            ||
| 89 |             'countryId' => $data->get('countryId'), | 
            ||
| 90 |             'countryStateId' => $data->get('countryStateId') ?: null, | 
            ||
| 91 |             'company' => $data->get('company'), | 
            ||
| 92 |             'department' => $data->get('department'), | 
            ||
| 93 |             'title' => $data->get('title'), | 
            ||
| 94 |             'phoneNumber' => $data->get('phoneNumber'), | 
            ||
| 95 |             'additionalAddressLine1' => $data->get('additionalAddressLine1'), | 
            ||
| 96 |             'additionalAddressLine2' => $data->get('additionalAddressLine2'), | 
            ||
| 97 | ];  | 
            ||
| 98 | |||
| 99 |         if ($data->get('customFields') instanceof RequestDataBag) { | 
            ||
| 100 | $addressData['customFields'] = $this->storeApiCustomFieldMapper->map(  | 
            ||
| 101 | CustomerAddressDefinition::ENTITY_NAME,  | 
            ||
| 102 |                 $data->get('customFields') | 
            ||
| 103 | );  | 
            ||
| 104 | }  | 
            ||
| 105 | |||
| 106 | $mappingEvent = new DataMappingEvent($data, $addressData, $context->getContext());  | 
            ||
| 107 | $this->eventDispatcher->dispatch($mappingEvent, CustomerEvents::MAPPING_ADDRESS_CREATE);  | 
            ||
| 108 | |||
| 109 | $addressData = $mappingEvent->getOutput();  | 
            ||
| 110 | $addressData['id'] = $addressId;  | 
            ||
| 111 | $addressData['customerId'] = $customer->getId();  | 
            ||
| 112 | |||
| 113 | $this->addressRepository->upsert([$addressData], $context->getContext());  | 
            ||
| 114 | |||
| 115 | $criteria = new Criteria([$addressId]);  | 
            ||
| 116 | |||
| 117 | /** @var CustomerAddressEntity $address */  | 
            ||
| 118 | $address = $this->addressRepository->search($criteria, $context->getContext())->first();  | 
            ||
| 119 | |||
| 120 | return new UpsertAddressRouteResponse($address);  | 
            ||
| 121 | }  | 
            ||
| 157 |