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 |
||
| 20 | class Balikobot |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * Balikobot API |
||
| 24 | * |
||
| 25 | * @var \Inspirum\Balikobot\Services\Client |
||
| 26 | */ |
||
| 27 | private $client; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Balikobot constructor |
||
| 31 | * |
||
| 32 | * @param \Inspirum\Balikobot\Contracts\RequesterInterface $requester |
||
| 33 | */ |
||
| 34 | 76 | public function __construct(RequesterInterface $requester) |
|
| 38 | |||
| 39 | /** |
||
| 40 | * All supported shipper services |
||
| 41 | * |
||
| 42 | * @return array<string> |
||
| 43 | */ |
||
| 44 | 1 | public function getShippers(): array |
|
| 48 | |||
| 49 | /** |
||
| 50 | * Add packages |
||
| 51 | * |
||
| 52 | * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages |
||
| 53 | * |
||
| 54 | * @return \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection|\Inspirum\Balikobot\Model\Values\OrderedPackage[] |
||
| 55 | * |
||
| 56 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 57 | */ |
||
| 58 | 8 | public function addPackages(PackageCollection $packages): OrderedPackageCollection |
|
| 84 | |||
| 85 | /** |
||
| 86 | * Exports order into Balikobot system |
||
| 87 | * |
||
| 88 | * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages |
||
| 89 | * |
||
| 90 | * @return void |
||
| 91 | * |
||
| 92 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 93 | */ |
||
| 94 | 1 | public function dropPackages(OrderedPackageCollection $packages): void |
|
| 98 | |||
| 99 | /** |
||
| 100 | * Exports order into Balikobot system |
||
| 101 | * |
||
| 102 | * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package |
||
| 103 | * |
||
| 104 | * @return void |
||
| 105 | * |
||
| 106 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 107 | */ |
||
| 108 | 1 | public function dropPackage(OrderedPackage $package): void |
|
| 112 | |||
| 113 | /** |
||
| 114 | * Order shipment |
||
| 115 | * |
||
| 116 | * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages |
||
| 117 | * |
||
| 118 | * @return \Inspirum\Balikobot\Model\Values\OrderedShipment |
||
| 119 | * |
||
| 120 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 121 | */ |
||
| 122 | 2 | public function orderShipment(OrderedPackageCollection $packages): OrderedShipment |
|
| 134 | |||
| 135 | /** |
||
| 136 | * Track package |
||
| 137 | * |
||
| 138 | * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package |
||
| 139 | * |
||
| 140 | * @return array<\Inspirum\Balikobot\Model\Values\PackageStatus>|\Inspirum\Balikobot\Model\Values\PackageStatus[] |
||
| 141 | * |
||
| 142 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 143 | */ |
||
| 144 | 3 | public function trackPackage(OrderedPackage $package): array |
|
| 153 | |||
| 154 | /** |
||
| 155 | * Track packages |
||
| 156 | * |
||
| 157 | * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages |
||
| 158 | * |
||
| 159 | * @return array<array<\Inspirum\Balikobot\Model\Values\PackageStatus>>|\Inspirum\Balikobot\Model\Values\PackageStatus[][] |
||
| 160 | * |
||
| 161 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 162 | */ |
||
| 163 | 5 | public function trackPackages(OrderedPackageCollection $packages): array |
|
| 179 | |||
| 180 | /** |
||
| 181 | * Track package last status |
||
| 182 | * |
||
| 183 | * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package |
||
| 184 | * |
||
| 185 | * @return \Inspirum\Balikobot\Model\Values\PackageStatus |
||
| 186 | * |
||
| 187 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 188 | */ |
||
| 189 | 2 | public function trackPackageLastStatus(OrderedPackage $package): PackageStatus |
|
| 198 | |||
| 199 | /** |
||
| 200 | * Track package last status |
||
| 201 | * |
||
| 202 | * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages |
||
| 203 | * |
||
| 204 | * @return array<\Inspirum\Balikobot\Model\Values\PackageStatus>|\Inspirum\Balikobot\Model\Values\PackageStatus[] |
||
| 205 | * |
||
| 206 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 207 | */ |
||
| 208 | 4 | public function trackPackagesLastStatus(OrderedPackageCollection $packages): array |
|
| 220 | |||
| 221 | /** |
||
| 222 | * Get overview for given shipper |
||
| 223 | * |
||
| 224 | * @param string $shipper |
||
| 225 | * |
||
| 226 | * @return \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection|\Inspirum\Balikobot\Model\Values\OrderedPackage[] |
||
| 227 | * |
||
| 228 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 229 | */ |
||
| 230 | 2 | public function getOverview(string $shipper): OrderedPackageCollection |
|
| 247 | |||
| 248 | /** |
||
| 249 | * Get labels for orders |
||
| 250 | * |
||
| 251 | * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages |
||
| 252 | * |
||
| 253 | * @return string |
||
| 254 | * |
||
| 255 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 256 | */ |
||
| 257 | 2 | public function getLabels(OrderedPackageCollection $packages): string |
|
| 263 | |||
| 264 | /** |
||
| 265 | * Gets complete information about a package |
||
| 266 | * |
||
| 267 | * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package |
||
| 268 | * |
||
| 269 | * @return \Inspirum\Balikobot\Model\Values\Package |
||
| 270 | * |
||
| 271 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 272 | */ |
||
| 273 | 2 | public function getPackageInfo(OrderedPackage $package): Package |
|
| 294 | |||
| 295 | /** |
||
| 296 | * Gets complete information about a package |
||
| 297 | * |
||
| 298 | * @param string $shipper |
||
| 299 | * @param int $orderId |
||
| 300 | * |
||
| 301 | * @return \Inspirum\Balikobot\Model\Values\OrderedShipment |
||
| 302 | * |
||
| 303 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 304 | */ |
||
| 305 | 2 | public function getOrder(string $shipper, int $orderId): OrderedShipment |
|
| 317 | |||
| 318 | /** |
||
| 319 | * Returns available services for the given shipper |
||
| 320 | * |
||
| 321 | * @param string $shipper |
||
| 322 | * @param string|null $country |
||
| 323 | * |
||
| 324 | * @return array<string,string> |
||
| 325 | * |
||
| 326 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 327 | */ |
||
| 328 | 5 | public function getServices(string $shipper, string $country = null): array |
|
| 336 | |||
| 337 | /** |
||
| 338 | * Returns available B2A services for the given shipper |
||
| 339 | * |
||
| 340 | * @param string $shipper |
||
| 341 | * |
||
| 342 | * @return array<string,string> |
||
| 343 | * |
||
| 344 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 345 | */ |
||
| 346 | 2 | public function getB2AServices(string $shipper): array |
|
| 352 | |||
| 353 | /** |
||
| 354 | * Returns all manipulation units for the given shipper |
||
| 355 | * |
||
| 356 | * @param string $shipper |
||
| 357 | * @param bool $fullData |
||
| 358 | * |
||
| 359 | * @return array<string|array> |
||
| 360 | * |
||
| 361 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 362 | */ |
||
| 363 | 2 | public function getManipulationUnits(string $shipper, bool $fullData = false): array |
|
| 369 | |||
| 370 | /** |
||
| 371 | * Returns available manipulation units for the given shipper |
||
| 372 | * |
||
| 373 | * @param string $shipper |
||
| 374 | * @param bool $fullData |
||
| 375 | * |
||
| 376 | * @return array<string|array> |
||
| 377 | * |
||
| 378 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 379 | */ |
||
| 380 | 2 | public function getActivatedManipulationUnits(string $shipper, bool $fullData = false): array |
|
| 386 | |||
| 387 | /** |
||
| 388 | * Get all available branches |
||
| 389 | * |
||
| 390 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 391 | * |
||
| 392 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 393 | */ |
||
| 394 | 1 | public function getBranches(): iterable |
|
| 402 | |||
| 403 | /** |
||
| 404 | * Get all available branches for countries |
||
| 405 | * |
||
| 406 | * @param array<string> $countries |
||
| 407 | * |
||
| 408 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 409 | * |
||
| 410 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 411 | */ |
||
| 412 | 1 | public function getBranchesForCountries(array $countries): iterable |
|
| 420 | |||
| 421 | /** |
||
| 422 | * Get all available branches for given shipper |
||
| 423 | * |
||
| 424 | * @param string $shipper |
||
| 425 | * |
||
| 426 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 427 | * |
||
| 428 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 429 | */ |
||
| 430 | 2 | public function getBranchesForShipper(string $shipper): iterable |
|
| 438 | |||
| 439 | /** |
||
| 440 | * Get all available branches for given shipper for countries |
||
| 441 | * |
||
| 442 | * @param string $shipper |
||
| 443 | * @param array<string> $countries |
||
| 444 | * |
||
| 445 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 446 | * |
||
| 447 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 448 | */ |
||
| 449 | 2 | public function getBranchesForShipperForCountries(string $shipper, array $countries): iterable |
|
| 457 | |||
| 458 | /** |
||
| 459 | * Get services for shipper |
||
| 460 | * |
||
| 461 | * @param string $shipper |
||
| 462 | * |
||
| 463 | * @return array<string|null> |
||
| 464 | * |
||
| 465 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 466 | */ |
||
| 467 | 4 | private function getServicesForShipper(string $shipper): array |
|
| 473 | |||
| 474 | /** |
||
| 475 | * Get all available branches for given shipper and service type |
||
| 476 | * |
||
| 477 | * @param string $shipper |
||
| 478 | * @param string|null $service |
||
| 479 | * @param string|null $country |
||
| 480 | * |
||
| 481 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 482 | * |
||
| 483 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 484 | */ |
||
| 485 | 4 | public function getBranchesForShipperService(string $shipper, ?string $service, string $country = null): iterable |
|
| 502 | |||
| 503 | /** |
||
| 504 | * Get all available branches for given shipper and service type for countries |
||
| 505 | * |
||
| 506 | * @param string $shipper |
||
| 507 | * @param string|null $service |
||
| 508 | * @param array<string> $countries |
||
| 509 | * |
||
| 510 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 511 | * |
||
| 512 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 513 | */ |
||
| 514 | 3 | public function getBranchesForShipperServiceForCountries( |
|
| 527 | |||
| 528 | /** |
||
| 529 | * Get all available branches for given shipper and service type filtered by countries if possible |
||
| 530 | * |
||
| 531 | * @param string $shipper |
||
| 532 | * @param string|null $service |
||
| 533 | * @param array<string> $countries |
||
| 534 | * |
||
| 535 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 536 | * |
||
| 537 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 538 | */ |
||
| 539 | 3 | private function getAllBranchesForShipperServiceForCountries( |
|
| 554 | |||
| 555 | /** |
||
| 556 | * Get all available branches for given shipper |
||
| 557 | * |
||
| 558 | * @param string $shipper |
||
| 559 | * @param string $country |
||
| 560 | * @param string $city |
||
| 561 | * @param string|null $postcode |
||
| 562 | * @param string|null $street |
||
| 563 | * @param int|null $maxResults |
||
| 564 | * @param float|null $radius |
||
| 565 | * @param string|null $type |
||
| 566 | * |
||
| 567 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 568 | * |
||
| 569 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 570 | */ |
||
| 571 | 3 | public function getBranchesForLocation( |
|
| 596 | |||
| 597 | /** |
||
| 598 | * Returns list of countries where service with cash-on-delivery payment type is available in |
||
| 599 | * |
||
| 600 | * @param string $shipper |
||
| 601 | * |
||
| 602 | * @return array<array<int|string,array<string,array>>> |
||
| 603 | * |
||
| 604 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 605 | */ |
||
| 606 | 2 | public function getCodCountries(string $shipper): array |
|
| 612 | |||
| 613 | /** |
||
| 614 | * Returns list of countries where service is available in |
||
| 615 | * |
||
| 616 | * @param string $shipper |
||
| 617 | * |
||
| 618 | * @return array<array<int|string,string>> |
||
| 619 | * |
||
| 620 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 621 | */ |
||
| 622 | 2 | public function getCountries(string $shipper): array |
|
| 628 | |||
| 629 | /** |
||
| 630 | * Returns available branches for the given shipper and its service |
||
| 631 | * |
||
| 632 | * @param string $shipper |
||
| 633 | * @param string $service |
||
| 634 | * @param string|null $country |
||
| 635 | * |
||
| 636 | * @return \Generator|\Inspirum\Balikobot\Model\Values\PostCode[] |
||
| 637 | * |
||
| 638 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 639 | */ |
||
| 640 | 2 | public function getPostCodes(string $shipper, string $service, string $country = null): iterable |
|
| 648 | |||
| 649 | /** |
||
| 650 | * Check package(s) data |
||
| 651 | * |
||
| 652 | * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages |
||
| 653 | * |
||
| 654 | * @return void |
||
| 655 | * |
||
| 656 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 657 | */ |
||
| 658 | 1 | public function checkPackages(PackageCollection $packages): void |
|
| 662 | |||
| 663 | /** |
||
| 664 | * Returns available manipulation units for the given shipper |
||
| 665 | * |
||
| 666 | * @param string $shipper |
||
| 667 | * @param bool $fullData |
||
| 668 | * |
||
| 669 | * @return array<string|array> |
||
| 670 | * |
||
| 671 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 672 | */ |
||
| 673 | 2 | public function getAdrUnits(string $shipper, bool $fullData = false): array |
|
| 679 | |||
| 680 | /** |
||
| 681 | * Returns available activated services for the given shipper |
||
| 682 | * |
||
| 683 | * @param string $shipper |
||
| 684 | * |
||
| 685 | * @return array<string,mixed> |
||
| 686 | * |
||
| 687 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 688 | */ |
||
| 689 | 2 | public function getActivatedServices(string $shipper): array |
|
| 695 | |||
| 696 | /** |
||
| 697 | * Order shipments from place B (typically supplier / previous consignee) to place A (shipping point) |
||
| 698 | * |
||
| 699 | * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages |
||
| 700 | * |
||
| 701 | * @return \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection|\Inspirum\Balikobot\Model\Values\OrderedPackage[] |
||
| 702 | * |
||
| 703 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 704 | */ |
||
| 705 | 3 | public function orderB2AShipment(PackageCollection $packages): OrderedPackageCollection |
|
| 722 | |||
| 723 | /** |
||
| 724 | * Get PDF link with signed consignment delivery document by the recipient |
||
| 725 | * |
||
| 726 | * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package |
||
| 727 | * |
||
| 728 | * @return string |
||
| 729 | * |
||
| 730 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 731 | */ |
||
| 732 | 2 | public function getProofOfDelivery(OrderedPackage $package): string |
|
| 741 | |||
| 742 | /** |
||
| 743 | * Get array of PDF links with signed consignment delivery document by the recipient |
||
| 744 | * |
||
| 745 | * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages |
||
| 746 | * |
||
| 747 | * @return array<string> |
||
| 748 | * |
||
| 749 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 750 | */ |
||
| 751 | 4 | public function getProofOfDeliveries(OrderedPackageCollection $packages): array |
|
| 757 | |||
| 758 | /** |
||
| 759 | * Obtain the price of carriage at consignment level |
||
| 760 | * |
||
| 761 | * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages |
||
| 762 | * |
||
| 763 | * @return \Inspirum\Balikobot\Model\Aggregates\PackageTransportCostCollection|\Inspirum\Balikobot\Model\Values\PackageTransportCost[] |
||
| 764 | * |
||
| 765 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 766 | */ |
||
| 767 | 2 | public function getTransportCosts(PackageCollection $packages): PackageTransportCostCollection |
|
| 780 | |||
| 781 | /** |
||
| 782 | * Get information on individual countries of the world |
||
| 783 | * |
||
| 784 | * @return array<string,\Inspirum\Balikobot\Model\Values\Country>|\Inspirum\Balikobot\Model\Values\Country[] |
||
| 785 | * |
||
| 786 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 787 | */ |
||
| 788 | 2 | public function getCountriesData(): array |
|
| 800 | |||
| 801 | /** |
||
| 802 | * Method for obtaining news in the Balikobot API |
||
| 803 | * |
||
| 804 | * @return array<string,mixed> |
||
| 805 | * |
||
| 806 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 807 | */ |
||
| 808 | public function getChangelog(): array |
||
| 814 | } |
||
| 815 |