| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
use MyParcelNL\Sdk\src\Adapter\DeliveryOptions\AbstractDeliveryOptionsAdapter; |
| 6 |
use MyParcelNL\Sdk\src\Adapter\DeliveryOptions\AbstractPickupLocationAdapter; |
| 7 |
|
| 8 |
class WCPN_PickupLocationFromOrderAdapter extends AbstractPickupLocationAdapter |
| 9 |
{ |
| 10 |
/** |
| 11 |
* @param \MyParcelNL\Sdk\src\Adapter\DeliveryOptions\AbstractDeliveryOptionsAdapter|null $originAdapter |
| 12 |
* @param array $inputData |
| 13 |
*/ |
| 14 |
public function __construct(?AbstractDeliveryOptionsAdapter $originAdapter, array $inputData) |
| 15 |
{ |
| 16 |
$pickupLocationAdapter = $originAdapter ? $originAdapter->getPickupLocation() : null; |
| 17 |
$inputData = $inputData['pickup_location']; |
| 18 |
|
| 19 |
$this->cc = $this->countryFromOptions($inputData, $pickupLocationAdapter); |
| 20 |
$this->city = $this->cityFromOptions($inputData, $pickupLocationAdapter); |
| 21 |
$this->location_code = $this->locationCodeFromOptions($inputData, $pickupLocationAdapter); |
| 22 |
$this->location_name = $this->locationNameFromOptions($inputData, $pickupLocationAdapter); |
| 23 |
$this->number = $this->numberFromOptions($inputData, $pickupLocationAdapter); |
| 24 |
$this->postal_code = $this->postalCodeFromOptions($inputData, $pickupLocationAdapter); |
| 25 |
$this->retail_network_id = $this->retailNetworkIdFromOptions($inputData, $pickupLocationAdapter); |
| 26 |
$this->street = $this->streetFromOptions($inputData, $pickupLocationAdapter); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* @param array $inputData |
| 31 |
* @param \MyParcelNL\Sdk\src\Adapter\DeliveryOptions\AbstractPickupLocationAdapter|null $adapter |
| 32 |
* |
| 33 |
* @return string |
| 34 |
*/ |
| 35 |
private function countryFromOptions(array $inputData, ?AbstractPickupLocationAdapter $adapter): string |
| 36 |
{ |
| 37 |
if (array_key_exists('cc', $inputData)) { |
| 38 |
return (string) $inputData['cc']; |
| 39 |
} |
| 40 |
|
| 41 |
return $adapter->getCountry(); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* @param array $inputData |
| 46 |
* @param \MyParcelNL\Sdk\src\Adapter\DeliveryOptions\AbstractPickupLocationAdapter|null $adapter |
| 47 |
* |
| 48 |
* @return string |
| 49 |
*/ |
| 50 |
private function cityFromOptions(array $inputData, ?AbstractPickupLocationAdapter $adapter): string |
| 51 |
{ |
| 52 |
if (array_key_exists('city', $inputData)) { |
| 53 |
return (string) $inputData['city']; |
| 54 |
} |
| 55 |
|
| 56 |
return $adapter->getCity(); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* @param array $inputData |
| 61 |
* @param \MyParcelNL\Sdk\src\Adapter\DeliveryOptions\AbstractPickupLocationAdapter|null $adapter |
| 62 |
* |
| 63 |
* @return string |
| 64 |
*/ |
| 65 |
private function locationCodeFromOptions(array $inputData, ?AbstractPickupLocationAdapter $adapter): string |
| 66 |
{ |
| 67 |
if (array_key_exists('location_code', $inputData)) { |
| 68 |
return (string) $inputData['location_code']; |
| 69 |
} |
| 70 |
|
| 71 |
return $adapter->getLocationCode(); |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* @param array $inputData |
| 76 |
* @param \MyParcelNL\Sdk\src\Adapter\DeliveryOptions\AbstractPickupLocationAdapter|null $adapter |
| 77 |
* |
| 78 |
* @return string |
| 79 |
*/ |
| 80 |
private function locationNameFromOptions(array $inputData, ?AbstractPickupLocationAdapter $adapter): string |
| 81 |
{ |
| 82 |
if (array_key_exists('location_name', $inputData)) { |
| 83 |
return (string) $inputData['location_name']; |
| 84 |
} |
| 85 |
|
| 86 |
return $adapter->getLocationName(); |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* @param array $inputData |
| 91 |
* @param \MyParcelNL\Sdk\src\Adapter\DeliveryOptions\AbstractPickupLocationAdapter|null $adapter |
| 92 |
* |
| 93 |
* @return string |
| 94 |
*/ |
| 95 |
private function numberFromOptions(array $inputData, ?AbstractPickupLocationAdapter $adapter): string |
| 96 |
{ |
| 97 |
if (array_key_exists('number', $inputData)) { |
| 98 |
return (string) $inputData['number']; |
| 99 |
} |
| 100 |
|
| 101 |
return $adapter->getNumber(); |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* @param array $inputData |
| 106 |
* @param \MyParcelNL\Sdk\src\Adapter\DeliveryOptions\AbstractPickupLocationAdapter|null $adapter |
| 107 |
* |
| 108 |
* @return string |
| 109 |
*/ |
| 110 |
private function postalCodeFromOptions(array $inputData, ?AbstractPickupLocationAdapter $adapter): string |
| 111 |
{ |
| 112 |
if (array_key_exists('postal_code', $inputData)) { |
| 113 |
return (string) $inputData['postal_code']; |
| 114 |
} |
| 115 |
|
| 116 |
return $adapter->getPostalCode(); |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* @param array $inputData |
| 121 |
* @param \MyParcelNL\Sdk\src\Adapter\DeliveryOptions\AbstractPickupLocationAdapter|null $adapter |
| 122 |
* |
| 123 |
* @return string |
| 124 |
*/ |
| 125 |
private function retailNetworkIdFromOptions(array $inputData, ?AbstractPickupLocationAdapter $adapter): string |
| 126 |
{ |
| 127 |
if (array_key_exists('retail_network_id', $inputData)) { |
| 128 |
return (string) $inputData['retail_network_id']; |
| 129 |
} |
| 130 |
|
| 131 |
return $adapter->getRetailNetworkId(); |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* @param array $inputData |
| 136 |
* @param \MyParcelNL\Sdk\src\Adapter\DeliveryOptions\AbstractPickupLocationAdapter|null $adapter |
| 137 |
* |
| 138 |
* @return string |
| 139 |
*/ |
| 140 |
private function streetFromOptions(array $inputData, ?AbstractPickupLocationAdapter $adapter): string |
| 141 |
{ |
| 142 |
if (array_key_exists('street', $inputData)) { |
| 143 |
return (string) $inputData['street']; |
| 144 |
} |
| 145 |
|
| 146 |
return $adapter->getStreet(); |
| 147 |
} |
| 148 |
} |
| 149 |
|