Complex classes like Balikobot often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Balikobot, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class Balikobot |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * Balikobot API |
||
| 23 | * |
||
| 24 | * @var \Inspirum\Balikobot\Services\Client |
||
| 25 | */ |
||
| 26 | private $client; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Balikobot constructor |
||
| 30 | * |
||
| 31 | * @param \Inspirum\Balikobot\Contracts\RequesterInterface $requester |
||
| 32 | */ |
||
| 33 | 73 | public function __construct(RequesterInterface $requester) |
|
| 34 | { |
||
| 35 | 73 | $this->client = new Client($requester); |
|
| 36 | 73 | } |
|
| 37 | |||
| 38 | /** |
||
| 39 | * All supported shipper services |
||
| 40 | * |
||
| 41 | * @return array<string> |
||
| 42 | */ |
||
| 43 | 1 | public function getShippers(): array |
|
| 44 | { |
||
| 45 | 1 | return Shipper::all(); |
|
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Add packages |
||
| 50 | * |
||
| 51 | * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages |
||
| 52 | * |
||
| 53 | * @return \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection|\Inspirum\Balikobot\Model\Values\OrderedPackage[] |
||
| 54 | * |
||
| 55 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 56 | */ |
||
| 57 | 8 | public function addPackages(PackageCollection $packages): OrderedPackageCollection |
|
| 58 | { |
||
| 59 | 8 | $usedRequestVersion = Shipper::resolveAddRequestVersion($packages->getShipper(), $packages->toArray()); |
|
| 60 | 8 | $labelsUrl = null; |
|
| 61 | |||
| 62 | 8 | $response = $this->client->addPackages( |
|
| 63 | 8 | $packages->getShipper(), |
|
| 64 | 8 | $packages->toArray(), |
|
| 65 | $usedRequestVersion, |
||
| 66 | $labelsUrl |
||
| 67 | ); |
||
| 68 | |||
| 69 | 8 | $orderedPackages = new OrderedPackageCollection(); |
|
| 70 | 8 | $orderedPackages->setLabelsUrl($labelsUrl); |
|
| 71 | |||
| 72 | 8 | foreach ($response as $i => $package) { |
|
| 73 | 8 | $orderedPackage = OrderedPackage::newInstanceFromData( |
|
| 74 | 8 | $packages->getShipper(), |
|
| 75 | 8 | $packages->offsetGet($i)->getEID(), |
|
| 76 | 8 | $package |
|
| 77 | ); |
||
| 78 | 8 | $orderedPackages->add($orderedPackage); |
|
| 79 | } |
||
| 80 | |||
| 81 | 8 | return $orderedPackages; |
|
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Exports order into Balikobot system |
||
| 86 | * |
||
| 87 | * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages |
||
| 88 | * |
||
| 89 | * @return void |
||
| 90 | * |
||
| 91 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 92 | */ |
||
| 93 | 1 | public function dropPackages(OrderedPackageCollection $packages): void |
|
| 94 | { |
||
| 95 | 1 | $this->client->dropPackages($packages->getShipper(), $packages->getPackageIds()); |
|
| 96 | 1 | } |
|
| 97 | |||
| 98 | /** |
||
| 99 | * Exports order into Balikobot system |
||
| 100 | * |
||
| 101 | * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package |
||
| 102 | * |
||
| 103 | * @return void |
||
| 104 | * |
||
| 105 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 106 | */ |
||
| 107 | 1 | public function dropPackage(OrderedPackage $package): void |
|
| 108 | { |
||
| 109 | 1 | $this->client->dropPackage($package->getShipper(), $package->getPackageId()); |
|
| 110 | 1 | } |
|
| 111 | |||
| 112 | /** |
||
| 113 | * Order shipment |
||
| 114 | * |
||
| 115 | * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages |
||
| 116 | * |
||
| 117 | * @return \Inspirum\Balikobot\Model\Values\OrderedShipment |
||
| 118 | * |
||
| 119 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 120 | */ |
||
| 121 | 2 | public function orderShipment(OrderedPackageCollection $packages): OrderedShipment |
|
| 122 | { |
||
| 123 | 2 | $response = $this->client->orderShipment($packages->getShipper(), $packages->getPackageIds()); |
|
| 124 | |||
| 125 | 2 | $orderedShipment = OrderedShipment::newInstanceFromData( |
|
| 126 | 2 | $packages->getShipper(), |
|
| 127 | 2 | $packages->getPackageIds(), |
|
| 128 | 2 | $response |
|
| 129 | ); |
||
| 130 | |||
| 131 | 2 | return $orderedShipment; |
|
| 132 | } |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Track package |
||
| 136 | * |
||
| 137 | * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package |
||
| 138 | * |
||
| 139 | * @return array<\Inspirum\Balikobot\Model\Values\PackageStatus>|\Inspirum\Balikobot\Model\Values\PackageStatus[] |
||
| 140 | * |
||
| 141 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 142 | */ |
||
| 143 | 2 | public function trackPackage(OrderedPackage $package): array |
|
| 144 | { |
||
| 145 | 2 | $packages = new OrderedPackageCollection(); |
|
| 146 | 2 | $packages->add($package); |
|
| 147 | |||
| 148 | 2 | $response = $this->trackPackages($packages); |
|
| 149 | |||
| 150 | 2 | return $response[0]; |
|
| 151 | } |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Track packages |
||
| 155 | * |
||
| 156 | * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages |
||
| 157 | * |
||
| 158 | * @return array<array<\Inspirum\Balikobot\Model\Values\PackageStatus>>|\Inspirum\Balikobot\Model\Values\PackageStatus[][] |
||
| 159 | * |
||
| 160 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 161 | */ |
||
| 162 | 4 | public function trackPackages(OrderedPackageCollection $packages): array |
|
| 163 | { |
||
| 164 | 4 | $response = $this->client->trackPackages($packages->getShipper(), $packages->getCarrierIds()); |
|
| 165 | |||
| 166 | 4 | $statuses = []; |
|
| 167 | |||
| 168 | 4 | foreach ($response as $i => $responseStatuses) { |
|
| 169 | 4 | $statuses[$i] = []; |
|
| 170 | |||
| 171 | 4 | foreach ($responseStatuses as $status) { |
|
| 172 | 4 | $statuses[$i][] = PackageStatus::newInstanceFromData($status); |
|
| 173 | } |
||
| 174 | } |
||
| 175 | |||
| 176 | 4 | return $statuses; |
|
| 177 | } |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Track package last status |
||
| 181 | * |
||
| 182 | * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package |
||
| 183 | * |
||
| 184 | * @return \Inspirum\Balikobot\Model\Values\PackageStatus |
||
| 185 | * |
||
| 186 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 187 | */ |
||
| 188 | 2 | public function trackPackageLastStatus(OrderedPackage $package): PackageStatus |
|
| 189 | { |
||
| 190 | 2 | $packages = new OrderedPackageCollection(); |
|
| 191 | 2 | $packages->add($package); |
|
| 192 | |||
| 193 | 2 | $response = $this->trackPackagesLastStatus($packages); |
|
| 194 | |||
| 195 | 2 | return $response[0]; |
|
| 196 | } |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Track package last status |
||
| 200 | * |
||
| 201 | * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages |
||
| 202 | * |
||
| 203 | * @return array<\Inspirum\Balikobot\Model\Values\PackageStatus>|\Inspirum\Balikobot\Model\Values\PackageStatus[] |
||
| 204 | * |
||
| 205 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 206 | */ |
||
| 207 | 4 | public function trackPackagesLastStatus(OrderedPackageCollection $packages): array |
|
| 208 | { |
||
| 209 | 4 | $response = $this->client->trackPackagesLastStatus($packages->getShipper(), $packages->getCarrierIds()); |
|
| 210 | |||
| 211 | 4 | $statuses = []; |
|
| 212 | |||
| 213 | 4 | foreach ($response as $status) { |
|
| 214 | 4 | $statuses[] = PackageStatus::newInstanceFromData($status); |
|
| 215 | } |
||
| 216 | |||
| 217 | 4 | return $statuses; |
|
| 218 | } |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Get overview for given shipper |
||
| 222 | * |
||
| 223 | * @param string $shipper |
||
| 224 | * |
||
| 225 | * @return \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection|\Inspirum\Balikobot\Model\Values\OrderedPackage[] |
||
| 226 | * |
||
| 227 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 228 | */ |
||
| 229 | 2 | public function getOverview(string $shipper): OrderedPackageCollection |
|
| 230 | { |
||
| 231 | 2 | $response = $this->client->getOverview($shipper); |
|
| 232 | |||
| 233 | 2 | $orderedPackages = new OrderedPackageCollection(); |
|
| 234 | |||
| 235 | 2 | foreach ($response as $package) { |
|
| 236 | 1 | $orderedPackage = OrderedPackage::newInstanceFromData( |
|
| 237 | 1 | $shipper, |
|
| 238 | 1 | (string) $package['eshop_id'], |
|
| 239 | 1 | $package |
|
| 240 | ); |
||
| 241 | 1 | $orderedPackages->add($orderedPackage); |
|
| 242 | } |
||
| 243 | |||
| 244 | 2 | return $orderedPackages; |
|
| 245 | } |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Get labels for orders |
||
| 249 | * |
||
| 250 | * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages |
||
| 251 | * |
||
| 252 | * @return string |
||
| 253 | * |
||
| 254 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 255 | */ |
||
| 256 | 2 | public function getLabels(OrderedPackageCollection $packages): string |
|
| 257 | { |
||
| 258 | 2 | $labelUrl = $this->client->getLabels($packages->getShipper(), $packages->getPackageIds()); |
|
| 259 | |||
| 260 | 2 | return $labelUrl; |
|
| 261 | } |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Gets complete information about a package |
||
| 265 | * |
||
| 266 | * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package |
||
| 267 | * |
||
| 268 | * @return \Inspirum\Balikobot\Model\Values\Package |
||
| 269 | * |
||
| 270 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 271 | */ |
||
| 272 | 2 | public function getPackageInfo(OrderedPackage $package): Package |
|
| 273 | { |
||
| 274 | 2 | $response = $this->client->getPackageInfo($package->getShipper(), $package->getPackageId()); |
|
| 275 | |||
| 276 | 2 | unset($response['package_id']); |
|
| 277 | 2 | unset($response['eshop_id']); |
|
| 278 | 2 | unset($response['carrier_id']); |
|
| 279 | 2 | unset($response['track_url']); |
|
| 280 | 2 | unset($response['label_url']); |
|
| 281 | 2 | unset($response['carrier_id_swap']); |
|
| 282 | 2 | unset($response['pieces']); |
|
| 283 | |||
| 284 | 2 | $options = $response; |
|
| 285 | 2 | $options[Option::EID] = $package->getBatchId(); |
|
| 286 | |||
| 287 | 2 | $package = new Package($options); |
|
| 288 | |||
| 289 | 2 | return $package; |
|
| 290 | } |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Gets complete information about a package |
||
| 294 | * |
||
| 295 | * @param string $shipper |
||
| 296 | * @param int $orderId |
||
| 297 | * |
||
| 298 | * @return \Inspirum\Balikobot\Model\Values\OrderedShipment |
||
| 299 | * |
||
| 300 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 301 | */ |
||
| 302 | 2 | public function getOrder(string $shipper, int $orderId): OrderedShipment |
|
| 303 | { |
||
| 304 | 2 | $response = $this->client->getOrder($shipper, $orderId); |
|
| 305 | |||
| 306 | 2 | $orderedShipment = OrderedShipment::newInstanceFromData( |
|
| 307 | 2 | $shipper, |
|
| 308 | 2 | $response['package_ids'], |
|
| 309 | 2 | $response |
|
| 310 | ); |
||
| 311 | |||
| 312 | 2 | return $orderedShipment; |
|
| 313 | } |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Returns available services for the given shipper |
||
| 317 | * |
||
| 318 | * @param string $shipper |
||
| 319 | * @param string|null $country |
||
| 320 | * |
||
| 321 | * @return array<string,string> |
||
| 322 | * |
||
| 323 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 324 | */ |
||
| 325 | 5 | public function getServices(string $shipper, string $country = null): array |
|
| 326 | { |
||
| 327 | 5 | $usedRequestVersion = Shipper::resolveServicesRequestVersion($shipper); |
|
| 328 | |||
| 329 | 5 | $services = $this->client->getServices($shipper, $country, $usedRequestVersion); |
|
| 330 | |||
| 331 | 4 | return $services; |
|
| 332 | } |
||
| 333 | |||
| 334 | /** |
||
| 335 | * Returns available B2A services for the given shipper |
||
| 336 | * |
||
| 337 | * @param string $shipper |
||
| 338 | * |
||
| 339 | * @return array<string,string> |
||
| 340 | * |
||
| 341 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 342 | */ |
||
| 343 | 2 | public function getB2AServices(string $shipper): array |
|
| 349 | |||
| 350 | /** |
||
| 351 | * Returns all manipulation units for the given shipper |
||
| 352 | * |
||
| 353 | * @param string $shipper |
||
| 354 | * |
||
| 355 | * @return array<string> |
||
| 356 | * |
||
| 357 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 358 | */ |
||
| 359 | 2 | public function getManipulationUnits(string $shipper): array |
|
| 360 | { |
||
| 361 | 2 | $units = $this->client->getManipulationUnits($shipper); |
|
| 362 | |||
| 363 | 2 | return $units; |
|
| 364 | } |
||
| 365 | |||
| 366 | /** |
||
| 367 | * Returns available manipulation units for the given shipper |
||
| 368 | * |
||
| 369 | * @param string $shipper |
||
| 370 | * |
||
| 371 | * @return array<string> |
||
| 372 | * |
||
| 373 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 374 | */ |
||
| 375 | 2 | public function getActivatedManipulationUnits(string $shipper): array |
|
| 381 | |||
| 382 | /** |
||
| 383 | * Get all available branches |
||
| 384 | * |
||
| 385 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 386 | * |
||
| 387 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 388 | */ |
||
| 389 | 1 | public function getBranches(): iterable |
|
| 390 | { |
||
| 391 | 1 | $shippers = $this->getShippers(); |
|
| 392 | |||
| 393 | 1 | foreach ($shippers as $shipper) { |
|
| 394 | 1 | yield from $this->getBranchesForShipper($shipper); |
|
| 395 | } |
||
| 396 | 1 | } |
|
| 397 | |||
| 398 | /** |
||
| 399 | * Get all available branches for countries |
||
| 400 | * |
||
| 401 | * @param array<string> $countries |
||
| 402 | * |
||
| 403 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 404 | * |
||
| 405 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 406 | */ |
||
| 407 | 1 | public function getBranchesForCountries(array $countries): iterable |
|
| 415 | |||
| 416 | /** |
||
| 417 | * Get all available branches for given shipper |
||
| 418 | * |
||
| 419 | * @param string $shipper |
||
| 420 | * |
||
| 421 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 422 | * |
||
| 423 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 424 | */ |
||
| 425 | 2 | public function getBranchesForShipper(string $shipper): iterable |
|
| 426 | { |
||
| 427 | 2 | $services = $this->getServicesForShipper($shipper); |
|
| 428 | |||
| 429 | 2 | foreach ($services as $service) { |
|
| 430 | 2 | yield from $this->getBranchesForShipperService($shipper, $service); |
|
| 431 | } |
||
| 432 | 2 | } |
|
| 433 | |||
| 434 | /** |
||
| 435 | * Get all available branches for given shipper for countries |
||
| 436 | * |
||
| 437 | * @param string $shipper |
||
| 438 | * @param array<string> $countries |
||
| 439 | * |
||
| 440 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 441 | * |
||
| 442 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 443 | */ |
||
| 444 | 2 | public function getBranchesForShipperForCountries(string $shipper, array $countries): iterable |
|
| 452 | |||
| 453 | /** |
||
| 454 | * Get services for shipper |
||
| 455 | * |
||
| 456 | * @param string $shipper |
||
| 457 | * |
||
| 458 | * @return array<string|null> |
||
| 459 | * |
||
| 460 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 461 | */ |
||
| 462 | 4 | private function getServicesForShipper(string $shipper): array |
|
| 468 | |||
| 469 | /** |
||
| 470 | * Get all available branches for given shipper and service type |
||
| 471 | * |
||
| 472 | * @param string $shipper |
||
| 473 | * @param string|null $service |
||
| 474 | * @param string|null $country |
||
| 475 | * |
||
| 476 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 477 | * |
||
| 478 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 479 | */ |
||
| 480 | 4 | public function getBranchesForShipperService(string $shipper, ?string $service, string $country = null): iterable |
|
| 481 | { |
||
| 482 | 4 | $useFullbranchRequest = Shipper::hasFullBranchesSupport($shipper, $service); |
|
| 483 | 4 | $usedRequestVersion = Shipper::resolveBranchesRequestVersion($shipper, $service); |
|
| 484 | |||
| 485 | 4 | $branches = $this->client->getBranches( |
|
| 486 | 4 | $shipper, |
|
| 487 | $service, |
||
| 488 | $useFullbranchRequest, |
||
| 489 | $country, |
||
| 490 | $usedRequestVersion |
||
| 491 | ); |
||
| 492 | |||
| 493 | 4 | foreach ($branches as $branch) { |
|
| 494 | 2 | yield Branch::newInstanceFromData($shipper, $service, $branch); |
|
| 495 | } |
||
| 496 | 4 | } |
|
| 497 | |||
| 498 | /** |
||
| 499 | * Get all available branches for given shipper and service type for countries |
||
| 500 | * |
||
| 501 | * @param string $shipper |
||
| 502 | * @param string|null $service |
||
| 503 | * @param array<string> $countries |
||
| 504 | * |
||
| 505 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 506 | * |
||
| 507 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 508 | */ |
||
| 509 | 3 | public function getBranchesForShipperServiceForCountries( |
|
| 522 | |||
| 523 | /** |
||
| 524 | * Get all available branches for given shipper and service type filtered by countries if possible |
||
| 525 | * |
||
| 526 | * @param string $shipper |
||
| 527 | * @param string|null $service |
||
| 528 | * @param array<string> $countries |
||
| 529 | * |
||
| 530 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 531 | * |
||
| 532 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 533 | */ |
||
| 534 | 3 | private function getAllBranchesForShipperServiceForCountries( |
|
| 549 | |||
| 550 | /** |
||
| 551 | * Get all available branches for given shipper |
||
| 552 | * |
||
| 553 | * @param string $shipper |
||
| 554 | * @param string $country |
||
| 555 | * @param string $city |
||
| 556 | * @param string|null $postcode |
||
| 557 | * @param string|null $street |
||
| 558 | * @param int|null $maxResults |
||
| 559 | * @param float|null $radius |
||
| 560 | * @param string|null $type |
||
| 561 | * |
||
| 562 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 563 | * |
||
| 564 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 565 | */ |
||
| 566 | 3 | public function getBranchesForLocation( |
|
| 591 | |||
| 592 | /** |
||
| 593 | * Returns list of countries where service with cash-on-delivery payment type is available in |
||
| 594 | * |
||
| 595 | * @param string $shipper |
||
| 596 | * |
||
| 597 | * @return array<array<int|string,array<string,array>>> |
||
| 598 | * |
||
| 599 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 600 | */ |
||
| 601 | 2 | public function getCodCountries(string $shipper): array |
|
| 607 | |||
| 608 | /** |
||
| 609 | * Returns list of countries where service is available in |
||
| 610 | * |
||
| 611 | * @param string $shipper |
||
| 612 | * |
||
| 613 | * @return array<array<int|string,string>> |
||
| 614 | * |
||
| 615 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 616 | */ |
||
| 617 | 2 | public function getCountries(string $shipper): array |
|
| 618 | { |
||
| 619 | 2 | $countries = $this->client->getCountries($shipper); |
|
| 620 | |||
| 621 | 2 | return $countries; |
|
| 622 | } |
||
| 623 | |||
| 624 | /** |
||
| 625 | * Returns available branches for the given shipper and its service |
||
| 626 | * |
||
| 627 | * @param string $shipper |
||
| 628 | * @param string $service |
||
| 629 | * @param string|null $country |
||
| 630 | * |
||
| 631 | * @return \Generator|\Inspirum\Balikobot\Model\Values\PostCode[] |
||
| 632 | * |
||
| 633 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 634 | */ |
||
| 635 | 2 | public function getPostCodes(string $shipper, string $service, string $country = null): iterable |
|
| 636 | { |
||
| 637 | 2 | $postCodes = $this->client->getPostCodes($shipper, $service, $country); |
|
| 638 | |||
| 639 | 2 | foreach ($postCodes as $postcode) { |
|
| 640 | 1 | yield PostCode::newInstanceFromData($shipper, $service, $postcode); |
|
| 641 | } |
||
| 642 | 2 | } |
|
| 643 | |||
| 644 | /** |
||
| 645 | * Check package(s) data |
||
| 646 | * |
||
| 647 | * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages |
||
| 648 | * |
||
| 649 | * @return void |
||
| 650 | * |
||
| 651 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 652 | */ |
||
| 653 | 1 | public function checkPackages(PackageCollection $packages): void |
|
| 654 | { |
||
| 655 | 1 | $this->client->checkPackages($packages->getShipper(), $packages->toArray()); |
|
| 656 | 1 | } |
|
| 657 | |||
| 658 | /** |
||
| 659 | * Returns available manipulation units for the given shipper |
||
| 660 | * |
||
| 661 | * @param string $shipper |
||
| 662 | * |
||
| 663 | * @return array<string> |
||
| 664 | * |
||
| 665 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 666 | */ |
||
| 667 | 2 | public function getAdrUnits(string $shipper): array |
|
| 668 | { |
||
| 669 | 2 | $units = $this->client->getAdrUnits($shipper); |
|
| 670 | |||
| 671 | 2 | return $units; |
|
| 672 | } |
||
| 673 | |||
| 674 | /** |
||
| 675 | * Returns available activated services for the given shipper |
||
| 676 | * |
||
| 677 | * @param string $shipper |
||
| 678 | * |
||
| 679 | * @return array<string,mixed> |
||
| 680 | * |
||
| 681 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 682 | */ |
||
| 683 | 2 | public function getActivatedServices(string $shipper): array |
|
| 689 | |||
| 690 | /** |
||
| 691 | * Order shipments from place B (typically supplier / previous consignee) to place A (shipping point) |
||
| 692 | * |
||
| 693 | * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages |
||
| 694 | * |
||
| 695 | * @return \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection|\Inspirum\Balikobot\Model\Values\OrderedPackage[] |
||
| 696 | * |
||
| 697 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 698 | */ |
||
| 699 | 3 | public function orderB2AShipment(PackageCollection $packages): OrderedPackageCollection |
|
| 716 | |||
| 717 | /** |
||
| 718 | * Get PDF link with signed consignment delivery document by the recipient |
||
| 719 | * |
||
| 720 | * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package |
||
| 721 | * |
||
| 722 | * @return string |
||
| 723 | * |
||
| 724 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 725 | */ |
||
| 726 | 2 | public function getProofOfDelivery(OrderedPackage $package): string |
|
| 735 | |||
| 736 | /** |
||
| 737 | * Get array of PDF links with signed consignment delivery document by the recipient |
||
| 738 | * |
||
| 739 | * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages |
||
| 740 | * |
||
| 741 | * @return array<string> |
||
| 742 | * |
||
| 743 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 744 | */ |
||
| 745 | 4 | public function getProofOfDeliveries(OrderedPackageCollection $packages): array |
|
| 751 | |||
| 752 | /** |
||
| 753 | * Obtain the price of carriage at consignment level |
||
| 754 | * |
||
| 755 | * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages |
||
| 756 | * |
||
| 757 | * @return \Inspirum\Balikobot\Model\Aggregates\PackageTransportCostCollection|\Inspirum\Balikobot\Model\Values\PackageTransportCost[] |
||
| 758 | * |
||
| 759 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 760 | */ |
||
| 761 | 2 | public function getTransportCosts(PackageCollection $packages): PackageTransportCostCollection |
|
| 774 | } |
||
| 775 |