diff --git a/src/MyParcelComApi.php b/src/MyParcelComApi.php index ce2f17dc..09887122 100644 --- a/src/MyParcelComApi.php +++ b/src/MyParcelComApi.php @@ -36,7 +36,6 @@ use MyParcelCom\ApiSdk\Resources\Service; use MyParcelCom\ApiSdk\Resources\ServiceRate; use MyParcelCom\ApiSdk\Resources\Shipment; -use MyParcelCom\ApiSdk\Shipments\ServiceMatcher; use MyParcelCom\ApiSdk\Utils\UrlBuilder; use MyParcelCom\ApiSdk\Validators\CollectionValidator; use MyParcelCom\ApiSdk\Validators\ManifestValidator; @@ -266,17 +265,25 @@ public function getServices( $services = $this->getResourcesArray($url->getUrl(), $ttl); - $matcher = new ServiceMatcher(); $services = array_values( array_filter( $services, - fn (ServiceInterface $service) => $matcher->matchesDeliveryMethod($shipment, $service), + fn (ServiceInterface $service) => $this->matchesDeliveryMethod($shipment, $service), ), ); return new ArrayCollection($services); } + protected function matchesDeliveryMethod(ShipmentInterface $shipment, ServiceInterface $service): bool + { + $deliveryMethod = $shipment->getPickupLocationCode() + ? ServiceInterface::DELIVERY_METHOD_PICKUP + : ServiceInterface::DELIVERY_METHOD_DELIVERY; + + return $service->getDeliveryMethod() === $deliveryMethod; + } + public function getServicesForCarrier( CarrierInterface $carrier, int $ttl = self::TTL_10MIN, diff --git a/src/Shipments/ServiceMatcher.php b/src/Shipments/ServiceMatcher.php index 8f470a82..7a1fe9a7 100644 --- a/src/Shipments/ServiceMatcher.php +++ b/src/Shipments/ServiceMatcher.php @@ -10,6 +10,9 @@ use MyParcelCom\ApiSdk\Resources\Interfaces\ServiceOptionInterface; use MyParcelCom\ApiSdk\Resources\Interfaces\ShipmentInterface; +/** + * @deprecated This class is deprecated and will be removed in the next major release. + */ class ServiceMatcher { /**