Complex classes like Branch 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 Branch, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 8 | class Branch |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var string |
||
| 12 | */ |
||
| 13 | private $shipper; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var string|null |
||
| 17 | */ |
||
| 18 | private $service; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | private $branchId; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var string|null |
||
| 27 | */ |
||
| 28 | private $id; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var string|null |
||
| 32 | */ |
||
| 33 | private $uid; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | private $type; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | private $name; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var string |
||
| 47 | */ |
||
| 48 | private $city; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var string |
||
| 52 | */ |
||
| 53 | private $street; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var string |
||
| 57 | */ |
||
| 58 | private $zip; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var string|null |
||
| 62 | */ |
||
| 63 | private $cityPart; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var string|null |
||
| 67 | */ |
||
| 68 | private $district; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var string|null |
||
| 72 | */ |
||
| 73 | private $region; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * ISO 3166-1 alpha-2 http://cs.wikipedia.org/wiki/ISO_3166-1 |
||
| 77 | * |
||
| 78 | * @var string|null |
||
| 79 | */ |
||
| 80 | private $country; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @var string|null |
||
| 84 | */ |
||
| 85 | private $currency; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @var string|null |
||
| 89 | */ |
||
| 90 | private $photoSmall; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @var string|null |
||
| 94 | */ |
||
| 95 | private $photoBig; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @var string|null |
||
| 99 | */ |
||
| 100 | private $url; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @var float|null |
||
| 104 | */ |
||
| 105 | private $latitude; |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @var float|null |
||
| 109 | */ |
||
| 110 | private $longitude; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @var string|null |
||
| 114 | */ |
||
| 115 | private $directionsGlobal; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @var string|null |
||
| 119 | */ |
||
| 120 | private $directionsCar; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @var string|null |
||
| 124 | */ |
||
| 125 | private $directionsPublic; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @var bool|null |
||
| 129 | */ |
||
| 130 | private $wheelchairAccessible; |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @var bool|null |
||
| 134 | */ |
||
| 135 | private $claimAssistant; |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @var bool|null |
||
| 139 | */ |
||
| 140 | private $dressingRoom; |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @var string|null |
||
| 144 | */ |
||
| 145 | private $openingMonday; |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @var string|null |
||
| 149 | */ |
||
| 150 | private $openingTuesday; |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @var string|null |
||
| 154 | */ |
||
| 155 | private $openingWednesday; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @var string|null |
||
| 159 | */ |
||
| 160 | private $openingThursday; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @var string|null |
||
| 164 | */ |
||
| 165 | private $openingFriday; |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @var string|null |
||
| 169 | */ |
||
| 170 | private $openingSaturday; |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @var string|null |
||
| 174 | */ |
||
| 175 | private $openingSunday; |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @var float|null |
||
| 179 | */ |
||
| 180 | private $maxWeight; |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Branch constructor |
||
| 184 | * |
||
| 185 | * @param string $shipper |
||
| 186 | * @param string|null $service |
||
| 187 | * @param string|null $id |
||
| 188 | * @param string|null $uid |
||
| 189 | * @param string $type |
||
| 190 | * @param string $name |
||
| 191 | * @param string $city |
||
| 192 | * @param string $street |
||
| 193 | * @param string $zip |
||
| 194 | * @param string|null $country |
||
| 195 | * @param string|null $cityPart |
||
| 196 | * @param string|null $district |
||
| 197 | * @param string|null $region |
||
| 198 | * @param string|null $currency |
||
| 199 | * @param string|null $photoSmall |
||
| 200 | * @param string|null $photoBig |
||
| 201 | * @param string|null $url |
||
| 202 | * @param float|null $latitude |
||
| 203 | * @param float|null $longitude |
||
| 204 | * @param string|null $directionsGlobal |
||
| 205 | * @param string|null $directionsCar |
||
| 206 | * @param string|null $directionsPublic |
||
| 207 | * @param bool|null $wheelchairAccessible |
||
| 208 | * @param bool|null $claimAssistant |
||
| 209 | * @param bool|null $dressingRoom |
||
| 210 | * @param string|null $openingMonday |
||
| 211 | * @param string|null $openingTuesday |
||
| 212 | * @param string|null $openingWednesday |
||
| 213 | * @param string|null $openingThursday |
||
| 214 | * @param string|null $openingFriday |
||
| 215 | * @param string|null $openingSaturday |
||
| 216 | * @param string|null $openingSunday |
||
| 217 | * @param float|null $maxWeight |
||
| 218 | */ |
||
| 219 | 19 | public function __construct( |
|
| 290 | |||
| 291 | /** |
||
| 292 | * @return string |
||
| 293 | */ |
||
| 294 | 3 | public function getShipper(): string |
|
| 298 | |||
| 299 | /** |
||
| 300 | * @return string|null |
||
| 301 | */ |
||
| 302 | 3 | public function getServiceType(): ?string |
|
| 306 | |||
| 307 | /** |
||
| 308 | * @return string |
||
| 309 | */ |
||
| 310 | 2 | public function getBranchId(): string |
|
| 314 | |||
| 315 | /** |
||
| 316 | * @return string|null |
||
| 317 | */ |
||
| 318 | 9 | public function getId(): ?string |
|
| 322 | |||
| 323 | /** |
||
| 324 | * @return string|null |
||
| 325 | */ |
||
| 326 | 1 | public function getUId(): ?string |
|
| 330 | |||
| 331 | /** |
||
| 332 | * @return string |
||
| 333 | */ |
||
| 334 | 4 | public function getType(): string |
|
| 338 | |||
| 339 | /** |
||
| 340 | * @return string |
||
| 341 | */ |
||
| 342 | 4 | public function getName(): string |
|
| 346 | |||
| 347 | /** |
||
| 348 | * @return string |
||
| 349 | */ |
||
| 350 | 3 | public function getCity(): string |
|
| 354 | |||
| 355 | /** |
||
| 356 | * @return string |
||
| 357 | */ |
||
| 358 | 5 | public function getStreet(): string |
|
| 362 | |||
| 363 | /** |
||
| 364 | * @return string |
||
| 365 | */ |
||
| 366 | 10 | public function getZip(): string |
|
| 370 | |||
| 371 | /** |
||
| 372 | * @return string|null |
||
| 373 | */ |
||
| 374 | 3 | public function getCityPart(): ?string |
|
| 378 | |||
| 379 | /** |
||
| 380 | * @return string|null |
||
| 381 | */ |
||
| 382 | 3 | public function getDistrict(): ?string |
|
| 386 | |||
| 387 | /** |
||
| 388 | * @return string|null |
||
| 389 | */ |
||
| 390 | 3 | public function getRegion(): ?string |
|
| 394 | |||
| 395 | /** |
||
| 396 | * @return string|null |
||
| 397 | */ |
||
| 398 | 6 | public function getCountry(): ?string |
|
| 402 | |||
| 403 | /** |
||
| 404 | * @return string|null |
||
| 405 | */ |
||
| 406 | 3 | public function getCurrency(): ?string |
|
| 410 | |||
| 411 | /** |
||
| 412 | * @return string|null |
||
| 413 | */ |
||
| 414 | 3 | public function getPhotoSmall(): ?string |
|
| 418 | |||
| 419 | /** |
||
| 420 | * @return string|null |
||
| 421 | */ |
||
| 422 | 3 | public function getPhotoBig(): ?string |
|
| 426 | |||
| 427 | /** |
||
| 428 | * @return string|null |
||
| 429 | */ |
||
| 430 | 3 | public function getUrl(): ?string |
|
| 434 | |||
| 435 | /** |
||
| 436 | * @return float|null |
||
| 437 | */ |
||
| 438 | 3 | public function getLatitude(): ?float |
|
| 442 | |||
| 443 | /** |
||
| 444 | * @return float|null |
||
| 445 | */ |
||
| 446 | 3 | public function getLongitude(): ?float |
|
| 450 | |||
| 451 | /** |
||
| 452 | * @return string|null |
||
| 453 | */ |
||
| 454 | 3 | public function getDirectionsGlobal(): ?string |
|
| 458 | |||
| 459 | /** |
||
| 460 | * @return string|null |
||
| 461 | */ |
||
| 462 | 3 | public function getDirectionsCar(): ?string |
|
| 466 | |||
| 467 | /** |
||
| 468 | * @return string|null |
||
| 469 | */ |
||
| 470 | 3 | public function getDirectionsPublic(): ?string |
|
| 474 | |||
| 475 | /** |
||
| 476 | * @return bool|null |
||
| 477 | */ |
||
| 478 | 3 | public function getWheelchairAccessible(): ?bool |
|
| 482 | |||
| 483 | /** |
||
| 484 | * @return bool|null |
||
| 485 | */ |
||
| 486 | 3 | public function getClaimAssistant(): ?bool |
|
| 490 | |||
| 491 | /** |
||
| 492 | * @return bool|null |
||
| 493 | */ |
||
| 494 | 3 | public function getDressingRoom(): ?bool |
|
| 498 | |||
| 499 | /** |
||
| 500 | * @return string|null |
||
| 501 | */ |
||
| 502 | 3 | public function getOpeningMonday(): ?string |
|
| 506 | |||
| 507 | /** |
||
| 508 | * @return string|null |
||
| 509 | */ |
||
| 510 | 3 | public function getOpeningTuesday(): ?string |
|
| 514 | |||
| 515 | /** |
||
| 516 | * @return string|null |
||
| 517 | */ |
||
| 518 | 3 | public function getOpeningWednesday(): ?string |
|
| 522 | |||
| 523 | /** |
||
| 524 | * @return string|null |
||
| 525 | */ |
||
| 526 | 3 | public function getOpeningThursday(): ?string |
|
| 530 | |||
| 531 | /** |
||
| 532 | * @return string|null |
||
| 533 | */ |
||
| 534 | 3 | public function getOpeningFriday(): ?string |
|
| 538 | |||
| 539 | /** |
||
| 540 | * @return string|null |
||
| 541 | */ |
||
| 542 | 3 | public function getOpeningSaturday(): ?string |
|
| 546 | |||
| 547 | /** |
||
| 548 | * @return string|null |
||
| 549 | */ |
||
| 550 | 3 | public function getOpeningSunday(): ?string |
|
| 554 | |||
| 555 | /** |
||
| 556 | * @return float|null |
||
| 557 | */ |
||
| 558 | 3 | public function getMaxWeight(): ?float |
|
| 562 | |||
| 563 | /** |
||
| 564 | * Set branch ID |
||
| 565 | * |
||
| 566 | * @return void |
||
| 567 | */ |
||
| 568 | 19 | private function setBranchId(): void |
|
| 572 | |||
| 573 | /** |
||
| 574 | * Resolve branch ID |
||
| 575 | * |
||
| 576 | * @return string |
||
| 577 | */ |
||
| 578 | 19 | private function resolveBranchId(): string |
|
| 599 | |||
| 600 | /** |
||
| 601 | * New instance from data |
||
| 602 | * |
||
| 603 | * @param string $shipper |
||
| 604 | * @param string|null $service |
||
| 605 | * @param array<string,mixed> $data |
||
| 606 | * |
||
| 607 | * @return \Inspirum\Balikobot\Model\Values\Branch |
||
| 608 | */ |
||
| 609 | 19 | public static function newInstanceFromData(string $shipper, ?string $service, array $data): self |
|
| 666 | } |
||
| 667 |