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 |
|
| 292 | |||
| 293 | /** |
||
| 294 | * Gets complete information about a package |
||
| 295 | * |
||
| 296 | * @param string $shipper |
||
| 297 | * @param int $orderId |
||
| 298 | * |
||
| 299 | * @return \Inspirum\Balikobot\Model\Values\OrderedShipment |
||
| 300 | * |
||
| 301 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 302 | */ |
||
| 303 | 2 | public function getOrder(string $shipper, int $orderId): OrderedShipment |
|
| 315 | |||
| 316 | /** |
||
| 317 | * Returns available services for the given shipper |
||
| 318 | * |
||
| 319 | * @param string $shipper |
||
| 320 | * @param string|null $country |
||
| 321 | * |
||
| 322 | * @return array<string,string> |
||
| 323 | * |
||
| 324 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 325 | */ |
||
| 326 | 5 | public function getServices(string $shipper, string $country = null): array |
|
| 334 | |||
| 335 | /** |
||
| 336 | * Returns available B2A services for the given shipper |
||
| 337 | * |
||
| 338 | * @param string $shipper |
||
| 339 | * |
||
| 340 | * @return array<string,string> |
||
| 341 | * |
||
| 342 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 343 | */ |
||
| 344 | 2 | public function getB2AServices(string $shipper): array |
|
| 350 | |||
| 351 | /** |
||
| 352 | * Returns all manipulation units for the given shipper |
||
| 353 | * |
||
| 354 | * @param string $shipper |
||
| 355 | * @param bool $fullData |
||
| 356 | * |
||
| 357 | * @return array<string|array> |
||
| 358 | * |
||
| 359 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 360 | */ |
||
| 361 | 2 | public function getManipulationUnits(string $shipper, bool $fullData = false): array |
|
| 367 | |||
| 368 | /** |
||
| 369 | * Returns available manipulation units for the given shipper |
||
| 370 | * |
||
| 371 | * @param string $shipper |
||
| 372 | * @param bool $fullData |
||
| 373 | * |
||
| 374 | * @return array<string|array> |
||
| 375 | * |
||
| 376 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 377 | */ |
||
| 378 | 2 | public function getActivatedManipulationUnits(string $shipper, bool $fullData = false): array |
|
| 384 | |||
| 385 | /** |
||
| 386 | * Get all available branches |
||
| 387 | * |
||
| 388 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 389 | * |
||
| 390 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 391 | */ |
||
| 392 | 1 | public function getBranches(): iterable |
|
| 400 | |||
| 401 | /** |
||
| 402 | * Get all available branches for countries |
||
| 403 | * |
||
| 404 | * @param array<string> $countries |
||
| 405 | * |
||
| 406 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 407 | * |
||
| 408 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 409 | */ |
||
| 410 | 1 | public function getBranchesForCountries(array $countries): iterable |
|
| 418 | |||
| 419 | /** |
||
| 420 | * Get all available branches for given shipper |
||
| 421 | * |
||
| 422 | * @param string $shipper |
||
| 423 | * |
||
| 424 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 425 | * |
||
| 426 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 427 | */ |
||
| 428 | 2 | public function getBranchesForShipper(string $shipper): iterable |
|
| 436 | |||
| 437 | /** |
||
| 438 | * Get all available branches for given shipper for countries |
||
| 439 | * |
||
| 440 | * @param string $shipper |
||
| 441 | * @param array<string> $countries |
||
| 442 | * |
||
| 443 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 444 | * |
||
| 445 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 446 | */ |
||
| 447 | 2 | public function getBranchesForShipperForCountries(string $shipper, array $countries): iterable |
|
| 455 | |||
| 456 | /** |
||
| 457 | * Get services for shipper |
||
| 458 | * |
||
| 459 | * @param string $shipper |
||
| 460 | * |
||
| 461 | * @return array<string|null> |
||
| 462 | * |
||
| 463 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 464 | */ |
||
| 465 | 4 | private function getServicesForShipper(string $shipper): array |
|
| 471 | |||
| 472 | /** |
||
| 473 | * Get all available branches for given shipper and service type |
||
| 474 | * |
||
| 475 | * @param string $shipper |
||
| 476 | * @param string|null $service |
||
| 477 | * @param string|null $country |
||
| 478 | * |
||
| 479 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 480 | * |
||
| 481 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 482 | */ |
||
| 483 | 4 | public function getBranchesForShipperService(string $shipper, ?string $service, string $country = null): iterable |
|
| 500 | |||
| 501 | /** |
||
| 502 | * Get all available branches for given shipper and service type for countries |
||
| 503 | * |
||
| 504 | * @param string $shipper |
||
| 505 | * @param string|null $service |
||
| 506 | * @param array<string> $countries |
||
| 507 | * |
||
| 508 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 509 | * |
||
| 510 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 511 | */ |
||
| 512 | 3 | public function getBranchesForShipperServiceForCountries( |
|
| 525 | |||
| 526 | /** |
||
| 527 | * Get all available branches for given shipper and service type filtered by countries if possible |
||
| 528 | * |
||
| 529 | * @param string $shipper |
||
| 530 | * @param string|null $service |
||
| 531 | * @param array<string> $countries |
||
| 532 | * |
||
| 533 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 534 | * |
||
| 535 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 536 | */ |
||
| 537 | 3 | private function getAllBranchesForShipperServiceForCountries( |
|
| 552 | |||
| 553 | /** |
||
| 554 | * Get all available branches for given shipper |
||
| 555 | * |
||
| 556 | * @param string $shipper |
||
| 557 | * @param string $country |
||
| 558 | * @param string $city |
||
| 559 | * @param string|null $postcode |
||
| 560 | * @param string|null $street |
||
| 561 | * @param int|null $maxResults |
||
| 562 | * @param float|null $radius |
||
| 563 | * @param string|null $type |
||
| 564 | * |
||
| 565 | * @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
||
| 566 | * |
||
| 567 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 568 | */ |
||
| 569 | 3 | public function getBranchesForLocation( |
|
| 594 | |||
| 595 | /** |
||
| 596 | * Returns list of countries where service with cash-on-delivery payment type is available in |
||
| 597 | * |
||
| 598 | * @param string $shipper |
||
| 599 | * |
||
| 600 | * @return array<array<int|string,array<string,array>>> |
||
| 601 | * |
||
| 602 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 603 | */ |
||
| 604 | 2 | public function getCodCountries(string $shipper): array |
|
| 610 | |||
| 611 | /** |
||
| 612 | * Returns list of countries where service is available in |
||
| 613 | * |
||
| 614 | * @param string $shipper |
||
| 615 | * |
||
| 616 | * @return array<array<int|string,string>> |
||
| 617 | * |
||
| 618 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 619 | */ |
||
| 620 | 2 | public function getCountries(string $shipper): array |
|
| 626 | |||
| 627 | /** |
||
| 628 | * Returns available branches for the given shipper and its service |
||
| 629 | * |
||
| 630 | * @param string $shipper |
||
| 631 | * @param string $service |
||
| 632 | * @param string|null $country |
||
| 633 | * |
||
| 634 | * @return \Generator|\Inspirum\Balikobot\Model\Values\PostCode[] |
||
| 635 | * |
||
| 636 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 637 | */ |
||
| 638 | 2 | public function getPostCodes(string $shipper, string $service, string $country = null): iterable |
|
| 646 | |||
| 647 | /** |
||
| 648 | * Check package(s) data |
||
| 649 | * |
||
| 650 | * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages |
||
| 651 | * |
||
| 652 | * @return void |
||
| 653 | * |
||
| 654 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 655 | */ |
||
| 656 | 1 | public function checkPackages(PackageCollection $packages): void |
|
| 660 | |||
| 661 | /** |
||
| 662 | * Returns available manipulation units for the given shipper |
||
| 663 | * |
||
| 664 | * @param string $shipper |
||
| 665 | * @param bool $fullData |
||
| 666 | * |
||
| 667 | * @return array<string|array> |
||
| 668 | * |
||
| 669 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 670 | */ |
||
| 671 | 2 | public function getAdrUnits(string $shipper, bool $fullData = false): array |
|
| 677 | |||
| 678 | /** |
||
| 679 | * Returns available activated services for the given shipper |
||
| 680 | * |
||
| 681 | * @param string $shipper |
||
| 682 | * |
||
| 683 | * @return array<string,mixed> |
||
| 684 | * |
||
| 685 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 686 | */ |
||
| 687 | 2 | public function getActivatedServices(string $shipper): array |
|
| 693 | |||
| 694 | /** |
||
| 695 | * Order shipments from place B (typically supplier / previous consignee) to place A (shipping point) |
||
| 696 | * |
||
| 697 | * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages |
||
| 698 | * |
||
| 699 | * @return \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection|\Inspirum\Balikobot\Model\Values\OrderedPackage[] |
||
| 700 | * |
||
| 701 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 702 | */ |
||
| 703 | 3 | public function orderB2AShipment(PackageCollection $packages): OrderedPackageCollection |
|
| 720 | |||
| 721 | /** |
||
| 722 | * Get PDF link with signed consignment delivery document by the recipient |
||
| 723 | * |
||
| 724 | * @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package |
||
| 725 | * |
||
| 726 | * @return string |
||
| 727 | * |
||
| 728 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 729 | */ |
||
| 730 | 2 | public function getProofOfDelivery(OrderedPackage $package): string |
|
| 739 | |||
| 740 | /** |
||
| 741 | * Get array of PDF links with signed consignment delivery document by the recipient |
||
| 742 | * |
||
| 743 | * @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages |
||
| 744 | * |
||
| 745 | * @return array<string> |
||
| 746 | * |
||
| 747 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 748 | */ |
||
| 749 | 4 | public function getProofOfDeliveries(OrderedPackageCollection $packages): array |
|
| 755 | |||
| 756 | /** |
||
| 757 | * Obtain the price of carriage at consignment level |
||
| 758 | * |
||
| 759 | * @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages |
||
| 760 | * |
||
| 761 | * @return \Inspirum\Balikobot\Model\Aggregates\PackageTransportCostCollection|\Inspirum\Balikobot\Model\Values\PackageTransportCost[] |
||
| 762 | * |
||
| 763 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 764 | */ |
||
| 765 | 2 | public function getTransportCosts(PackageCollection $packages): PackageTransportCostCollection |
|
| 778 | |||
| 779 | /** |
||
| 780 | * Ģet information on individual countries of the world |
||
| 781 | * |
||
| 782 | * @return array<string,\Inspirum\Balikobot\Model\Values\Country>|\Inspirum\Balikobot\Model\Values\Country[] |
||
| 783 | * |
||
| 784 | * @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
||
| 785 | */ |
||
| 786 | 2 | public function getCountriesData(): array |
|
| 798 | } |
||
| 799 |