Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/MyParcelComApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/Shipments/ServiceMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand Down