diff --git a/src/Client/Client.php b/src/Client/Client.php index 5e6db78..8cc5207 100644 --- a/src/Client/Client.php +++ b/src/Client/Client.php @@ -4,7 +4,7 @@ namespace Inspirum\Balikobot\Client; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; use Inspirum\Balikobot\Client\Request\Method; use Inspirum\Balikobot\Client\Request\Version; @@ -21,10 +21,10 @@ interface Client */ public function call( Version $version, - ?CarrierType $carrier, + ?Carrier $carrier, Method $request, array $data = [], - string $path = '', + ?string $path = null, bool $shouldHaveStatus = true, bool $gzip = false, ): array; diff --git a/src/Client/DefaultClient.php b/src/Client/DefaultClient.php index ca84eb0..6571e62 100644 --- a/src/Client/DefaultClient.php +++ b/src/Client/DefaultClient.php @@ -5,7 +5,7 @@ namespace Inspirum\Balikobot\Client; use GuzzleHttp\Psr7\InflateStream; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; use Inspirum\Balikobot\Client\Request\Method; use Inspirum\Balikobot\Client\Request\Version; use Inspirum\Balikobot\Client\Response\Validator; @@ -30,10 +30,10 @@ public function __construct( /** @inheritDoc */ public function call( Version $version, - ?CarrierType $carrier, + ?Carrier $carrier, Method $request, array $data = [], - string $path = '', + ?string $path = null, bool $shouldHaveStatus = true, bool $gzip = false, ): array { @@ -50,9 +50,9 @@ public function call( return $parsedContent; } - private function resolveUrl(string $version, ?string $carrier, string $request, string $path, bool $gzip): string + private function resolveUrl(string $version, ?string $carrier, string $request, ?string $path, bool $gzip): string { - $url = sprintf('%s/%s/%s', $carrier, $request, $path); + $url = sprintf('%s/%s/%s', $carrier, $request, $path ?? ''); $url = trim(str_replace('//', '/', $url), '/'); if ($gzip) { diff --git a/src/Client/Request/CarrierType.php b/src/Client/Request/Carrier.php similarity index 84% rename from src/Client/Request/CarrierType.php rename to src/Client/Request/Carrier.php index 9af9e1c..c5fabe0 100644 --- a/src/Client/Request/CarrierType.php +++ b/src/Client/Request/Carrier.php @@ -4,7 +4,7 @@ namespace Inspirum\Balikobot\Client\Request; -interface CarrierType +interface Carrier { public function getValue(): string; } diff --git a/src/Client/Request/ServiceType.php b/src/Client/Request/Service.php similarity index 77% rename from src/Client/Request/ServiceType.php rename to src/Client/Request/Service.php index 4cbe881..969593f 100644 --- a/src/Client/Request/ServiceType.php +++ b/src/Client/Request/Service.php @@ -6,7 +6,7 @@ use Stringable; -interface ServiceType extends Stringable +interface Service extends Stringable { public function getValue(): string; } diff --git a/src/Definitions/Carrier.php b/src/Definitions/CarrierType.php similarity index 83% rename from src/Definitions/Carrier.php rename to src/Definitions/CarrierType.php index 6ea034a..285d32c 100644 --- a/src/Definitions/Carrier.php +++ b/src/Definitions/CarrierType.php @@ -4,10 +4,10 @@ namespace Inspirum\Balikobot\Definitions; -use Inspirum\Balikobot\Client\Request\CarrierType; -use Inspirum\Balikobot\Client\Request\ServiceType; +use Inspirum\Balikobot\Client\Request\Carrier; +use Inspirum\Balikobot\Client\Request\Service; -enum Carrier: string implements CarrierType +enum CarrierType: string implements Carrier { case CP = 'cp'; case DPD = 'dpd'; @@ -48,13 +48,13 @@ public function getValue(): string return $this->value; } - public static function hasBranchCountryFilterSupport(CarrierType $carrier, ?ServiceType $service): bool + public static function hasBranchCountryFilterSupport(Carrier $carrier, ?Service $service): bool { // TODO: return false; } - public static function hasFullBranchesSupport(CarrierType $carrier, ?ServiceType $service): bool + public static function hasFullBranchesSupport(Carrier $carrier, ?Service $service): bool { // TODO: return false; diff --git a/src/Definitions/Request.php b/src/Definitions/Request.php index b40b312..e059d3e 100644 --- a/src/Definitions/Request.php +++ b/src/Definitions/Request.php @@ -8,39 +8,39 @@ enum Request: string implements Method { - case TRACK = 'track'; - case TRACK_STATUS = 'trackstatus'; - case BRANCHES = 'branches'; - case FULL_BRANCHES = 'fullbranches'; - case BRANCH_LOCATOR = 'branchlocator'; - case ADD = 'add'; - case DROP = 'drop'; - case OVERVIEW = 'overview'; - case LABELS = 'labels'; - case PACKAGE = 'package'; - case ORDER = 'order'; - case ORDER_VIEW = 'orderview'; - case ORDER_PICKUP = 'orderpickup'; - case CHECK = 'check'; - case PROOF_OF_DELIVERY = 'pod'; - case TRANSPORT_COSTS = 'transportcosts'; - case ADD_SERVICE_OPTIONS = 'addserviceoptions'; - case ADD_ATTRIBUTES = 'addattributes'; - case B2A = 'b2a'; - case B2A_SERVICES = 'b2a/services'; - case INFO_WHO_AM_I = 'info/whoami'; - case INFO_CARRIERS = 'info/carriers'; - case CHANGELOG = 'changelog'; - case SERVICES = 'services'; - case ACTIVATED_SERVICES = 'activatedservices'; - case GET_COUNTRIES_DATA = 'getCountriesData'; - case MANIPULATION_UNITS = 'manipulationunits'; + case TRACK = 'track'; + case TRACK_STATUS = 'trackstatus'; + case BRANCHES = 'branches'; + case FULL_BRANCHES = 'fullbranches'; + case BRANCH_LOCATOR = 'branchlocator'; + case ADD = 'add'; + case DROP = 'drop'; + case OVERVIEW = 'overview'; + case LABELS = 'labels'; + case PACKAGE = 'package'; + case ORDER = 'order'; + case ORDER_VIEW = 'orderview'; + case ORDER_PICKUP = 'orderpickup'; + case CHECK = 'check'; + case PROOF_OF_DELIVERY = 'pod'; + case TRANSPORT_COSTS = 'transportcosts'; + case ADD_SERVICE_OPTIONS = 'addserviceoptions'; + case ADD_ATTRIBUTES = 'addattributes'; + case B2A = 'b2a'; + case B2A_SERVICES = 'b2a/services'; + case INFO_WHO_AM_I = 'info/whoami'; + case INFO_CARRIERS = 'info/carriers'; + case CHANGELOG = 'changelog'; + case SERVICES = 'services'; + case ACTIVATED_SERVICES = 'activatedservices'; + case GET_COUNTRIES_DATA = 'getCountriesData'; + case MANIPULATION_UNITS = 'manipulationunits'; case ACTIVATED_MANIPULATION_UNITS = 'activatedmanipulationunits'; - case CASH_ON_DELIVERY_COUNTRIES = 'cod4services'; - case COUNTRIES = 'countries4service'; - case ZIP_CODES = 'zipcodes'; - case ADR_UNITS = 'adrunits'; - case FULL_ADR_UNITS = 'fulladrunits'; + case CASH_ON_DELIVERY_COUNTRIES = 'cod4services'; + case COUNTRIES = 'countries4service'; + case ZIP_CODES = 'zipcodes'; + case ADR_UNITS = 'adrunits'; + case FULL_ADR_UNITS = 'fulladrunits'; public function getValue(): string { diff --git a/src/Definitions/ServiceType.php b/src/Definitions/ServiceType.php index 585303b..eb00500 100644 --- a/src/Definitions/ServiceType.php +++ b/src/Definitions/ServiceType.php @@ -3146,39 +3146,39 @@ public static function magyarposta(): array public static function all(): array { return [ - Carrier::CP->value => self::cp(), - Carrier::DPD->value => self::dpd(), - Carrier::DHL->value => self::dhl(), - Carrier::GEIS->value => self::geis(), - Carrier::GLS->value => self::gls(), - Carrier::INTIME->value => self::intime(), - Carrier::PBH->value => self::pbh(), - Carrier::PPL->value => self::ppl(), - Carrier::SP->value => self::sp(), - Carrier::SPS->value => self::sps(), - Carrier::TOPTRANS->value => self::topTrans(), - Carrier::ULOZENKA->value => self::ulozenka(), - Carrier::UPS->value => self::ups(), - Carrier::ZASILKOVNA->value => self::zasilkovna(), - Carrier::TNT->value => self::tnt(), - Carrier::GW->value => self::gw(), - Carrier::GWCZ->value => self::gwcz(), - Carrier::MESSENGER->value => self::messenger(), - Carrier::DHLDE->value => self::dhlde(), - Carrier::FEDEX->value => self::fedex(), - Carrier::FOFR->value => self::fofr(), - Carrier::DACHSER->value => self::dachser(), - Carrier::DHLPARCEL->value => self::dhlparcel(), - Carrier::RABEN->value => self::raben(), - Carrier::SPRING->value => self::spring(), - Carrier::DSV->value => self::dsv(), - Carrier::DHLFREIGHTEC->value => self::dhlfreightec(), - Carrier::KURIER->value => self::kurier(), - Carrier::DBSCHENKER->value => self::dbschenker(), - Carrier::AIRWAY->value => self::airway(), - Carrier::JAPO->value => self::japo(), - Carrier::LIFTAGO->value => self::liftago(), - Carrier::MAGYARPOSTA->value => self::magyarposta(), + CarrierType::CP->value => self::cp(), + CarrierType::DPD->value => self::dpd(), + CarrierType::DHL->value => self::dhl(), + CarrierType::GEIS->value => self::geis(), + CarrierType::GLS->value => self::gls(), + CarrierType::INTIME->value => self::intime(), + CarrierType::PBH->value => self::pbh(), + CarrierType::PPL->value => self::ppl(), + CarrierType::SP->value => self::sp(), + CarrierType::SPS->value => self::sps(), + CarrierType::TOPTRANS->value => self::topTrans(), + CarrierType::ULOZENKA->value => self::ulozenka(), + CarrierType::UPS->value => self::ups(), + CarrierType::ZASILKOVNA->value => self::zasilkovna(), + CarrierType::TNT->value => self::tnt(), + CarrierType::GW->value => self::gw(), + CarrierType::GWCZ->value => self::gwcz(), + CarrierType::MESSENGER->value => self::messenger(), + CarrierType::DHLDE->value => self::dhlde(), + CarrierType::FEDEX->value => self::fedex(), + CarrierType::FOFR->value => self::fofr(), + CarrierType::DACHSER->value => self::dachser(), + CarrierType::DHLPARCEL->value => self::dhlparcel(), + CarrierType::RABEN->value => self::raben(), + CarrierType::SPRING->value => self::spring(), + CarrierType::DSV->value => self::dsv(), + CarrierType::DHLFREIGHTEC->value => self::dhlfreightec(), + CarrierType::KURIER->value => self::kurier(), + CarrierType::DBSCHENKER->value => self::dbschenker(), + CarrierType::AIRWAY->value => self::airway(), + CarrierType::JAPO->value => self::japo(), + CarrierType::LIFTAGO->value => self::liftago(), + CarrierType::MAGYARPOSTA->value => self::magyarposta(), ]; } } diff --git a/src/Definitions/Version.php b/src/Definitions/VersionType.php similarity index 81% rename from src/Definitions/Version.php rename to src/Definitions/VersionType.php index b368f25..d6778a7 100644 --- a/src/Definitions/Version.php +++ b/src/Definitions/VersionType.php @@ -4,7 +4,9 @@ namespace Inspirum\Balikobot\Definitions; -enum Version: string implements \Inspirum\Balikobot\Client\Request\Version +use Inspirum\Balikobot\Client\Request\Version; + +enum VersionType: string implements Version { case V1V1 = 'https://api.balikobot.cz'; case V1V2 = 'https://api.balikobot.cz/v2'; diff --git a/src/Model/AdrUnit/AdrUnit.php b/src/Model/AdrUnit/AdrUnit.php index 606c584..0e6a7b8 100644 --- a/src/Model/AdrUnit/AdrUnit.php +++ b/src/Model/AdrUnit/AdrUnit.php @@ -5,7 +5,7 @@ namespace Inspirum\Balikobot\Model\AdrUnit; use Inspirum\Arrayable\BaseModel; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; /** * @extends \Inspirum\Arrayable\BaseModel @@ -13,7 +13,7 @@ class AdrUnit extends BaseModel { public function __construct( - public readonly CarrierType $carrier, + public readonly Carrier $carrier, public readonly string $id, public readonly string $code, public readonly string $name, diff --git a/src/Model/AdrUnit/AdrUnitCollection.php b/src/Model/AdrUnit/AdrUnitCollection.php index d8243d0..8371d55 100644 --- a/src/Model/AdrUnit/AdrUnitCollection.php +++ b/src/Model/AdrUnit/AdrUnitCollection.php @@ -5,10 +5,25 @@ namespace Inspirum\Balikobot\Model\AdrUnit; use Inspirum\Arrayable\BaseCollection; +use Inspirum\Balikobot\Client\Request\Carrier; /** * @extends \Inspirum\Arrayable\BaseCollection */ final class AdrUnitCollection extends BaseCollection { + /** + * @param array $items + */ + public function __construct( + private Carrier $carrier, + array $items = [], + ) { + parent::__construct($items); + } + + public function getCarrier(): Carrier + { + return $this->carrier; + } } diff --git a/src/Model/AdrUnit/AdrUnitFactory.php b/src/Model/AdrUnit/AdrUnitFactory.php index d3d5c79..f6e72ba 100644 --- a/src/Model/AdrUnit/AdrUnitFactory.php +++ b/src/Model/AdrUnit/AdrUnitFactory.php @@ -4,17 +4,17 @@ namespace Inspirum\Balikobot\Model\AdrUnit; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; interface AdrUnitFactory { /** * @param array $data */ - public function create(CarrierType $carrier, array $data): AdrUnit; + public function create(Carrier $carrier, array $data): AdrUnit; /** * @param array $data */ - public function createCollection(CarrierType $carrier, array $data): AdrUnitCollection; + public function createCollection(Carrier $carrier, array $data): AdrUnitCollection; } diff --git a/src/Model/AdrUnit/DefaultAdrUnitFactory.php b/src/Model/AdrUnit/DefaultAdrUnitFactory.php index 5e2e8bd..8cfadb3 100644 --- a/src/Model/AdrUnit/DefaultAdrUnitFactory.php +++ b/src/Model/AdrUnit/DefaultAdrUnitFactory.php @@ -4,13 +4,13 @@ namespace Inspirum\Balikobot\Model\AdrUnit; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; use function array_map; final class DefaultAdrUnitFactory implements AdrUnitFactory { /** @inheritDoc */ - public function create(CarrierType $carrier, array $data): AdrUnit + public function create(Carrier $carrier, array $data): AdrUnit { return new AdrUnit( $carrier, @@ -25,9 +25,10 @@ public function create(CarrierType $carrier, array $data): AdrUnit } /** @inheritDoc */ - public function createCollection(CarrierType $carrier, array $data): AdrUnitCollection + public function createCollection(Carrier $carrier, array $data): AdrUnitCollection { return new AdrUnitCollection( + $carrier, array_map(fn(array $unit): AdrUnit => $this->create($carrier, $unit), $data['units'] ?? []), ); } diff --git a/src/Model/Attribute/Attribute.php b/src/Model/Attribute/Attribute.php index 960c9f8..b5bc3a5 100644 --- a/src/Model/Attribute/Attribute.php +++ b/src/Model/Attribute/Attribute.php @@ -14,7 +14,7 @@ final class Attribute extends BaseModel public function __construct( public readonly string $name, public readonly string $dataType, - public readonly string $maxLength, + public readonly ?string $maxLength, ) { } diff --git a/src/Model/Attribute/AttributeCollection.php b/src/Model/Attribute/AttributeCollection.php index 4ddd0cf..51bd6f7 100644 --- a/src/Model/Attribute/AttributeCollection.php +++ b/src/Model/Attribute/AttributeCollection.php @@ -5,10 +5,25 @@ namespace Inspirum\Balikobot\Model\Attribute; use Inspirum\Arrayable\BaseCollection; +use Inspirum\Balikobot\Client\Request\Carrier; /** * @extends \Inspirum\Arrayable\BaseCollection */ final class AttributeCollection extends BaseCollection { + /** + * @param array $items + */ + public function __construct( + private Carrier $carrier, + array $items = [], + ) { + parent::__construct($items); + } + + public function getCarrier(): Carrier + { + return $this->carrier; + } } diff --git a/src/Model/Attribute/AttributeFactory.php b/src/Model/Attribute/AttributeFactory.php index e86405b..d660b7d 100644 --- a/src/Model/Attribute/AttributeFactory.php +++ b/src/Model/Attribute/AttributeFactory.php @@ -4,6 +4,8 @@ namespace Inspirum\Balikobot\Model\Attribute; +use Inspirum\Balikobot\Client\Request\Carrier; + interface AttributeFactory { /** @@ -14,5 +16,5 @@ public function create(array $data): Attribute; /** * @param array $data */ - public function createCollection(array $data): AttributeCollection; + public function createCollection(Carrier $carrier, array $data): AttributeCollection; } diff --git a/src/Model/Attribute/DefaultAttributeFactory.php b/src/Model/Attribute/DefaultAttributeFactory.php index f7f649b..ad66708 100644 --- a/src/Model/Attribute/DefaultAttributeFactory.php +++ b/src/Model/Attribute/DefaultAttributeFactory.php @@ -4,6 +4,7 @@ namespace Inspirum\Balikobot\Model\Attribute; +use Inspirum\Balikobot\Client\Request\Carrier; use function array_map; final class DefaultAttributeFactory implements AttributeFactory @@ -19,10 +20,11 @@ public function create(array $data): Attribute } /** @inheritDoc */ - public function createCollection(array $data): AttributeCollection + public function createCollection(Carrier $carrier, array $data): AttributeCollection { return new AttributeCollection( - array_map(fn(array $attribute): Attribute => $this->create($attribute), $data['units'] ?? []), + $carrier, + array_map(fn(array $attribute): Attribute => $this->create($attribute), $data['attributes'] ?? []), ); } } diff --git a/src/Model/BasePerCarrierCollection.php b/src/Model/BasePerCarrierCollection.php index 2838a61..6a896c7 100644 --- a/src/Model/BasePerCarrierCollection.php +++ b/src/Model/BasePerCarrierCollection.php @@ -5,7 +5,7 @@ namespace Inspirum\Balikobot\Model; use Inspirum\Arrayable\BaseCollection; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; use InvalidArgumentException; use RuntimeException; use function array_map; @@ -25,7 +25,7 @@ abstract class BasePerCarrierCollection extends BaseCollection implements PerCar * @param array $items */ public function __construct( - private ?CarrierType $carrier = null, + private ?Carrier $carrier = null, array $items = [], ) { parent::__construct([]); @@ -38,7 +38,7 @@ public function __construct( /** * @throws \RuntimeException */ - public function getCarrier(): CarrierType + public function getCarrier(): Carrier { return $this->carrier ?? throw new RuntimeException('Collection is empty'); } diff --git a/src/Model/Branch/Branch.php b/src/Model/Branch/Branch.php index f146650..3961431 100644 --- a/src/Model/Branch/Branch.php +++ b/src/Model/Branch/Branch.php @@ -5,8 +5,8 @@ namespace Inspirum\Balikobot\Model\Branch; use Inspirum\Arrayable\BaseModel; -use Inspirum\Balikobot\Client\Request\CarrierType; -use Inspirum\Balikobot\Client\Request\ServiceType; +use Inspirum\Balikobot\Client\Request\Carrier; +use Inspirum\Balikobot\Client\Request\Service; /** * @extends \Inspirum\Arrayable\BaseModel @@ -14,8 +14,8 @@ class Branch extends BaseModel { public function __construct( - public readonly CarrierType $carrier, - public readonly ?ServiceType $service, + public readonly Carrier $carrier, + public readonly ?Service $service, public readonly string $branchId, public readonly ?string $id, public readonly ?string $uid, diff --git a/src/Model/Branch/BranchFactory.php b/src/Model/Branch/BranchFactory.php index 9aa3807..aa98137 100644 --- a/src/Model/Branch/BranchFactory.php +++ b/src/Model/Branch/BranchFactory.php @@ -4,8 +4,8 @@ namespace Inspirum\Balikobot\Model\Branch; -use Inspirum\Balikobot\Client\Request\CarrierType; -use Inspirum\Balikobot\Client\Request\ServiceType; +use Inspirum\Balikobot\Client\Request\Carrier; +use Inspirum\Balikobot\Client\Request\Service; interface BranchFactory { @@ -14,5 +14,5 @@ interface BranchFactory * * @param array $data */ - public function createFromData(CarrierType $carrier, ?ServiceType $service, array $data): Branch; + public function createFromData(Carrier $carrier, ?Service $service, array $data): Branch; } diff --git a/src/Model/Branch/DefaultBranchFactory.php b/src/Model/Branch/DefaultBranchFactory.php index bd18ff9..5660aee 100644 --- a/src/Model/Branch/DefaultBranchFactory.php +++ b/src/Model/Branch/DefaultBranchFactory.php @@ -4,8 +4,9 @@ namespace Inspirum\Balikobot\Model\Branch; -use Inspirum\Balikobot\Client\Request\CarrierType; -use Inspirum\Balikobot\Definitions\Carrier; +use Inspirum\Balikobot\Client\Request\Carrier; +use Inspirum\Balikobot\Client\Request\Service; +use Inspirum\Balikobot\Definitions\CarrierType; use Inspirum\Balikobot\Definitions\ServiceType; use function sprintf; use function str_replace; @@ -14,9 +15,9 @@ class DefaultBranchFactory implements BranchFactory { /** @inheritDoc */ - public function createFromData(CarrierType $carrier, ?\Inspirum\Balikobot\Client\Request\ServiceType $service, array $data): Branch + public function createFromData(Carrier $carrier, ?Service $service, array $data): Branch { - if ($carrier->getValue() === Carrier::CP->getValue() && $service?->getValue() === ServiceType::CP_NP) { + if ($carrier->getValue() === CarrierType::CP->getValue() && $service?->getValue() === ServiceType::CP_NP) { $data['country'] ??= 'CZ'; } @@ -84,22 +85,22 @@ public function createFromData(CarrierType $carrier, ?\Inspirum\Balikobot\Client /** * @param array $data */ - private function resolveBranchId(CarrierType $carrier, ?\Inspirum\Balikobot\Client\Request\ServiceType $service, array $data): string + private function resolveBranchId(Carrier $carrier, ?Service $service, array $data): string { // get key used in branch_id when calling add request if ( - $carrier->getValue() === Carrier::CP->getValue() - || $carrier->getValue() === Carrier::SP->getValue() - || ($carrier->getValue() === Carrier::ULOZENKA->getValue() && $service?->getValue() === ServiceType::ULOZENKA_CP_NP) + $carrier->getValue() === CarrierType::CP->getValue() + || $carrier->getValue() === CarrierType::SP->getValue() + || ($carrier->getValue() === CarrierType::ULOZENKA->getValue() && $service?->getValue() === ServiceType::ULOZENKA_CP_NP) ) { return str_replace(' ', '', $data['zip']); } - if ($carrier->getValue() === Carrier::PPL->getValue()) { + if ($carrier->getValue() === CarrierType::PPL->getValue()) { return str_replace('KM', '', (string) $data['id']); } - if ($carrier->getValue() === Carrier::INTIME->getValue()) { + if ($carrier->getValue() === CarrierType::INTIME->getValue()) { return $data['name']; } diff --git a/src/Model/Carrier/Carrier.php b/src/Model/Carrier/Carrier.php index 58e2c73..346f688 100644 --- a/src/Model/Carrier/Carrier.php +++ b/src/Model/Carrier/Carrier.php @@ -5,7 +5,7 @@ namespace Inspirum\Balikobot\Model\Carrier; use Inspirum\Arrayable\BaseModel; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier as RequestCarrier; use Inspirum\Balikobot\Client\Request\Version; use Inspirum\Balikobot\Model\Method\MethodCollection; use function array_map; @@ -13,7 +13,7 @@ /** * @extends \Inspirum\Arrayable\BaseModel */ -final class Carrier extends BaseModel implements CarrierType +final class Carrier extends BaseModel implements RequestCarrier { /** * @param array $methods diff --git a/src/Model/Carrier/CarrierFactory.php b/src/Model/Carrier/CarrierFactory.php index 9145383..12dbb1a 100644 --- a/src/Model/Carrier/CarrierFactory.php +++ b/src/Model/Carrier/CarrierFactory.php @@ -4,14 +4,15 @@ namespace Inspirum\Balikobot\Model\Carrier; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; +use Inspirum\Balikobot\Model\Carrier\Carrier as CarrierModel; interface CarrierFactory { /** * @param array $data */ - public function create(CarrierType $carrier, array $data): Carrier; + public function create(Carrier $carrier, array $data): CarrierModel; /** * @param array> $data diff --git a/src/Model/Carrier/DefaultCarrierFactory.php b/src/Model/Carrier/DefaultCarrierFactory.php index 41f380c..5163d3a 100644 --- a/src/Model/Carrier/DefaultCarrierFactory.php +++ b/src/Model/Carrier/DefaultCarrierFactory.php @@ -4,8 +4,9 @@ namespace Inspirum\Balikobot\Model\Carrier; -use Inspirum\Balikobot\Client\Request\CarrierType; -use Inspirum\Balikobot\Definitions\Version; +use Inspirum\Balikobot\Client\Request\Carrier; +use Inspirum\Balikobot\Definitions\VersionType; +use Inspirum\Balikobot\Model\Carrier\Carrier as CarrierModel; use Inspirum\Balikobot\Model\Method\MethodFactory; use function array_filter; use function array_map; @@ -18,11 +19,11 @@ public function __construct( } /** @inheritDoc */ - public function create(CarrierType $carrier, array $data): Carrier + public function create(Carrier $carrier, array $data): CarrierModel { - return new Carrier($carrier->getValue(), $data['name'], array_map(fn(array $methods) => $this->methodFactory->createCollection($methods), array_filter([ - Version::V2V1->getValue() => $data['methods'] ?? [], - Version::V2V2->getValue() => $data['v2_methods'] ?? [], + return new CarrierModel($carrier->getValue(), $data['name'], array_map(fn(array $methods) => $this->methodFactory->createCollection($methods), array_filter([ + VersionType::V2V1->getValue() => $data['methods'] ?? [], + VersionType::V2V2->getValue() => $data['v2_methods'] ?? [], ]))); } @@ -30,7 +31,7 @@ public function create(CarrierType $carrier, array $data): Carrier public function createCollection(array $data): CarrierCollection { return new CarrierCollection( - array_map(fn(array $carrier): Carrier => $this->create(Carrier::from($carrier['slug']), $carrier), $data['carriers']), + array_map(fn(array $carrier): CarrierModel => $this->create(CarrierModel::from($carrier['slug']), $carrier), $data['carriers']), ); } } diff --git a/src/Model/OrderedShipment/DefaultOrderedShipmentFactory.php b/src/Model/OrderedShipment/DefaultOrderedShipmentFactory.php index d60669d..b3b9db8 100644 --- a/src/Model/OrderedShipment/DefaultOrderedShipmentFactory.php +++ b/src/Model/OrderedShipment/DefaultOrderedShipmentFactory.php @@ -4,12 +4,12 @@ namespace Inspirum\Balikobot\Model\OrderedShipment; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; final class DefaultOrderedShipmentFactory implements OrderedShipmentFactory { /** @inheritDoc */ - public function create(CarrierType $carrier, array $packageIds, array $data): OrderedShipment + public function create(Carrier $carrier, array $packageIds, array $data): OrderedShipment { return new OrderedShipment( $data['order_id'], diff --git a/src/Model/OrderedShipment/OrderedShipment.php b/src/Model/OrderedShipment/OrderedShipment.php index ab361be..56fbcb8 100644 --- a/src/Model/OrderedShipment/OrderedShipment.php +++ b/src/Model/OrderedShipment/OrderedShipment.php @@ -5,7 +5,7 @@ namespace Inspirum\Balikobot\Model\OrderedShipment; use Inspirum\Arrayable\BaseModel; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; /** * @extends \Inspirum\Arrayable\BaseModel @@ -17,7 +17,7 @@ class OrderedShipment extends BaseModel */ public function __construct( public readonly string $orderId, - public readonly CarrierType $carrier, + public readonly Carrier $carrier, public readonly array $packageIds, public readonly string $handoverUrl, public readonly string $labelsUrl, diff --git a/src/Model/OrderedShipment/OrderedShipmentFactory.php b/src/Model/OrderedShipment/OrderedShipmentFactory.php index a1ccebb..5e97deb 100644 --- a/src/Model/OrderedShipment/OrderedShipmentFactory.php +++ b/src/Model/OrderedShipment/OrderedShipmentFactory.php @@ -4,7 +4,7 @@ namespace Inspirum\Balikobot\Model\OrderedShipment; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; interface OrderedShipmentFactory { @@ -12,5 +12,5 @@ interface OrderedShipmentFactory * @param array $packageIds * @param array $data */ - public function create(CarrierType $carrier, array $packageIds, array $data): OrderedShipment; + public function create(Carrier $carrier, array $packageIds, array $data): OrderedShipment; } diff --git a/src/Model/Package/DefaultPackageFactory.php b/src/Model/Package/DefaultPackageFactory.php index f76243b..0ead8bb 100644 --- a/src/Model/Package/DefaultPackageFactory.php +++ b/src/Model/Package/DefaultPackageFactory.php @@ -4,7 +4,7 @@ namespace Inspirum\Balikobot\Model\Package; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; use Inspirum\Balikobot\Client\Response\Validator; use function count; @@ -16,7 +16,7 @@ public function __construct( } /** @inheritDoc */ - public function create(CarrierType $carrier, array $data): Package + public function create(Carrier $carrier, array $data): Package { return new Package( $carrier, @@ -33,7 +33,7 @@ public function create(CarrierType $carrier, array $data): Package } /** @inheritDoc */ - public function createCollection(CarrierType $carrier, ?array $packages, array $data): PackageCollection + public function createCollection(Carrier $carrier, ?array $packages, array $data): PackageCollection { $packagesResponse = $data['packages'] ?? []; if ($packages !== null) { diff --git a/src/Model/Package/Package.php b/src/Model/Package/Package.php index 0c8ae2e..f2588df 100644 --- a/src/Model/Package/Package.php +++ b/src/Model/Package/Package.php @@ -5,7 +5,7 @@ namespace Inspirum\Balikobot\Model\Package; use Inspirum\Arrayable\BaseModel; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; use Inspirum\Balikobot\Model\WithCarrierId; /** @@ -17,7 +17,7 @@ class Package extends BaseModel implements WithCarrierId * @param array $pieces */ public function __construct( - public readonly CarrierType $carrier, + public readonly Carrier $carrier, public readonly string $packageId, public readonly string $batchId, public readonly string $carrierId, @@ -30,7 +30,7 @@ public function __construct( ) { } - public function getCarrier(): CarrierType + public function getCarrier(): Carrier { return $this->carrier; } diff --git a/src/Model/Package/PackageCollection.php b/src/Model/Package/PackageCollection.php index 8568d46..a5528c8 100644 --- a/src/Model/Package/PackageCollection.php +++ b/src/Model/Package/PackageCollection.php @@ -4,7 +4,7 @@ namespace Inspirum\Balikobot\Model\Package; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; use Inspirum\Balikobot\Model\BasePerCarrierCollection; use function array_map; @@ -17,7 +17,7 @@ class PackageCollection extends BasePerCarrierCollection * @param array<\Inspirum\Balikobot\Model\Package\Package> $packages */ public function __construct( - ?CarrierType $carrier = null, + ?Carrier $carrier = null, array $packages = [], private ?string $labelsUrl = null, ) { diff --git a/src/Model/Package/PackageFactory.php b/src/Model/Package/PackageFactory.php index 1382898..b24b4f8 100644 --- a/src/Model/Package/PackageFactory.php +++ b/src/Model/Package/PackageFactory.php @@ -4,18 +4,18 @@ namespace Inspirum\Balikobot\Model\Package; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; interface PackageFactory { /** * @param array $data */ - public function create(CarrierType $carrier, array $data): Package; + public function create(Carrier $carrier, array $data): Package; /** * @param array>|null $packages * @param array $data */ - public function createCollection(CarrierType $carrier, ?array $packages, array $data): PackageCollection; + public function createCollection(Carrier $carrier, ?array $packages, array $data): PackageCollection; } diff --git a/src/Model/PackageData/PackageDataCollection.php b/src/Model/PackageData/PackageDataCollection.php index d974348..680e458 100644 --- a/src/Model/PackageData/PackageDataCollection.php +++ b/src/Model/PackageData/PackageDataCollection.php @@ -5,7 +5,7 @@ namespace Inspirum\Balikobot\Model\PackageData; use Inspirum\Arrayable\BaseCollection; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; use function substr; use function time; use function uniqid; @@ -19,7 +19,7 @@ class PackageDataCollection extends BaseCollection * @param array<\Inspirum\Balikobot\Model\PackageData\PackageData> $packages */ public function __construct( - private CarrierType $carrier, + private Carrier $carrier, array $packages = [], ) { parent::__construct([]); @@ -29,7 +29,7 @@ public function __construct( } } - public function getCarrier(): CarrierType + public function getCarrier(): Carrier { return $this->carrier; } diff --git a/src/Model/PerCarrierCollection.php b/src/Model/PerCarrierCollection.php index 09aabf6..0510221 100644 --- a/src/Model/PerCarrierCollection.php +++ b/src/Model/PerCarrierCollection.php @@ -4,14 +4,14 @@ namespace Inspirum\Balikobot\Model; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; /** * @template T of \Inspirum\Balikobot\Model\WithCarrierId */ interface PerCarrierCollection { - public function getCarrier(): CarrierType; + public function getCarrier(): Carrier; /** * @return T|null diff --git a/src/Model/PostCode/DefaultPostCodeFactory.php b/src/Model/PostCode/DefaultPostCodeFactory.php index c5fe38a..2c5fd54 100644 --- a/src/Model/PostCode/DefaultPostCodeFactory.php +++ b/src/Model/PostCode/DefaultPostCodeFactory.php @@ -4,13 +4,13 @@ namespace Inspirum\Balikobot\Model\PostCode; -use Inspirum\Balikobot\Client\Request\CarrierType; -use Inspirum\Balikobot\Client\Request\ServiceType; +use Inspirum\Balikobot\Client\Request\Carrier; +use Inspirum\Balikobot\Client\Request\Service; final class DefaultPostCodeFactory implements PostCodeFactory { /** @inheritDoc */ - public function create(CarrierType $carrier, ?ServiceType $service, array $data): PostCode + public function create(Carrier $carrier, ?Service $service, array $data): PostCode { return new PostCode( $carrier, @@ -22,4 +22,16 @@ public function create(CarrierType $carrier, ?ServiceType $service, array $data) (bool) ($data['1B'] ?? false), ); } + + /** @inheritDoc */ + public function createIterator(Carrier $carrier, ?Service $service, ?string $country, array $data): iterable + { + $country = $data['country'] ?? $country; + + foreach ($data['zip_codes'] ?? [] as $item) { + $item['country'] ??= $country; + + yield $this->create($carrier, $service, $item); + } + } } diff --git a/src/Model/PostCode/PostCode.php b/src/Model/PostCode/PostCode.php index ff5da3d..e1321c7 100644 --- a/src/Model/PostCode/PostCode.php +++ b/src/Model/PostCode/PostCode.php @@ -5,8 +5,8 @@ namespace Inspirum\Balikobot\Model\PostCode; use Inspirum\Arrayable\BaseModel; -use Inspirum\Balikobot\Client\Request\CarrierType; -use Inspirum\Balikobot\Client\Request\ServiceType; +use Inspirum\Balikobot\Client\Request\Carrier; +use Inspirum\Balikobot\Client\Request\Service; /** * @extends \Inspirum\Arrayable\BaseModel @@ -14,8 +14,8 @@ class PostCode extends BaseModel { public function __construct( - public readonly CarrierType $carrier, - public readonly ?ServiceType $service, + public readonly Carrier $carrier, + public readonly ?Service $service, public readonly string $postcode, public readonly ?string $postcodeEnd, public readonly ?string $city, diff --git a/src/Model/PostCode/PostCodeFactory.php b/src/Model/PostCode/PostCodeFactory.php index ac74746..5160a19 100644 --- a/src/Model/PostCode/PostCodeFactory.php +++ b/src/Model/PostCode/PostCodeFactory.php @@ -4,13 +4,20 @@ namespace Inspirum\Balikobot\Model\PostCode; -use Inspirum\Balikobot\Client\Request\CarrierType; -use Inspirum\Balikobot\Client\Request\ServiceType; +use Inspirum\Balikobot\Client\Request\Carrier; +use Inspirum\Balikobot\Client\Request\Service; interface PostCodeFactory { /** * @param array $data */ - public function create(CarrierType $carrier, ?ServiceType $service, array $data): PostCode; + public function create(Carrier $carrier, ?Service $service, array $data): PostCode; + + /** + * @param array $data + * + * @return iterable<\Inspirum\Balikobot\Model\PostCode\PostCode> + */ + public function createIterator(Carrier $carrier, ?Service $service, ?string $country, array $data): iterable; } diff --git a/src/Model/Service/DefaultServiceFactory.php b/src/Model/Service/DefaultServiceFactory.php index ecc4d47..ef29c8a 100644 --- a/src/Model/Service/DefaultServiceFactory.php +++ b/src/Model/Service/DefaultServiceFactory.php @@ -4,7 +4,7 @@ namespace Inspirum\Balikobot\Model\Service; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; use Inspirum\Balikobot\Model\Country\CountryFactory; use function array_key_exists; use function array_map; @@ -17,7 +17,7 @@ public function __construct( } /** @inheritDoc */ - public function create(CarrierType $carrier, array $data): Service + public function create(Carrier $carrier, array $data): Service { return new Service( $data['service_type'], @@ -33,7 +33,7 @@ public function create(CarrierType $carrier, array $data): Service } /** @inheritDoc */ - public function createCollection(CarrierType $carrier, array $data): ServiceCollection + public function createCollection(Carrier $carrier, array $data): ServiceCollection { return new ServiceCollection( $carrier, @@ -57,7 +57,7 @@ public function createOption(array $data): ServiceOption /** * @param array $data */ - private function createOptionCollection(CarrierType $carrier, array $data): ServiceOptionCollection + private function createOptionCollection(Carrier $carrier, array $data): ServiceOptionCollection { return new ServiceOptionCollection( array_map(fn(array $data): ServiceOption => $this->createOption($data), $data['services'] ?? []) diff --git a/src/Model/Service/Service.php b/src/Model/Service/Service.php index 13a2f51..cd68c40 100644 --- a/src/Model/Service/Service.php +++ b/src/Model/Service/Service.php @@ -5,12 +5,12 @@ namespace Inspirum\Balikobot\Model\Service; use Inspirum\Arrayable\BaseModel; -use Inspirum\Balikobot\Client\Request\ServiceType; +use Inspirum\Balikobot\Client\Request\Service; /** * @extends \Inspirum\Arrayable\BaseModel */ -final class Service extends BaseModel implements ServiceType +final class Service extends BaseModel implements Service { /** * @param array|null $countries diff --git a/src/Model/Service/ServiceCollection.php b/src/Model/Service/ServiceCollection.php index fbe61de..035b020 100644 --- a/src/Model/Service/ServiceCollection.php +++ b/src/Model/Service/ServiceCollection.php @@ -5,8 +5,8 @@ namespace Inspirum\Balikobot\Model\Service; use Inspirum\Arrayable\BaseCollection; -use Inspirum\Balikobot\Client\Request\CarrierType; -use Inspirum\Balikobot\Client\Request\ServiceType; +use Inspirum\Balikobot\Client\Request\Carrier; +use Inspirum\Balikobot\Client\Request\Service; use function array_map; /** @@ -18,7 +18,7 @@ final class ServiceCollection extends BaseCollection * @param array $services */ public function __construct( - private readonly CarrierType $carrier, + private readonly Carrier $carrier, private readonly array $services, private readonly ?bool $parcel = null, private readonly ?bool $cargo = null, @@ -26,17 +26,17 @@ public function __construct( parent::__construct($this->services); } - public function getCarrier(): CarrierType + public function getCarrier(): Carrier { return $this->carrier; } /** - * @return array<\Inspirum\Balikobot\Client\Request\ServiceType> + * @return array<\Inspirum\Balikobot\Client\Request\Service> */ public function getServiceTypes(): array { - return array_map(static fn(Service $service): ServiceType => $service, $this->services); + return array_map(static fn(Service $service): Service => $service, $this->services); } public function supportsParcel(): ?bool diff --git a/src/Model/Service/ServiceFactory.php b/src/Model/Service/ServiceFactory.php index 010e240..537dc4a 100644 --- a/src/Model/Service/ServiceFactory.php +++ b/src/Model/Service/ServiceFactory.php @@ -4,17 +4,17 @@ namespace Inspirum\Balikobot\Model\Service; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; interface ServiceFactory { /** * @param array $data */ - public function create(CarrierType $carrier, array $data): Service; + public function create(Carrier $carrier, array $data): Service; /** * @param array $data */ - public function createCollection(CarrierType $carrier, array $data): ServiceCollection; + public function createCollection(Carrier $carrier, array $data): ServiceCollection; } diff --git a/src/Model/Status/DefaultPackageStatusFactory.php b/src/Model/Status/DefaultPackageStatusFactory.php index 65b5af3..c0efcbc 100644 --- a/src/Model/Status/DefaultPackageStatusFactory.php +++ b/src/Model/Status/DefaultPackageStatusFactory.php @@ -5,7 +5,7 @@ namespace Inspirum\Balikobot\Model\Status; use DateTimeImmutable; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; use Inspirum\Balikobot\Client\Response\Validator; use Inspirum\Balikobot\Exception\BadRequestException; use Throwable; @@ -24,7 +24,7 @@ public function __construct( } /** @inheritDoc */ - public function create(CarrierType $carrier, string $carrierId, array $data, array $response = []): Status + public function create(Carrier $carrier, string $carrierId, array $data, array $response = []): Status { try { return new Status( @@ -42,7 +42,7 @@ public function create(CarrierType $carrier, string $carrierId, array $data, arr } /** @inheritDoc */ - public function createLastStatus(CarrierType $carrier, array $data, array $response = []): Status + public function createLastStatus(Carrier $carrier, array $data, array $response = []): Status { $this->validator->validateResponseStatus($data, $response); @@ -62,7 +62,7 @@ public function createLastStatus(CarrierType $carrier, array $data, array $respo } /** @inheritDoc */ - public function createCollection(CarrierType $carrier, array $carrierIds, array $data): StatusesCollection + public function createCollection(Carrier $carrier, array $carrierIds, array $data): StatusesCollection { $packages = $data['packages'] ?? []; $this->validator->validateIndexes($packages, count($carrierIds)); @@ -81,7 +81,7 @@ public function createCollection(CarrierType $carrier, array $carrierIds, array * * @throws \Inspirum\Balikobot\Exception\Exception */ - private function createStatuses(CarrierType $carrier, array $data, array $response = []): Statuses + private function createStatuses(Carrier $carrier, array $data, array $response = []): Statuses { $this->validator->validateResponseStatus($data, $response); assert(is_string($data['carrier_id'])); @@ -98,7 +98,7 @@ private function createStatuses(CarrierType $carrier, array $data, array $respon } /** @inheritDoc */ - public function createLastStatusCollection(CarrierType $carrier, array $carrierIds, array $data): StatusCollection + public function createLastStatusCollection(Carrier $carrier, array $carrierIds, array $data): StatusCollection { $packages = $data['packages'] ?? []; $this->validator->validateIndexes($packages, count($carrierIds)); diff --git a/src/Model/Status/PackageStatusFactory.php b/src/Model/Status/PackageStatusFactory.php index 9194700..c8da89e 100644 --- a/src/Model/Status/PackageStatusFactory.php +++ b/src/Model/Status/PackageStatusFactory.php @@ -4,7 +4,7 @@ namespace Inspirum\Balikobot\Model\Status; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; interface PackageStatusFactory { @@ -12,23 +12,23 @@ interface PackageStatusFactory * @param array $data * @param array $response */ - public function create(CarrierType $carrier, string $carrierId, array $data, array $response = []): Status; + public function create(Carrier $carrier, string $carrierId, array $data, array $response = []): Status; /** * @param array $data * @param array $response */ - public function createLastStatus(CarrierType $carrier, array $data, array $response = []): Status; + public function createLastStatus(Carrier $carrier, array $data, array $response = []): Status; /** * @param array $carrierIds * @param array $data */ - public function createCollection(CarrierType $carrier, array $carrierIds, array $data): StatusesCollection; + public function createCollection(Carrier $carrier, array $carrierIds, array $data): StatusesCollection; /** * @param array $carrierIds * @param array $data */ - public function createLastStatusCollection(CarrierType $carrier, array $carrierIds, array $data): StatusCollection; + public function createLastStatusCollection(Carrier $carrier, array $carrierIds, array $data): StatusCollection; } diff --git a/src/Model/Status/Status.php b/src/Model/Status/Status.php index 9e8f318..8d7eadf 100644 --- a/src/Model/Status/Status.php +++ b/src/Model/Status/Status.php @@ -6,7 +6,7 @@ use DateTimeInterface; use Inspirum\Arrayable\BaseModel; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; use Inspirum\Balikobot\Model\WithCarrierId; /** @@ -15,7 +15,7 @@ final class Status extends BaseModel implements WithCarrierId { public function __construct( - public readonly CarrierType $carrier, + public readonly Carrier $carrier, public readonly string $carrierId, public readonly float $id, public readonly string $name, @@ -25,7 +25,7 @@ public function __construct( ) { } - public function getCarrier(): CarrierType + public function getCarrier(): Carrier { return $this->carrier; } diff --git a/src/Model/Status/Statuses.php b/src/Model/Status/Statuses.php index 0a44283..43cc02e 100644 --- a/src/Model/Status/Statuses.php +++ b/src/Model/Status/Statuses.php @@ -5,7 +5,7 @@ namespace Inspirum\Balikobot\Model\Status; use Inspirum\Arrayable\BaseCollection; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; use Inspirum\Balikobot\Model\WithCarrierId; use InvalidArgumentException; use function sprintf; @@ -19,7 +19,7 @@ final class Statuses extends BaseCollection implements WithCarrierId * @param array<\Inspirum\Balikobot\Model\Status\Status> $states */ public function __construct( - private CarrierType $carrier, + private Carrier $carrier, private string $carrierId, array $states, ) { @@ -60,7 +60,7 @@ private function validateCarrierId(Status $item): void } } - public function getCarrier(): CarrierType + public function getCarrier(): Carrier { return $this->carrier; } diff --git a/src/Model/TransportCost/DefaultTransportCostFactory.php b/src/Model/TransportCost/DefaultTransportCostFactory.php index afdba3e..f8efbcc 100644 --- a/src/Model/TransportCost/DefaultTransportCostFactory.php +++ b/src/Model/TransportCost/DefaultTransportCostFactory.php @@ -4,13 +4,13 @@ namespace Inspirum\Balikobot\Model\TransportCost; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; use function array_map; final class DefaultTransportCostFactory implements TransportCostFactory { /** @inheritDoc */ - public function create(CarrierType $carrier, array $data): TransportCost + public function create(Carrier $carrier, array $data): TransportCost { return new TransportCost( $data['eid'], @@ -22,7 +22,7 @@ public function create(CarrierType $carrier, array $data): TransportCost } /** @inheritDoc */ - public function createCollection(CarrierType $carrier, array $data): TransportCostCollection + public function createCollection(Carrier $carrier, array $data): TransportCostCollection { unset($data['status']); diff --git a/src/Model/TransportCost/TransportCost.php b/src/Model/TransportCost/TransportCost.php index 7090ff1..9c87238 100644 --- a/src/Model/TransportCost/TransportCost.php +++ b/src/Model/TransportCost/TransportCost.php @@ -5,7 +5,7 @@ namespace Inspirum\Balikobot\Model\TransportCost; use Inspirum\Arrayable\BaseModel; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; /** * @extends \Inspirum\Arrayable\BaseModel @@ -17,7 +17,7 @@ class TransportCost extends BaseModel */ public function __construct( public readonly string $batchId, - public readonly CarrierType $carrier, + public readonly Carrier $carrier, public readonly float $totalCost, public readonly string $currencyCode, public readonly array $costsBreakdown = [] diff --git a/src/Model/TransportCost/TransportCostCollection.php b/src/Model/TransportCost/TransportCostCollection.php index 25a9bdf..fe16c8e 100644 --- a/src/Model/TransportCost/TransportCostCollection.php +++ b/src/Model/TransportCost/TransportCostCollection.php @@ -5,7 +5,7 @@ namespace Inspirum\Balikobot\Model\TransportCost; use Inspirum\Arrayable\BaseCollection; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; use RuntimeException; use function array_map; @@ -15,12 +15,12 @@ class TransportCostCollection extends BaseCollection { public function __construct( - private ?CarrierType $carrier, + private ?Carrier $carrier, ) { parent::__construct([]); } - public function getCarrier(): CarrierType + public function getCarrier(): Carrier { return $this->carrier ?? throw new RuntimeException('Collection is empty'); } diff --git a/src/Model/TransportCost/TransportCostFactory.php b/src/Model/TransportCost/TransportCostFactory.php index 0a9976c..939d13a 100644 --- a/src/Model/TransportCost/TransportCostFactory.php +++ b/src/Model/TransportCost/TransportCostFactory.php @@ -4,17 +4,17 @@ namespace Inspirum\Balikobot\Model\TransportCost; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; interface TransportCostFactory { /** * @param array $data */ - public function create(CarrierType $carrier, array $data): TransportCost; + public function create(Carrier $carrier, array $data): TransportCost; /** * @param array $data */ - public function createCollection(CarrierType $carrier, array $data): TransportCostCollection; + public function createCollection(Carrier $carrier, array $data): TransportCostCollection; } diff --git a/src/Model/Unit/DefaultUnitFactory.php b/src/Model/Unit/DefaultUnitFactory.php index 263be72..6982764 100644 --- a/src/Model/Unit/DefaultUnitFactory.php +++ b/src/Model/Unit/DefaultUnitFactory.php @@ -4,6 +4,7 @@ namespace Inspirum\Balikobot\Model\Unit; +use Inspirum\Balikobot\Client\Request\Carrier; use function array_map; final class DefaultUnitFactory implements UnitFactory @@ -15,9 +16,10 @@ public function create(array $data): Unit } /** @inheritDoc */ - public function createCollection(array $data): UnitCollection + public function createCollection(Carrier $carrierType, array $data): UnitCollection { return new UnitCollection( + $carrierType, array_map(fn(array $unit): Unit => $this->create($unit), $data['units'] ?? []), ); } diff --git a/src/Model/Unit/UnitCollection.php b/src/Model/Unit/UnitCollection.php index cd911c9..7c25e70 100644 --- a/src/Model/Unit/UnitCollection.php +++ b/src/Model/Unit/UnitCollection.php @@ -5,10 +5,25 @@ namespace Inspirum\Balikobot\Model\Unit; use Inspirum\Arrayable\BaseCollection; +use Inspirum\Balikobot\Client\Request\Carrier; /** * @extends \Inspirum\Arrayable\BaseCollection */ final class UnitCollection extends BaseCollection { + /** + * @param array $items + */ + public function __construct( + private Carrier $carrier, + array $items = [], + ) { + parent::__construct($items); + } + + public function getCarrier(): Carrier + { + return $this->carrier; + } } diff --git a/src/Model/Unit/UnitFactory.php b/src/Model/Unit/UnitFactory.php index 6ab27a3..c8ef06d 100644 --- a/src/Model/Unit/UnitFactory.php +++ b/src/Model/Unit/UnitFactory.php @@ -4,6 +4,8 @@ namespace Inspirum\Balikobot\Model\Unit; +use Inspirum\Balikobot\Client\Request\Carrier; + interface UnitFactory { /** @@ -14,5 +16,5 @@ public function create(array $data): Unit; /** * @param array $data */ - public function createCollection(array $data): UnitCollection; + public function createCollection(Carrier $carrierType, array $data): UnitCollection; } diff --git a/src/Model/WithCarrierId.php b/src/Model/WithCarrierId.php index 1739de4..09578bb 100644 --- a/src/Model/WithCarrierId.php +++ b/src/Model/WithCarrierId.php @@ -4,11 +4,11 @@ namespace Inspirum\Balikobot\Model; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; interface WithCarrierId { - public function getCarrier(): CarrierType; + public function getCarrier(): Carrier; public function getCarrierId(): string; } diff --git a/src/Service/BranchService.php b/src/Service/BranchService.php index 49a5477..3cce1fc 100644 --- a/src/Service/BranchService.php +++ b/src/Service/BranchService.php @@ -4,14 +4,15 @@ namespace Inspirum\Balikobot\Service; -use Inspirum\Balikobot\Definitions\Carrier; +use Inspirum\Balikobot\Client\Request\Carrier; +use Inspirum\Balikobot\Client\Request\Service; interface BranchService { /** * Get all available branches * - * @return iterable<\Inspirum\Balikobot\Model\Branch> + * @return iterable<\Inspirum\Balikobot\Model\Branch\Branch> * * @throws \Inspirum\Balikobot\Exception\Exception */ @@ -22,61 +23,61 @@ public function getBranches(): iterable; * * @param array $countries * - * @return iterable<\Inspirum\Balikobot\Model\Branch> + * @return iterable<\Inspirum\Balikobot\Model\Branch\Branch> * * @throws \Inspirum\Balikobot\Exception\Exception */ public function getBranchesForCountries(array $countries): iterable; /** - * Get all available branches for given shipper + * Get all available branches for carrier * - * @return iterable<\Inspirum\Balikobot\Model\Branch> + * @return iterable<\Inspirum\Balikobot\Model\Branch\Branch> * * @throws \Inspirum\Balikobot\Exception\Exception */ - public function getBranchesForCarrier(string $carrier): iterable; + public function getBranchesForCarrier(Carrier $carrier): iterable; /** - * Get all available branches for given shipper for countries + * Get all available branches for carrier and countries * * @param array $countries * - * @return iterable<\Inspirum\Balikobot\Model\Branch> + * @return iterable<\Inspirum\Balikobot\Model\Branch\Branch> * * @throws \Inspirum\Balikobot\Exception\Exception */ - public function getBranchesForCarrierAndCountries(string $carrier, array $countries): iterable; + public function getBranchesForCarrierAndCountries(Carrier $carrier, array $countries): iterable; /** - * Get all available branches for given shipper and service type for countries + * Get all available branches for carrier and service type * - * @param array $countries - * - * @return iterable<\Inspirum\Balikobot\Model\Branch> + * @return iterable<\Inspirum\Balikobot\Model\Branch\Branch> * * @throws \Inspirum\Balikobot\Exception\Exception */ - public function getBranchesForCarrierServiceAndCountries(string $carrier, ?string $service, array $countries): iterable; + public function getBranchesForCarrierService(Carrier $carrier, ?Service $service): iterable; /** - * Get all available branches for given shipper and service type + * Get all available branches for carrier, service type and countries + * + * @param array $countries * - * @return iterable<\Inspirum\Balikobot\Model\Branch> + * @return iterable<\Inspirum\Balikobot\Model\Branch\Branch> * * @throws \Inspirum\Balikobot\Exception\Exception */ - public function getBranchesForShipperServiceAndCountry(string $carrier, ?string $service, ?string $country = null): iterable; + public function getBranchesForCarrierServiceAndCountries(Carrier $carrier, ?Service $service, array $countries): iterable; /** - * Get all available branches for given shipper + * Get all available branches for carrier in specific location * - * @return iterable<\Inspirum\Balikobot\Model\Branch> + * @return iterable<\Inspirum\Balikobot\Model\Branch\Branch> * * @throws \Inspirum\Balikobot\Exception\Exception */ public function getBranchesForLocation( - string $carrier, + Carrier $carrier, string $country, string $city, ?string $postcode = null, diff --git a/src/Service/DefaultInfoService.php b/src/Service/DefaultInfoService.php index e4701a1..6247c9f 100644 --- a/src/Service/DefaultInfoService.php +++ b/src/Service/DefaultInfoService.php @@ -5,12 +5,12 @@ namespace Inspirum\Balikobot\Service; use Inspirum\Balikobot\Client\Client; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; use Inspirum\Balikobot\Definitions\Request; -use Inspirum\Balikobot\Definitions\Version; +use Inspirum\Balikobot\Definitions\VersionType; use Inspirum\Balikobot\Model\Account\Account; use Inspirum\Balikobot\Model\Account\AccountFactory; -use Inspirum\Balikobot\Model\Carrier\Carrier; +use Inspirum\Balikobot\Model\Carrier\Carrier as CarrierModel; use Inspirum\Balikobot\Model\Carrier\CarrierCollection; use Inspirum\Balikobot\Model\Carrier\CarrierFactory; use Inspirum\Balikobot\Model\Changelog\ChangelogCollection; @@ -28,28 +28,28 @@ public function __construct( public function getAccountInfo(): Account { - $response = $this->client->call(Version::V2V1, null, Request::INFO_WHO_AM_I); + $response = $this->client->call(VersionType::V2V1, null, Request::INFO_WHO_AM_I); return $this->accountFactory->create($response); } public function getCarriers(): CarrierCollection { - $response = $this->client->call(Version::V2V1, null, Request::INFO_CARRIERS); + $response = $this->client->call(VersionType::V2V1, null, Request::INFO_CARRIERS); return $this->carrierFactory->createCollection($response); } - public function getCarrier(CarrierType $carrier): Carrier + public function getCarrier(Carrier $carrier): CarrierModel { - $response = $this->client->call(Version::V2V1, null, Request::INFO_CARRIERS, path: $carrier->getValue()); + $response = $this->client->call(VersionType::V2V1, null, Request::INFO_CARRIERS, path: $carrier->getValue()); return $this->carrierFactory->create($carrier, $response); } public function getChangelog(): ChangelogCollection { - $response = $this->client->call(Version::V2V1, null, Request::CHANGELOG); + $response = $this->client->call(VersionType::V2V1, null, Request::CHANGELOG); return $this->changelogFactory->createCollection($response); } diff --git a/src/Service/DefaultSettingService.php b/src/Service/DefaultSettingService.php new file mode 100644 index 0000000..ea47a89 --- /dev/null +++ b/src/Service/DefaultSettingService.php @@ -0,0 +1,129 @@ +client->call(VersionType::V2V1, $carrier, Request::SERVICES); + + return $this->serviceFactory->createCollection($carrier, $response); + } + + public function getActivatedServices(Carrier $carrier): ServiceCollection + { + $response = $this->client->call(VersionType::V2V1, $carrier, Request::ACTIVATED_SERVICES); + + return $this->serviceFactory->createCollection($carrier, $response); + } + + public function getB2AServices(Carrier $carrier): ServiceCollection + { + $response = $this->client->call(VersionType::V2V1, $carrier, Request::B2A_SERVICES); + + return $this->serviceFactory->createCollection($carrier, $response); + } + + public function getManipulationUnits(Carrier $carrier): UnitCollection + { + $response = $this->client->call(VersionType::V2V1, $carrier, Request::MANIPULATION_UNITS); + + return $this->unitFactory->createCollection($carrier, $response); + } + + public function getActivatedManipulationUnits(Carrier $carrier): UnitCollection + { + $response = $this->client->call(VersionType::V2V1, $carrier, Request::ACTIVATED_MANIPULATION_UNITS); + + return $this->unitFactory->createCollection($carrier, $response); + } + + public function getCodCountries(Carrier $carrier): ServiceCollection + { + $response = $this->client->call(VersionType::V2V1, $carrier, Request::CASH_ON_DELIVERY_COUNTRIES); + + return $this->serviceFactory->createCollection($carrier, $response); + } + + public function getCountries(Carrier $carrier): ServiceCollection + { + $response = $this->client->call(VersionType::V2V1, $carrier, Request::COUNTRIES); + + return $this->serviceFactory->createCollection($carrier, $response); + } + + public function getCountriesData(): CountryCollection + { + $response = $this->client->call(VersionType::V2V1, null, Request::GET_COUNTRIES_DATA); + + return $this->countryFactory->createCollection($response); + } + + /** @inheritDoc */ + public function getPostCodes(Carrier $carrier, Service $service, ?string $country = null): iterable + { + $response = $this->client->call(VersionType::V2V1, $carrier, Request::ZIP_CODES, path: sprintf('%s/%s', $service->getValue(), $country)); + + return $this->postCodeFactory->createIterator($carrier, $service, $country, $response); + } + + public function getAdrUnits(Carrier $carrier): AdrUnitCollection + { + $response = $this->client->call(VersionType::V2V1, $carrier, Request::FULL_ADR_UNITS); + + return $this->adrUnitFactory->createCollection($carrier, $response); + } + + public function getAddAttributes(Carrier $carrier): AttributeCollection + { + $response = $this->client->call(VersionType::V2V1, $carrier, Request::ADD_ATTRIBUTES); + + return $this->attributeFactory->createCollection($carrier, $response); + } + + public function getAddServiceOptions(Carrier $carrier): ServiceCollection + { + $response = $this->client->call(VersionType::V2V1, $carrier, Request::ADD_SERVICE_OPTIONS); + + return $this->serviceFactory->createCollection($carrier, $response); + } + + public function getAddServiceOptionsForService(Carrier $carrier, Service $service): Service + { + $response = $this->client->call(VersionType::V2V1, $carrier, Request::ADD_SERVICE_OPTIONS, path: $service->getValue()); + + return $this->serviceFactory->create($carrier, $response); + } +} diff --git a/src/Service/DefaultTrackService.php b/src/Service/DefaultTrackService.php index 11eb6eb..0413ae6 100644 --- a/src/Service/DefaultTrackService.php +++ b/src/Service/DefaultTrackService.php @@ -5,9 +5,9 @@ namespace Inspirum\Balikobot\Service; use Inspirum\Balikobot\Client\Client; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; use Inspirum\Balikobot\Definitions\Request; -use Inspirum\Balikobot\Definitions\Version; +use Inspirum\Balikobot\Definitions\VersionType; use Inspirum\Balikobot\Model\Package\Package; use Inspirum\Balikobot\Model\Package\PackageCollection; use Inspirum\Balikobot\Model\Status\PackageStatusFactory; @@ -30,7 +30,7 @@ public function trackPackage(Package $package): Statuses return $this->trackPackageById($package->carrier, $package->carrierId); } - public function trackPackageById(CarrierType $carrier, string $carrierId): Statuses + public function trackPackageById(Carrier $carrier, string $carrierId): Statuses { return $this->trackPackagesByIds($carrier, [$carrierId])->getForCarrierId($carrierId) ?? throw new OutOfBoundsException(); } @@ -41,10 +41,10 @@ public function trackPackages(PackageCollection $packages): StatusesCollection } /** @inheritDoc */ - public function trackPackagesByIds(CarrierType $carrier, array $carrierIds): StatusesCollection + public function trackPackagesByIds(Carrier $carrier, array $carrierIds): StatusesCollection { $response = $this->client->call( - Version::V2V2, + VersionType::V2V2, $carrier, Request::TRACK, ['carrier_ids' => $carrierIds], @@ -59,7 +59,7 @@ public function trackPackageLastStatus(Package $package): Status return $this->trackPackageLastStatusById($package->carrier, $package->carrierId); } - public function trackPackageLastStatusById(CarrierType $carrier, string $carrierId): Status + public function trackPackageLastStatusById(Carrier $carrier, string $carrierId): Status { return $this->trackPackagesLastStatusesByIds($carrier, [$carrierId])->getForCarrierId($carrierId) ?? throw new OutOfBoundsException(); } @@ -70,10 +70,10 @@ public function trackPackagesLastStatuses(PackageCollection $packages): StatusCo } /** @inheritDoc */ - public function trackPackagesLastStatusesByIds(CarrierType $carrier, array $carrierIds): StatusCollection + public function trackPackagesLastStatusesByIds(Carrier $carrier, array $carrierIds): StatusCollection { $response = $this->client->call( - Version::V2V2, + VersionType::V2V2, $carrier, Request::TRACK_STATUS, ['carrier_ids' => $carrierIds], diff --git a/src/Service/InfoService.php b/src/Service/InfoService.php index 590fbab..fc5351c 100644 --- a/src/Service/InfoService.php +++ b/src/Service/InfoService.php @@ -4,9 +4,9 @@ namespace Inspirum\Balikobot\Service; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; use Inspirum\Balikobot\Model\Account\Account; -use Inspirum\Balikobot\Model\Carrier\Carrier; +use Inspirum\Balikobot\Model\Carrier\Carrier as CarrierModel; use Inspirum\Balikobot\Model\Carrier\CarrierCollection; use Inspirum\Balikobot\Model\Changelog\ChangelogCollection; @@ -31,7 +31,7 @@ public function getCarriers(): CarrierCollection; * * @throws \Inspirum\Balikobot\Exception\Exception */ - public function getCarrier(CarrierType $carrier): Carrier; + public function getCarrier(Carrier $carrier): CarrierModel; /** * Get news in the Balikobot API diff --git a/src/Service/SettingService.php b/src/Service/SettingService.php new file mode 100644 index 0000000..f0b15da --- /dev/null +++ b/src/Service/SettingService.php @@ -0,0 +1,109 @@ + + * + * @throws \Inspirum\Balikobot\Exception\Exception + */ + public function getPostCodes(Carrier $carrier, Service $service, ?string $country = null): iterable; + + /** + * Get ADR units for carrier + * + * @throws \Inspirum\Balikobot\Exception\Exception + */ + public function getAdrUnits(Carrier $carrier): AdrUnitCollection; + + /** + * Get available package data options for carrier + * + * @throws \Inspirum\Balikobot\Exception\Exception + */ + public function getAddAttributes(Carrier $carrier): AttributeCollection; + + /** + * Get additional services (package data `services`) for carrier + * + * @throws \Inspirum\Balikobot\Exception\Exception + */ + public function getAddServiceOptions(Carrier $carrier): ServiceCollection; + + /** + * Get additional services (package data `services`) for carrier and service type + * + * @throws \Inspirum\Balikobot\Exception\Exception + */ + public function getAddServiceOptionsForService(Carrier $carrier, Service $service): Service; +} diff --git a/src/Service/TrackService.php b/src/Service/TrackService.php index e905890..49039dc 100644 --- a/src/Service/TrackService.php +++ b/src/Service/TrackService.php @@ -4,7 +4,7 @@ namespace Inspirum\Balikobot\Service; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; use Inspirum\Balikobot\Model\Package\Package; use Inspirum\Balikobot\Model\Package\PackageCollection; use Inspirum\Balikobot\Model\Status\Status; @@ -26,7 +26,7 @@ public function trackPackage(Package $package): Statuses; * * @throws \Inspirum\Balikobot\Exception\Exception */ - public function trackPackageById(CarrierType $carrier, string $carrierId): Statuses; + public function trackPackageById(Carrier $carrier, string $carrierId): Statuses; /** * Track packages @@ -42,7 +42,7 @@ public function trackPackages(PackageCollection $packages): StatusesCollection; * * @throws \Inspirum\Balikobot\Exception\Exception */ - public function trackPackagesByIds(CarrierType $carrier, array $carrierIds): StatusesCollection; + public function trackPackagesByIds(Carrier $carrier, array $carrierIds): StatusesCollection; /** * Track package last status @@ -56,7 +56,7 @@ public function trackPackageLastStatus(Package $package): Status; * * @throws \Inspirum\Balikobot\Exception\Exception */ - public function trackPackageLastStatusById(CarrierType $carrier, string $carrierId): Status; + public function trackPackageLastStatusById(Carrier $carrier, string $carrierId): Status; /** * Track packages last statuses @@ -72,5 +72,5 @@ public function trackPackagesLastStatuses(PackageCollection $packages): StatusCo * * @throws \Inspirum\Balikobot\Exception\Exception */ - public function trackPackagesLastStatusesByIds(CarrierType $carrier, array $carrierIds): StatusCollection; + public function trackPackagesLastStatusesByIds(Carrier $carrier, array $carrierIds): StatusCollection; } diff --git a/tests/Integration/Client/CurlRequesterTest.php b/tests/Integration/Client/CurlRequesterTest.php index f7dec26..3260b94 100644 --- a/tests/Integration/Client/CurlRequesterTest.php +++ b/tests/Integration/Client/CurlRequesterTest.php @@ -4,9 +4,9 @@ namespace Inspirum\Balikobot\Tests\Integration\Client; -use Inspirum\Balikobot\Client\CurlRequester; +use Inspirum\Balikobot\Client\DefaultCurlRequester; use Inspirum\Balikobot\Definitions\Request; -use Inspirum\Balikobot\Definitions\Version; +use Inspirum\Balikobot\Definitions\VersionType; use Inspirum\Balikobot\Tests\BaseTestCase; use function getenv; use function json_decode; @@ -18,12 +18,12 @@ public function testSSLVerificationIsNotNeeded(): void { $apiUser = (string) getenv('BALIKOBOT_API_USER'); $apiKey = (string) getenv('BALIKOBOT_API_KEY'); - $url = sprintf('%s/%s', Version::V2V1, Request::CHANGELOG); + $url = sprintf('%s/%s', VersionType::V2V1->getValue(), Request::CHANGELOG->getValue()); - $requesterWithSSL = new CurlRequester($apiUser, $apiKey, sslVerify: false); + $requesterWithSSL = new DefaultCurlRequester($apiUser, $apiKey, sslVerify: false); $firstVersion = json_decode($requesterWithSSL->request($url)->getBody()->getContents(), true)['version']; - $requesterWithoutSSL = new CurlRequester($apiUser, $apiKey, sslVerify: true); + $requesterWithoutSSL = new DefaultCurlRequester($apiUser, $apiKey, sslVerify: true); $secondVersion = json_decode($requesterWithoutSSL->request($url)->getBody()->getContents(), true)['version']; self::assertEquals($firstVersion, $secondVersion); diff --git a/tests/Unit/Service/DefaultInfoServiceTest.php b/tests/Unit/Service/DefaultInfoServiceTest.php index a2e5687..ea6f1a3 100644 --- a/tests/Unit/Service/DefaultInfoServiceTest.php +++ b/tests/Unit/Service/DefaultInfoServiceTest.php @@ -6,8 +6,8 @@ use DateTimeImmutable; use Inspirum\Balikobot\Client\DefaultClient; -use Inspirum\Balikobot\Client\Request\CarrierType; use Inspirum\Balikobot\Client\Response\Validator; +use Inspirum\Balikobot\Definitions\CarrierType; use Inspirum\Balikobot\Exception\BadRequestException; use Inspirum\Balikobot\Model\Account\Account; use Inspirum\Balikobot\Model\Account\DefaultAccountFactory; @@ -31,7 +31,6 @@ final class DefaultInfoServiceTest extends BaseTestCase { /** * @param array $response - * @param array $carrierIds * @param array|null $request * * @dataProvider providesTestAccountInfo @@ -160,7 +159,6 @@ public function providesTestAccountInfo(): iterable /** * @param array $response - * @param array $carrierIds * @param array|null $request * * @dataProvider providesTestGetCarriers @@ -259,14 +257,13 @@ public function providesTestGetCarriers(): iterable /** * @param array $response - * @param array $carrierIds * @param array|null $request * * @dataProvider providesTestGetCarrier */ public function testGetCarrier( int $statusCode, - CarrierType $carrier, + Carrier $carrier, array $response, Carrier|Throwable|null $result, ?array $request = null, @@ -292,7 +289,7 @@ public function providesTestGetCarrier(): iterable { yield 'response_without_status' => [ 'statusCode' => 200, - 'carrier' => \Inspirum\Balikobot\Definitions\Carrier::ZASILKOVNA, + 'carrier' => CarrierType::ZASILKOVNA, 'response' => [ 'name' => 'Zásilkovna', 'v2_methods_available' => true, @@ -323,7 +320,7 @@ public function providesTestGetCarrier(): iterable yield 'valid_request' => [ 'statusCode' => 200, - 'carrier' => \Inspirum\Balikobot\Definitions\Carrier::ZASILKOVNA, + 'carrier' => CarrierType::ZASILKOVNA, 'response' => [ 'status' => 200, 'name' => 'Zásilkovna', @@ -371,7 +368,6 @@ public function providesTestGetCarrier(): iterable /** * @param array $response - * @param array $carrierIds * @param array|null $request * * @dataProvider providesTestGetChangelog diff --git a/tests/Unit/Service/DefaultSettingServiceTest.php b/tests/Unit/Service/DefaultSettingServiceTest.php new file mode 100644 index 0000000..635399d --- /dev/null +++ b/tests/Unit/Service/DefaultSettingServiceTest.php @@ -0,0 +1,629 @@ + [ + [ + 'service_type' => 'NP', + 'name' => 'NP - Balík Na poštu', + ], + [ + 'service_type' => 'RR', + 'name' => 'RR - Doporučená zásilka Ekonomická', + ], + ], + ]; + $expectedResult = new ServiceCollection($carrier, [ + new ServiceModel('NP', 'NP - Balík Na poštu'), + new ServiceModel('RR', 'RR - Doporučená zásilka Ekonomická'), + ]); + + $service = $this->newDefaultSettingService( + client: $this->mockClient([VersionType::V2V1, $carrier, Request::SERVICES], $response), + serviceFactory: $this->mockServiceFactory($carrier, $response, $expectedResult), + ); + + $actualResult = $service->getServices($carrier); + + self::assertSame($expectedResult, $actualResult); + } + + public function testGetActivatedServices(): void + { + $carrier = CarrierType::CP; + $response = [ + 'service_types' => [ + [ + 'service_type' => 'NP', + 'name' => 'NP - Balík Na poštu', + ], + [ + 'service_type' => 'RR', + 'name' => 'RR - Doporučená zásilka Ekonomická', + ], + ], + ]; + $expectedResult = new ServiceCollection($carrier, [ + new ServiceModel('NP', 'NP - Balík Na poštu'), + new ServiceModel('RR', 'RR - Doporučená zásilka Ekonomická'), + ]); + + $service = $this->newDefaultSettingService( + client: $this->mockClient([VersionType::V2V1, $carrier, Request::ACTIVATED_SERVICES], $response), + serviceFactory: $this->mockServiceFactory($carrier, $response, $expectedResult), + ); + + $actualResult = $service->getActivatedServices($carrier); + + self::assertSame($expectedResult, $actualResult); + } + + public function testGetB2AServices(): void + { + $carrier = CarrierType::CP; + $response = [ + 'service_types' => [ + [ + 'service_type' => 'NP', + 'name' => 'NP - Balík Na poštu', + ], + [ + 'service_type' => 'RR', + 'name' => 'RR - Doporučená zásilka Ekonomická', + ], + ], + ]; + $expectedResult = new ServiceCollection($carrier, [ + new ServiceModel('NP', 'NP - Balík Na poštu'), + new ServiceModel('RR', 'RR - Doporučená zásilka Ekonomická'), + ]); + + $service = $this->newDefaultSettingService( + client: $this->mockClient([VersionType::V2V1, $carrier, Request::B2A_SERVICES], $response), + serviceFactory: $this->mockServiceFactory($carrier, $response, $expectedResult), + ); + + $actualResult = $service->getB2AServices($carrier); + + self::assertSame($expectedResult, $actualResult); + } + + public function testGetManipulationUnits(): void + { + $carrier = CarrierType::CP; + $response = [ + 'units' => [ + [ + 'code' => 'KARTON', + 'name' => 'KARTON', + ], + [ + 'code' => 'KUS', + 'name' => 'KUS', + ], + ], + ]; + + $expectedResult = new UnitCollection($carrier, [ + new Unit('KARTON', 'KARTON'), + new Unit('KUS', 'KUS'), + ]); + + $service = $this->newDefaultSettingService( + client: $this->mockClient([VersionType::V2V1, $carrier, Request::MANIPULATION_UNITS], $response), + unitFactory: $this->mockUnitFactory($carrier, $response, $expectedResult), + ); + + $actualResult = $service->getManipulationUnits($carrier); + + self::assertSame($expectedResult, $actualResult); + } + + public function testGetActivatedManipulationUnits(): void + { + $carrier = CarrierType::TOPTRANS; + $response = [ + 'units' => [ + [ + 'code' => 'KARTON', + 'name' => 'KARTON', + ], + [ + 'code' => 'PALETA', + 'name' => 'PALETA', + ], + ], + ]; + + $expectedResult = new UnitCollection($carrier, [ + new Unit('KARTON', 'KARTON'), + new Unit('PALETA', 'PALETA'), + ]); + + $service = $this->newDefaultSettingService( + client: $this->mockClient([VersionType::V2V1, $carrier, Request::ACTIVATED_MANIPULATION_UNITS], $response), + unitFactory: $this->mockUnitFactory($carrier, $response, $expectedResult), + ); + + $actualResult = $service->getActivatedManipulationUnits($carrier); + + self::assertSame($expectedResult, $actualResult); + } + + public function testGetCodCountries(): void + { + $carrier = CarrierType::CP; + $response = [ + 'service_types' => [ + [ + 'service_type' => 'DR', + 'cod_countries' => [ + 'CZ' => [ + 'max_price' => 100000, + 'currency' => 'CZK', + ], + ], + ], + ], + ]; + $expectedResult = new ServiceCollection($carrier, [ + new ServiceModel('DR', null, codCountries: [ + new CodCountry( + 'CZ', + 'CZK', + 100000, + ), + ]), + ]); + + $service = $this->newDefaultSettingService( + client: $this->mockClient([VersionType::V2V1, $carrier, Request::CASH_ON_DELIVERY_COUNTRIES], $response), + serviceFactory: $this->mockServiceFactory($carrier, $response, $expectedResult), + ); + + $actualResult = $service->getCodCountries($carrier); + + self::assertSame($expectedResult, $actualResult); + } + + public function testGetCountries(): void + { + $carrier = CarrierType::CP; + $response = [ + 'service_types' => [ + [ + 'service_type' => 'RZP', + 'countries' => [ + 'SK', + 'CY', + 'MT', + ], + ], + ], + ]; + $expectedResult = new ServiceCollection($carrier, [ + new ServiceModel('RZP', null, countries: [ + 'SK', + 'CY', + 'MT', + ]), + ]); + + $service = $this->newDefaultSettingService( + client: $this->mockClient([VersionType::V2V1, $carrier, Request::COUNTRIES], $response), + serviceFactory: $this->mockServiceFactory($carrier, $response, $expectedResult), + ); + + $actualResult = $service->getCountries($carrier); + + self::assertSame($expectedResult, $actualResult); + } + + public function testGetCountriesData(): void + { + $response = [ + 'countries' => [ + [ + 'name_en' => 'Andorra', + 'name_cz' => 'Andorra', + 'iso_code' => 'AD', + 'phone_prefix' => '+376', + 'currency' => 'EUR', + 'continent' => 'Europe', + ], + ], + ]; + $expectedResult = new CountryCollection([ + new CountryModel( + [ + 'cz' => 'Andorra', + 'en' => 'Andorra', + ], + 'AD', + 'EUR', + [ + '+376', + ], + 'Europe', + ), + ]); + + $service = $this->newDefaultSettingService( + client: $this->mockClient([VersionType::V2V1, null, Request::GET_COUNTRIES_DATA], $response), + countryFactory: $this->mockCountryFactory($response, $expectedResult), + ); + + $actualResult = $service->getCountriesData(); + + self::assertSame($expectedResult, $actualResult); + } + + public function testGetPostCodes(): void + { + $carrier = CarrierType::CP; + $serviceType = ServiceModel::from(ServiceType::CP_DR); + $country = Country::CZECH_REPUBLIC; + $response = [ + 'units' => [ + [ + 'zip' => '79862', + '1B' => false, + 'country' => 'CZ', + ], + [ + 'zip' => '79907', + '1B' => false, + 'country' => 'CZ', + ], + ], + ]; + $expectedResult = new ArrayIterator([ + new PostCode( + $carrier, + $serviceType, + '79862', + null, + null, + 'CZ', + false, + ), + new PostCode( + $carrier, + $serviceType, + '79907', + null, + null, + 'CZ', + false, + ), + ]); + + $service = $this->newDefaultSettingService( + client: $this->mockClient([VersionType::V2V1, $carrier, Request::ZIP_CODES, [], sprintf('%s/%s', $serviceType->getValue(), $country)], $response), + postCodeFactory: $this->mockPostCodeFactory($carrier, $serviceType, $country, $response, $expectedResult), + ); + + $actualResult = $service->getPostCodes($carrier, $serviceType, $country); + + self::assertSame($expectedResult, $actualResult); + } + + public function testGetAdrUnits(): void + { + $carrier = CarrierType::TOPTRANS; + $response = [ + 'units' => [ + [ + 'id' => '2892', + 'code' => '3509', + 'name' => 'OBALY PRAZDNE, NEVYCISTENE', + 'class' => '9', + 'packaging' => null, + 'tunnel_code' => 'E', + 'transport_category' => '4', + ], + ], + ]; + $expectedResult = new AdrUnitCollection($carrier, [ + new AdrUnit( + $carrier, + '2892', + '3509', + 'OBALY PRAZDNE, NEVYCISTENE', + '9', + null, + 'E', + '4', + ), + ]); + + $service = $this->newDefaultSettingService( + client: $this->mockClient([VersionType::V2V1, $carrier, Request::FULL_ADR_UNITS], $response), + adrUnitFactory: $this->mockAdrUnitFactory($carrier, $response, $expectedResult), + ); + + $actualResult = $service->getAdrUnits($carrier); + + self::assertSame($expectedResult, $actualResult); + } + + public function testGetAddAttributes(): void + { + $carrier = CarrierType::CP; + $response = [ + 'attributes' => [ + [ + 'data_type' => 'string', + 'name' => 'eid', + 'max_length' => '40', + ], + [ + 'data_type' => 'plus_separated_values', + 'name' => 'services', + 'max_length' => null, + ], + ], + ]; + $expectedResult = new AttributeCollection($carrier, [ + new Attribute( + 'eid', + 'string', + '40', + ), + new Attribute( + 'services', + 'plus_separated_values', + null, + ), + ]); + + $service = $this->newDefaultSettingService( + client: $this->mockClient([VersionType::V2V1, $carrier, Request::ADD_ATTRIBUTES], $response), + attributeFactory: $this->mockAttributeFactory($carrier, $response, $expectedResult), + ); + + $actualResult = $service->getAddAttributes($carrier); + + self::assertSame($expectedResult, $actualResult); + } + + public function testGetAddServiceOptions(): void + { + $carrier = CarrierType::CP; + $response = [ + 'service_types' => [ + [ + 'service_type' => 'CE', + 'service_type_name' => 'CE - Obchodní balík do zahraničí', + 'services' => [ + [ + 'name' => 'Neskladně', + 'code' => '10', + ], + [ + 'name' => 'Zboží s VDD (pouze pro zásilky do ciziny s celní zónou)', + 'code' => '44', + ], + ], + ], + ], + ]; + $expectedResult = new ServiceCollection($carrier, [ + new ServiceModel('DR', null, options: new ServiceOptionCollection([ + new ServiceOption( + '10', + 'Neskladně', + ), + new ServiceOption( + '44', + 'Zboží s VDD (pouze pro zásilky do ciziny s celní zónou)', + ), + ])), + ]); + + $service = $this->newDefaultSettingService( + client: $this->mockClient([VersionType::V2V1, $carrier, Request::ADD_SERVICE_OPTIONS], $response), + serviceFactory: $this->mockServiceFactory($carrier, $response, $expectedResult), + ); + + $actualResult = $service->getAddServiceOptions($carrier); + + self::assertSame($expectedResult, $actualResult); + } + + public function testGetAddServiceOptionsForService(): void + { + $carrier = CarrierType::CP; + $serviceType = ServiceModel::from(ServiceType::CP_DR); + $response = [ + 'service_type' => 'CE', + 'service_type_name' => 'CE - Obchodní balík do zahraničí', + 'services' => [ + [ + 'name' => 'Neskladně', + 'code' => '10', + ], + [ + 'name' => 'Zboží s VDD (pouze pro zásilky do ciziny s celní zónou)', + 'code' => '44', + ], + ], + ]; + $expectedResult = new ServiceModel('DR', null, options: new ServiceOptionCollection([ + new ServiceOption( + '10', + 'Neskladně', + ), + new ServiceOption( + '44', + 'Zboží s VDD (pouze pro zásilky do ciziny s celní zónou)', + ), + ])); + + $service = $this->newDefaultSettingService( + client: $this->mockClient([VersionType::V2V1, $carrier, Request::ADD_SERVICE_OPTIONS, [], $serviceType->getValue()], $response), + serviceFactory: $this->mockServiceFactory($carrier, $response, $expectedResult), + ); + + $actualResult = $service->getAddServiceOptionsForService($carrier, $serviceType); + + self::assertSame($expectedResult, $actualResult); + } + + /** + * @param array $arguments + * @param array $response + */ + private function mockClient(array $arguments, array $response): Client + { + $arguments = array_replace([ + null, + null, + null, + [], + null, + true, + false, + ], $arguments); + + $client = $this->createMock(Client::class); + $client->expects(self::once())->method('call')->with(...$arguments)->willReturn($response); + + return $client; + } + + /** + * @param array $data + */ + private function mockServiceFactory(Carrier $carrier, array $data, ServiceCollection|Service $response): ServiceFactory + { + $serviceFactory = $this->createMock(ServiceFactory::class); + $serviceFactory->expects(self::once())->method($response instanceof Service ? 'create' : 'createCollection')->with($carrier, $data) + ->willReturn($response); + + return $serviceFactory; + } + + /** + * @param array $data + */ + private function mockUnitFactory(Carrier $carrier, array $data, UnitCollection $response): UnitFactory + { + $serviceFactory = $this->createMock(UnitFactory::class); + $serviceFactory->expects(self::once())->method('createCollection')->with($carrier, $data)->willReturn($response); + + return $serviceFactory; + } + + /** + * @param array $data + */ + private function mockCountryFactory(array $data, CountryCollection $response): CountryFactory + { + $serviceFactory = $this->createMock(CountryFactory::class); + $serviceFactory->expects(self::once())->method('createCollection')->with($data)->willReturn($response); + + return $serviceFactory; + } + + /** + * @param array $data + * @param iterable<\Inspirum\Balikobot\Model\PostCode\PostCode> $response + */ + private function mockPostCodeFactory( + Carrier $carrier, + Service $service, + ?string $country, + array $data, + iterable $response + ): PostCodeFactory { + $serviceFactory = $this->createMock(PostCodeFactory::class); + $serviceFactory->expects(self::once())->method('createIterator')->with($carrier, $service, $country, $data)->willReturn($response); + + return $serviceFactory; + } + + /** + * @param array $data + */ + private function mockAdrUnitFactory(Carrier $carrier, array $data, AdrUnitCollection $response): AdrUnitFactory + { + $serviceFactory = $this->createMock(AdrUnitFactory::class); + $serviceFactory->expects(self::once())->method('createCollection')->with($carrier, $data)->willReturn($response); + + return $serviceFactory; + } + + /** + * @param array $data + */ + private function mockAttributeFactory(Carrier $carrier, array $data, AttributeCollection $response): AttributeFactory + { + $serviceFactory = $this->createMock(AttributeFactory::class); + $serviceFactory->expects(self::once())->method('createCollection')->with($carrier, $data)->willReturn($response); + + return $serviceFactory; + } + + private function newDefaultSettingService( + Client $client, + ?ServiceFactory $serviceFactory = null, + ?UnitFactory $unitFactory = null, + ?CountryFactory $countryFactory = null, + ?PostCodeFactory $postCodeFactory = null, + ?AdrUnitFactory $adrUnitFactory = null, + ?AttributeFactory $attributeFactory = null, + ): DefaultSettingService { + return new DefaultSettingService( + $client, + $serviceFactory ?? $this->createMock(ServiceFactory::class), + $unitFactory ?? $this->createMock(UnitFactory::class), + $countryFactory ?? $this->createMock(CountryFactory::class), + $postCodeFactory ?? $this->createMock(PostCodeFactory::class), + $adrUnitFactory ?? $this->createMock(AdrUnitFactory::class), + $attributeFactory ?? $this->createMock(AttributeFactory::class), + ); + } +} diff --git a/tests/Unit/Service/DefaultTrackServiceTest.php b/tests/Unit/Service/DefaultTrackServiceTest.php index bca81e0..01383a4 100644 --- a/tests/Unit/Service/DefaultTrackServiceTest.php +++ b/tests/Unit/Service/DefaultTrackServiceTest.php @@ -6,9 +6,9 @@ use DateTimeImmutable; use Inspirum\Balikobot\Client\DefaultClient; -use Inspirum\Balikobot\Client\Request\CarrierType; +use Inspirum\Balikobot\Client\Request\Carrier; use Inspirum\Balikobot\Client\Response\Validator; -use Inspirum\Balikobot\Definitions\Carrier; +use Inspirum\Balikobot\Definitions\CarrierType; use Inspirum\Balikobot\Exception\BadRequestException; use Inspirum\Balikobot\Model\Package\Package; use Inspirum\Balikobot\Model\Package\PackageCollection; @@ -33,7 +33,7 @@ final class DefaultTrackServiceTest extends BaseTestCase public function testTrackPackagesByIds( int $statusCode, array $response, - CarrierType $carrier, + Carrier $carrier, array $carrierIds, StatusesCollection|Throwable|null $result, ?array $request = null, @@ -85,14 +85,14 @@ public function providesTestTrackPackagesByIds(): iterable ], ], ], - 'carrier' => Carrier::CP, + 'carrier' => CarrierType::CP, 'carrierIds' => ['1'], 'result' => new StatusesCollection( - Carrier::CP, + CarrierType::CP, [ - new Statuses(Carrier::CP, '1', [ + new Statuses(CarrierType::CP, '1', [ new Status( - Carrier::CP, + CarrierType::CP, '1', 2.2, 'Zásilka je v přepravě.', @@ -101,7 +101,7 @@ public function providesTestTrackPackagesByIds(): iterable new DateTimeImmutable('2018-11-07 14:15:01'), ), new Status( - Carrier::CP, + CarrierType::CP, '1', 1.2, 'Zásilka byla doručena příjemci.', @@ -119,7 +119,7 @@ public function providesTestTrackPackagesByIds(): iterable 'response' => [ 'status' => 200, ], - 'carrier' => Carrier::CP, + 'carrier' => CarrierType::CP, 'carrierIds' => ['1', '2'], 'result' => new BadRequestException([], 400), ]; @@ -180,7 +180,7 @@ public function providesTestTrackPackagesByIds(): iterable ], ], ], - 'carrier' => Carrier::CP, + 'carrier' => CarrierType::CP, 'carrierIds' => ['3', '4', '5'], 'result' => null, 'request' => [ @@ -251,7 +251,7 @@ public function providesTestTrackPackagesByIds(): iterable ], ], ], - 'carrier' => Carrier::CP, + 'carrier' => CarrierType::CP, 'carrierIds' => ['3', '4', '5'], 'result' => new BadRequestException([], 400), ]; @@ -277,7 +277,7 @@ public function providesTestTrackPackagesByIds(): iterable ], ], ], - 'carrier' => Carrier::PPL, + 'carrier' => CarrierType::PPL, 'carrierIds' => ['1', '3'], 'result' => new BadRequestException([], 400), ]; @@ -308,7 +308,7 @@ public function providesTestTrackPackagesByIds(): iterable ], ], ], - 'carrier' => Carrier::PPL, + 'carrier' => CarrierType::PPL, 'carrierIds' => ['1', '3'], 'result' => new BadRequestException([], 503), ]; @@ -346,7 +346,7 @@ public function providesTestTrackPackagesByIds(): iterable ], ], ], - 'carrier' => Carrier::CP, + 'carrier' => CarrierType::CP, 'carrierIds' => ['1', '2'], 'result' => new BadRequestException([], 400), ]; @@ -358,49 +358,49 @@ public function testTrackPackagesByIdsProxy(): void $expectedStatuses = [ new StatusesCollection( - Carrier::PPL, + CarrierType::PPL, [ - new Statuses(Carrier::PPL, '1234', [ - new Status(Carrier::PPL, '1234', 1.1, 'name', 'desc', 'event', new DateTimeImmutable()), + new Statuses(CarrierType::PPL, '1234', [ + new Status(CarrierType::PPL, '1234', 1.1, 'name', 'desc', 'event', new DateTimeImmutable()), ]), ] ), new StatusesCollection( - Carrier::CP, + CarrierType::CP, [ - new Statuses(Carrier::CP, '3456', [ - new Status(Carrier::CP, '3456', 1.1, 'name', 'desc', 'event', new DateTimeImmutable()), + new Statuses(CarrierType::CP, '3456', [ + new Status(CarrierType::CP, '3456', 1.1, 'name', 'desc', 'event', new DateTimeImmutable()), ]), ] ), new StatusesCollection( - Carrier::CP, + CarrierType::CP, [ - new Statuses(Carrier::CP, 'Z123', [ - new Status(Carrier::ZASILKOVNA, 'Z123', 1.1, 'name', 'desc', 'event', new DateTimeImmutable()), + new Statuses(CarrierType::CP, 'Z123', [ + new Status(CarrierType::ZASILKOVNA, 'Z123', 1.1, 'name', 'desc', 'event', new DateTimeImmutable()), ]), - new Statuses(Carrier::CP, 'Z234', [ - new Status(Carrier::ZASILKOVNA, 'Z234', 2.0, 'name', 'desc', 'event', new DateTimeImmutable()), + new Statuses(CarrierType::CP, 'Z234', [ + new Status(CarrierType::ZASILKOVNA, 'Z234', 2.0, 'name', 'desc', 'event', new DateTimeImmutable()), ]), ] ), ]; $service->expects(self::exactly(3))->method('trackPackagesByIds')->withConsecutive( - [Carrier::PPL, ['1234']], - [Carrier::CP, ['3456']], - [Carrier::ZASILKOVNA, ['Z123', 'Z234']], + [CarrierType::PPL, ['1234']], + [CarrierType::CP, ['3456']], + [CarrierType::ZASILKOVNA, ['Z123', 'Z234']], )->willReturn(...$expectedStatuses); - $actualStatuses = $service->trackPackage(new Package(Carrier::PPL, '1', '0001', '1234')); + $actualStatuses = $service->trackPackage(new Package(CarrierType::PPL, '1', '0001', '1234')); self::assertSame($expectedStatuses[0][0], $actualStatuses); - $actualStatuses = $service->trackPackageById(Carrier::CP, '3456'); + $actualStatuses = $service->trackPackageById(CarrierType::CP, '3456'); self::assertSame($expectedStatuses[1][0], $actualStatuses); $packages = new PackageCollection(); - $packages->add(new Package(Carrier::ZASILKOVNA, '1', '0001', 'Z123')); - $packages->add(new Package(Carrier::ZASILKOVNA, '2', '0001', 'Z234')); + $packages->add(new Package(CarrierType::ZASILKOVNA, '1', '0001', 'Z123')); + $packages->add(new Package(CarrierType::ZASILKOVNA, '2', '0001', 'Z234')); $actualStatuses = $service->trackPackages($packages); self::assertSame($expectedStatuses[2], $actualStatuses); @@ -416,7 +416,7 @@ public function testTrackPackagesByIdsProxy(): void public function testTrackPackagesLastStatusesByIds( int $statusCode, array $response, - CarrierType $carrier, + Carrier $carrier, array $carrierIds, StatusCollection|Throwable|null $result, ?array $request = null, @@ -458,13 +458,13 @@ public function providesTestTrackPackagesLastStatusesByIds(): iterable ], ], ], - 'carrier' => Carrier::CP, + 'carrier' => CarrierType::CP, 'carrierIds' => ['1', '2'], 'result' => new StatusCollection( - Carrier::CP, + CarrierType::CP, [ new Status( - Carrier::CP, + CarrierType::CP, '1', 1.2, 'Zásilka byla doručena příjemci.', @@ -473,7 +473,7 @@ public function providesTestTrackPackagesLastStatusesByIds(): iterable null, ), new Status( - Carrier::CP, + CarrierType::CP, '2', 2.2, 'Zásilka je v přepravě.', @@ -490,7 +490,7 @@ public function providesTestTrackPackagesLastStatusesByIds(): iterable 'response' => [ 'status' => 200, ], - 'carrier' => Carrier::CP, + 'carrier' => CarrierType::CP, 'carrierIds' => ['1', '2'], 'result' => new BadRequestException([], 400), ]; @@ -514,7 +514,7 @@ public function providesTestTrackPackagesLastStatusesByIds(): iterable ], ], ], - 'carrier' => Carrier::CP, + 'carrier' => CarrierType::CP, 'carrierIds' => ['1', '3'], 'result' => null, 'request' => [ @@ -546,7 +546,7 @@ public function providesTestTrackPackagesLastStatusesByIds(): iterable ], ], ], - 'carrier' => Carrier::CP, + 'carrier' => CarrierType::CP, 'carrierIds' => ['3', '4'], 'result' => new BadRequestException([], 400), ]; @@ -564,7 +564,7 @@ public function providesTestTrackPackagesLastStatusesByIds(): iterable ], ], ], - 'carrier' => Carrier::PPL, + 'carrier' => CarrierType::PPL, 'carrierIds' => ['1', '3'], 'result' => new BadRequestException([], 400), ]; @@ -586,7 +586,7 @@ public function providesTestTrackPackagesLastStatusesByIds(): iterable ], ], ], - 'carrier' => Carrier::PPL, + 'carrier' => CarrierType::PPL, 'carrierIds' => ['1', '3'], 'result' => new BadRequestException([], 404), ]; @@ -597,33 +597,33 @@ public function testTrackPackagesLastStatusesByIdsProxy(): void $service = $this->createPartialMock(DefaultTrackService::class, ['trackPackagesLastStatusesByIds']); $expectedStatuses = [ - new StatusCollection(Carrier::PPL, [ - 0 => new Status(Carrier::PPL, '1234', 1.1, 'name1', 'name1', 'event', null), + new StatusCollection(CarrierType::PPL, [ + 0 => new Status(CarrierType::PPL, '1234', 1.1, 'name1', 'name1', 'event', null), ]), - new StatusCollection(Carrier::CP, [ - 0 => new Status(Carrier::CP, '3456', 1.1, 'name1', 'name1', 'event', null), + new StatusCollection(CarrierType::CP, [ + 0 => new Status(CarrierType::CP, '3456', 1.1, 'name1', 'name1', 'event', null), ]), - new StatusCollection(Carrier::ZASILKOVNA, [ - 0 => new Status(Carrier::ZASILKOVNA, 'Z123', 1.1, 'name1', 'name1', 'event', null), - 1 => new Status(Carrier::ZASILKOVNA, 'Z234', 2.1, 'name2', 'name2', 'event', null), + new StatusCollection(CarrierType::ZASILKOVNA, [ + 0 => new Status(CarrierType::ZASILKOVNA, 'Z123', 1.1, 'name1', 'name1', 'event', null), + 1 => new Status(CarrierType::ZASILKOVNA, 'Z234', 2.1, 'name2', 'name2', 'event', null), ]), ]; $service->expects(self::exactly(3))->method('trackPackagesLastStatusesByIds')->withConsecutive( - [Carrier::PPL, ['1234']], - [Carrier::CP, ['3456']], - [Carrier::ZASILKOVNA, ['Z123', 'Z234']], + [CarrierType::PPL, ['1234']], + [CarrierType::CP, ['3456']], + [CarrierType::ZASILKOVNA, ['Z123', 'Z234']], )->willReturnOnConsecutiveCalls(...$expectedStatuses); - $actualStatuses = $service->trackPackageLastStatus(new Package(Carrier::PPL, '1', '0001', '1234')); + $actualStatuses = $service->trackPackageLastStatus(new Package(CarrierType::PPL, '1', '0001', '1234')); self::assertSame($expectedStatuses[0][0], $actualStatuses); - $actualStatuses = $service->trackPackageLastStatusById(Carrier::CP, '3456'); + $actualStatuses = $service->trackPackageLastStatusById(CarrierType::CP, '3456'); self::assertSame($expectedStatuses[1][0], $actualStatuses); $packages = new PackageCollection(); - $packages->add(new Package(Carrier::ZASILKOVNA, '1', '0001', 'Z123')); - $packages->add(new Package(Carrier::ZASILKOVNA, '2', '0001', 'Z234')); + $packages->add(new Package(CarrierType::ZASILKOVNA, '1', '0001', 'Z123')); + $packages->add(new Package(CarrierType::ZASILKOVNA, '2', '0001', 'Z234')); $actualStatuses = $service->trackPackagesLastStatuses($packages); self::assertSame($expectedStatuses[2], $actualStatuses);