Complex classes like Label 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 Label, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 11 | class Label |
||
| 12 | { |
||
| 13 | const STATUS_PENDING_NORMALIZATION = 'pending_normalization'; |
||
| 14 | const STATUS_PENDING_CREATION = 'pending_creation'; |
||
| 15 | const STATUS_ERROR = 'error'; |
||
| 16 | const STATUS_SUCCESS = 'success'; |
||
| 17 | |||
| 18 | const LABEL_FORMAT_A4_PDF = 'a4_pdf'; |
||
| 19 | const LABEL_FORMAT_10_X_19_PDF = '10x19_pdf'; |
||
| 20 | const LABEL_FORMAT_PNG = 'png'; |
||
| 21 | const LABEL_FORMAT_ZPL = 'zpl'; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var int |
||
| 25 | * |
||
| 26 | * @ORM\Id |
||
| 27 | * @ORM\GeneratedValue |
||
| 28 | * @ORM\Column(type="integer") |
||
| 29 | */ |
||
| 30 | protected $id; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var string |
||
| 34 | * |
||
| 35 | * @ORM\Column(type="string") |
||
| 36 | */ |
||
| 37 | protected $status; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var string |
||
| 41 | * |
||
| 42 | * @ORM\Column(type="text", nullable=true) |
||
| 43 | */ |
||
| 44 | protected $error; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * The shipping method property is used in normalization. We check the mappings table to see |
||
| 48 | * if there is a shipping method matching this. If there is, we will populate the product code |
||
| 49 | * and services codes properties |
||
| 50 | * |
||
| 51 | * @var string |
||
| 52 | * |
||
| 53 | * @ORM\Column(type="string", nullable=true) |
||
| 54 | */ |
||
| 55 | protected $shippingMethod; |
||
| 56 | |||
| 57 | /************************** |
||
| 58 | * Pakkelabels properties * |
||
| 59 | *************************/ |
||
| 60 | /** |
||
| 61 | * @var string |
||
| 62 | * |
||
| 63 | * @ORM\Column(type="string", nullable=true) |
||
| 64 | */ |
||
| 65 | protected $orderId; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @var string |
||
| 69 | * |
||
| 70 | * @ORM\Column(type="string", nullable=true) |
||
| 71 | */ |
||
| 72 | protected $reference; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var string |
||
| 76 | * |
||
| 77 | * @ORM\Column(type="string", nullable=true) |
||
| 78 | */ |
||
| 79 | protected $source; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var boolean |
||
| 83 | * |
||
| 84 | * @ORM\Column(type="boolean") |
||
| 85 | */ |
||
| 86 | protected $ownAgreement; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @var string |
||
| 90 | * |
||
| 91 | * @ORM\Column(type="string", nullable=true) |
||
| 92 | */ |
||
| 93 | protected $labelFormat; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @var string |
||
| 97 | * |
||
| 98 | * @ORM\Column(type="string") |
||
| 99 | */ |
||
| 100 | protected $productCode; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @var string |
||
| 104 | * |
||
| 105 | * @ORM\Column(type="string") |
||
| 106 | */ |
||
| 107 | protected $serviceCodes; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @var boolean |
||
| 111 | * |
||
| 112 | * @ORM\Column(type="boolean") |
||
| 113 | */ |
||
| 114 | protected $automaticSelectServicePoint; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @var string |
||
| 118 | * |
||
| 119 | * @ORM\Column(type="string") |
||
| 120 | */ |
||
| 121 | protected $servicePointId; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @var boolean |
||
| 125 | * |
||
| 126 | * @ORM\Column(type="boolean") |
||
| 127 | */ |
||
| 128 | protected $smsNotification; |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @var boolean |
||
| 132 | * |
||
| 133 | * @ORM\Column(type="boolean") |
||
| 134 | */ |
||
| 135 | protected $emailNotification; |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @var string |
||
| 139 | * |
||
| 140 | * @ORM\Column(type="string") |
||
| 141 | */ |
||
| 142 | protected $senderName; |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @var string |
||
| 146 | * |
||
| 147 | * @ORM\Column(type="string") |
||
| 148 | */ |
||
| 149 | protected $senderAddress1; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @var string |
||
| 153 | * |
||
| 154 | * @ORM\Column(type="string", nullable=true) |
||
| 155 | */ |
||
| 156 | protected $senderAddress2; |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @var string |
||
| 160 | * |
||
| 161 | * @ORM\Column(type="string") |
||
| 162 | */ |
||
| 163 | protected $senderCountryCode; |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @var string |
||
| 167 | * |
||
| 168 | * @ORM\Column(type="string") |
||
| 169 | */ |
||
| 170 | protected $senderZipCode; |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @var string |
||
| 174 | * |
||
| 175 | * @ORM\Column(type="string") |
||
| 176 | */ |
||
| 177 | protected $senderCity; |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @var string |
||
| 181 | * |
||
| 182 | * @ORM\Column(type="string", nullable=true) |
||
| 183 | */ |
||
| 184 | protected $senderAttention; |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @var string |
||
| 188 | * |
||
| 189 | * @ORM\Column(type="string") |
||
| 190 | */ |
||
| 191 | protected $senderEmail; |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @var string |
||
| 195 | * |
||
| 196 | * @ORM\Column(type="string") |
||
| 197 | */ |
||
| 198 | protected $senderTelephone; |
||
| 199 | |||
| 200 | /** |
||
| 201 | * @var string |
||
| 202 | * |
||
| 203 | * @ORM\Column(type="string") |
||
| 204 | */ |
||
| 205 | protected $senderMobile; |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @var string |
||
| 209 | * |
||
| 210 | * @ORM\Column(type="string") |
||
| 211 | */ |
||
| 212 | protected $receiverName; |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @var string |
||
| 216 | * |
||
| 217 | * @ORM\Column(type="string") |
||
| 218 | */ |
||
| 219 | protected $receiverAddress1; |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @var string |
||
| 223 | * |
||
| 224 | * @ORM\Column(type="string", nullable=true) |
||
| 225 | */ |
||
| 226 | protected $receiverAddress2; |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @var string |
||
| 230 | * |
||
| 231 | * @ORM\Column(type="string") |
||
| 232 | */ |
||
| 233 | protected $receiverCountryCode; |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @var string |
||
| 237 | * |
||
| 238 | * @ORM\Column(type="string") |
||
| 239 | */ |
||
| 240 | protected $receiverZipCode; |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @var string |
||
| 244 | * |
||
| 245 | * @ORM\Column(type="string") |
||
| 246 | */ |
||
| 247 | protected $receiverCity; |
||
| 248 | |||
| 249 | /** |
||
| 250 | * @var string |
||
| 251 | * |
||
| 252 | * @ORM\Column(type="string", nullable=true) |
||
| 253 | */ |
||
| 254 | protected $receiverAttention; |
||
| 255 | |||
| 256 | /** |
||
| 257 | * @var string |
||
| 258 | * |
||
| 259 | * @ORM\Column(type="string") |
||
| 260 | */ |
||
| 261 | protected $receiverEmail; |
||
| 262 | |||
| 263 | /** |
||
| 264 | * @var string |
||
| 265 | * |
||
| 266 | * @ORM\Column(type="string") |
||
| 267 | */ |
||
| 268 | protected $receiverTelephone; |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @var string |
||
| 272 | * |
||
| 273 | * @ORM\Column(type="string") |
||
| 274 | */ |
||
| 275 | protected $receiverMobile; |
||
| 276 | |||
| 277 | /** |
||
| 278 | * @var string |
||
| 279 | * |
||
| 280 | * @ORM\Column(type="text", nullable=true) |
||
| 281 | */ |
||
| 282 | protected $receiverInstruction; |
||
| 283 | |||
| 284 | public function __construct() |
||
| 290 | |||
| 291 | public function arrayForApi() : array |
||
| 345 | |||
| 346 | public function markAsError(string $error) |
||
| 351 | |||
| 352 | public function markAsSuccess() |
||
| 357 | |||
| 358 | /********************* |
||
| 359 | * Getters / Setters * |
||
| 360 | ********************/ |
||
| 361 | /** |
||
| 362 | * @return int |
||
| 363 | */ |
||
| 364 | public function getId(): int |
||
| 368 | |||
| 369 | /** |
||
| 370 | * @param int $id |
||
| 371 | * @return Label |
||
| 372 | */ |
||
| 373 | public function setId(int $id) |
||
| 378 | |||
| 379 | /** |
||
| 380 | * @return string |
||
| 381 | */ |
||
| 382 | public function getStatus(): string |
||
| 386 | |||
| 387 | /** |
||
| 388 | * @param string $status |
||
| 389 | * @return Label |
||
| 390 | */ |
||
| 391 | public function setStatus(string $status) |
||
| 396 | |||
| 397 | /** |
||
| 398 | * @return string |
||
| 399 | */ |
||
| 400 | public function getError(): string |
||
| 404 | |||
| 405 | /** |
||
| 406 | * @param string $error |
||
| 407 | * @return Label |
||
| 408 | */ |
||
| 409 | public function setError(string $error) |
||
| 414 | |||
| 415 | /** |
||
| 416 | * @return string |
||
| 417 | */ |
||
| 418 | public function getShippingMethod(): string |
||
| 422 | |||
| 423 | /** |
||
| 424 | * @param string $shippingMethod |
||
| 425 | * @return Label |
||
| 426 | */ |
||
| 427 | public function setShippingMethod(string $shippingMethod) |
||
| 432 | |||
| 433 | /** |
||
| 434 | * @return string |
||
| 435 | */ |
||
| 436 | public function getOrderId(): string |
||
| 440 | |||
| 441 | /** |
||
| 442 | * @param string $orderId |
||
| 443 | * @return Label |
||
| 444 | */ |
||
| 445 | public function setOrderId(string $orderId) |
||
| 450 | |||
| 451 | /** |
||
| 452 | * @return string |
||
| 453 | */ |
||
| 454 | public function getReference(): string |
||
| 458 | |||
| 459 | /** |
||
| 460 | * @param string $reference |
||
| 461 | * @return Label |
||
| 462 | */ |
||
| 463 | public function setReference(string $reference) |
||
| 468 | |||
| 469 | /** |
||
| 470 | * @return string |
||
| 471 | */ |
||
| 472 | public function getSource(): string |
||
| 476 | |||
| 477 | /** |
||
| 478 | * @param string $source |
||
| 479 | * @return Label |
||
| 480 | */ |
||
| 481 | public function setSource(string $source) |
||
| 486 | |||
| 487 | /** |
||
| 488 | * @return bool |
||
| 489 | */ |
||
| 490 | public function isOwnAgreement(): bool |
||
| 494 | |||
| 495 | /** |
||
| 496 | * @param bool $ownAgreement |
||
| 497 | * @return Label |
||
| 498 | */ |
||
| 499 | public function setOwnAgreement(bool $ownAgreement) |
||
| 504 | |||
| 505 | /** |
||
| 506 | * @return string |
||
| 507 | */ |
||
| 508 | public function getLabelFormat(): string |
||
| 512 | |||
| 513 | /** |
||
| 514 | * @param string $labelFormat |
||
| 515 | * @return Label |
||
| 516 | */ |
||
| 517 | public function setLabelFormat(string $labelFormat) |
||
| 522 | |||
| 523 | /** |
||
| 524 | * @return string |
||
| 525 | */ |
||
| 526 | public function getProductCode(): string |
||
| 530 | |||
| 531 | /** |
||
| 532 | * @param string $productCode |
||
| 533 | * @return Label |
||
| 534 | */ |
||
| 535 | public function setProductCode(string $productCode) |
||
| 540 | |||
| 541 | /** |
||
| 542 | * @return string |
||
| 543 | */ |
||
| 544 | public function getServiceCodes(): string |
||
| 548 | |||
| 549 | /** |
||
| 550 | * @param string $serviceCodes |
||
| 551 | * @return Label |
||
| 552 | */ |
||
| 553 | public function setServiceCodes(string $serviceCodes) |
||
| 558 | |||
| 559 | /** |
||
| 560 | * @return bool |
||
| 561 | */ |
||
| 562 | public function isAutomaticSelectServicePoint(): bool |
||
| 566 | |||
| 567 | /** |
||
| 568 | * @param bool $automaticSelectServicePoint |
||
| 569 | * @return Label |
||
| 570 | */ |
||
| 571 | public function setAutomaticSelectServicePoint(bool $automaticSelectServicePoint) |
||
| 576 | |||
| 577 | /** |
||
| 578 | * @return string |
||
| 579 | */ |
||
| 580 | public function getServicePointId(): string |
||
| 584 | |||
| 585 | /** |
||
| 586 | * @param string $servicePointId |
||
| 587 | * @return Label |
||
| 588 | */ |
||
| 589 | public function setServicePointId(string $servicePointId) |
||
| 594 | |||
| 595 | /** |
||
| 596 | * @return bool |
||
| 597 | */ |
||
| 598 | public function isSmsNotification(): bool |
||
| 602 | |||
| 603 | /** |
||
| 604 | * @param bool $smsNotification |
||
| 605 | * @return Label |
||
| 606 | */ |
||
| 607 | public function setSmsNotification(bool $smsNotification) |
||
| 612 | |||
| 613 | /** |
||
| 614 | * @return bool |
||
| 615 | */ |
||
| 616 | public function isEmailNotification(): bool |
||
| 620 | |||
| 621 | /** |
||
| 622 | * @param bool $emailNotification |
||
| 623 | * @return Label |
||
| 624 | */ |
||
| 625 | public function setEmailNotification(bool $emailNotification) |
||
| 630 | |||
| 631 | /** |
||
| 632 | * @return string |
||
| 633 | */ |
||
| 634 | public function getSenderName(): string |
||
| 638 | |||
| 639 | /** |
||
| 640 | * @param string $senderName |
||
| 641 | * @return Label |
||
| 642 | */ |
||
| 643 | public function setSenderName(string $senderName) |
||
| 648 | |||
| 649 | /** |
||
| 650 | * @return string |
||
| 651 | */ |
||
| 652 | public function getSenderAddress1(): string |
||
| 656 | |||
| 657 | /** |
||
| 658 | * @param string $senderAddress1 |
||
| 659 | * @return Label |
||
| 660 | */ |
||
| 661 | public function setSenderAddress1(string $senderAddress1) |
||
| 666 | |||
| 667 | /** |
||
| 668 | * @return string |
||
| 669 | */ |
||
| 670 | public function getSenderAddress2(): string |
||
| 674 | |||
| 675 | /** |
||
| 676 | * @param string $senderAddress2 |
||
| 677 | * @return Label |
||
| 678 | */ |
||
| 679 | public function setSenderAddress2(string $senderAddress2) |
||
| 684 | |||
| 685 | /** |
||
| 686 | * @return string |
||
| 687 | */ |
||
| 688 | public function getSenderCountryCode(): string |
||
| 692 | |||
| 693 | /** |
||
| 694 | * @param string $senderCountryCode |
||
| 695 | * @return Label |
||
| 696 | */ |
||
| 697 | public function setSenderCountryCode(string $senderCountryCode) |
||
| 702 | |||
| 703 | /** |
||
| 704 | * @return string |
||
| 705 | */ |
||
| 706 | public function getSenderZipCode(): string |
||
| 710 | |||
| 711 | /** |
||
| 712 | * @param string $senderZipCode |
||
| 713 | * @return Label |
||
| 714 | */ |
||
| 715 | public function setSenderZipCode(string $senderZipCode) |
||
| 720 | |||
| 721 | /** |
||
| 722 | * @return string |
||
| 723 | */ |
||
| 724 | public function getSenderCity(): string |
||
| 728 | |||
| 729 | /** |
||
| 730 | * @param string $senderCity |
||
| 731 | * @return Label |
||
| 732 | */ |
||
| 733 | public function setSenderCity(string $senderCity) |
||
| 738 | |||
| 739 | /** |
||
| 740 | * @return string |
||
| 741 | */ |
||
| 742 | public function getSenderAttention(): string |
||
| 746 | |||
| 747 | /** |
||
| 748 | * @param string $senderAttention |
||
| 749 | * @return Label |
||
| 750 | */ |
||
| 751 | public function setSenderAttention(string $senderAttention) |
||
| 756 | |||
| 757 | /** |
||
| 758 | * @return string |
||
| 759 | */ |
||
| 760 | public function getSenderEmail(): string |
||
| 764 | |||
| 765 | /** |
||
| 766 | * @param string $senderEmail |
||
| 767 | * @return Label |
||
| 768 | */ |
||
| 769 | public function setSenderEmail(string $senderEmail) |
||
| 774 | |||
| 775 | /** |
||
| 776 | * @return string |
||
| 777 | */ |
||
| 778 | public function getSenderTelephone(): string |
||
| 782 | |||
| 783 | /** |
||
| 784 | * @param string $senderTelephone |
||
| 785 | * @return Label |
||
| 786 | */ |
||
| 787 | public function setSenderTelephone(string $senderTelephone) |
||
| 792 | |||
| 793 | /** |
||
| 794 | * @return string |
||
| 795 | */ |
||
| 796 | public function getSenderMobile(): string |
||
| 800 | |||
| 801 | /** |
||
| 802 | * @param string $senderMobile |
||
| 803 | * @return Label |
||
| 804 | */ |
||
| 805 | public function setSenderMobile(string $senderMobile) |
||
| 810 | |||
| 811 | /** |
||
| 812 | * @return string |
||
| 813 | */ |
||
| 814 | public function getReceiverName(): string |
||
| 818 | |||
| 819 | /** |
||
| 820 | * @param string $receiverName |
||
| 821 | * @return Label |
||
| 822 | */ |
||
| 823 | public function setReceiverName(string $receiverName) |
||
| 828 | |||
| 829 | /** |
||
| 830 | * @return string |
||
| 831 | */ |
||
| 832 | public function getReceiverAddress1(): string |
||
| 836 | |||
| 837 | /** |
||
| 838 | * @param string $receiverAddress1 |
||
| 839 | * @return Label |
||
| 840 | */ |
||
| 841 | public function setReceiverAddress1(string $receiverAddress1) |
||
| 846 | |||
| 847 | /** |
||
| 848 | * @return string |
||
| 849 | */ |
||
| 850 | public function getReceiverAddress2(): string |
||
| 854 | |||
| 855 | /** |
||
| 856 | * @param string $receiverAddress2 |
||
| 857 | * @return Label |
||
| 858 | */ |
||
| 859 | public function setReceiverAddress2(string $receiverAddress2) |
||
| 864 | |||
| 865 | /** |
||
| 866 | * @return string |
||
| 867 | */ |
||
| 868 | public function getReceiverCountryCode(): string |
||
| 872 | |||
| 873 | /** |
||
| 874 | * @param string $receiverCountryCode |
||
| 875 | * @return Label |
||
| 876 | */ |
||
| 877 | public function setReceiverCountryCode(string $receiverCountryCode) |
||
| 882 | |||
| 883 | /** |
||
| 884 | * @return string |
||
| 885 | */ |
||
| 886 | public function getReceiverZipCode(): string |
||
| 890 | |||
| 891 | /** |
||
| 892 | * @param string $receiverZipCode |
||
| 893 | * @return Label |
||
| 894 | */ |
||
| 895 | public function setReceiverZipCode(string $receiverZipCode) |
||
| 900 | |||
| 901 | /** |
||
| 902 | * @return string |
||
| 903 | */ |
||
| 904 | public function getReceiverCity(): string |
||
| 908 | |||
| 909 | /** |
||
| 910 | * @param string $receiverCity |
||
| 911 | * @return Label |
||
| 912 | */ |
||
| 913 | public function setReceiverCity(string $receiverCity) |
||
| 918 | |||
| 919 | /** |
||
| 920 | * @return string |
||
| 921 | */ |
||
| 922 | public function getReceiverAttention(): string |
||
| 926 | |||
| 927 | /** |
||
| 928 | * @param string $receiverAttention |
||
| 929 | * @return Label |
||
| 930 | */ |
||
| 931 | public function setReceiverAttention(string $receiverAttention) |
||
| 936 | |||
| 937 | /** |
||
| 938 | * @return string |
||
| 939 | */ |
||
| 940 | public function getReceiverEmail(): string |
||
| 944 | |||
| 945 | /** |
||
| 946 | * @param string $receiverEmail |
||
| 947 | * @return Label |
||
| 948 | */ |
||
| 949 | public function setReceiverEmail(string $receiverEmail) |
||
| 954 | |||
| 955 | /** |
||
| 956 | * @return string |
||
| 957 | */ |
||
| 958 | public function getReceiverTelephone(): string |
||
| 962 | |||
| 963 | /** |
||
| 964 | * @param string $receiverTelephone |
||
| 965 | * @return Label |
||
| 966 | */ |
||
| 967 | public function setReceiverTelephone(string $receiverTelephone) |
||
| 972 | |||
| 973 | /** |
||
| 974 | * @return string |
||
| 975 | */ |
||
| 976 | public function getReceiverMobile(): string |
||
| 980 | |||
| 981 | /** |
||
| 982 | * @param string $receiverMobile |
||
| 983 | * @return Label |
||
| 984 | */ |
||
| 985 | public function setReceiverMobile(string $receiverMobile) |
||
| 990 | |||
| 991 | /** |
||
| 992 | * @return string |
||
| 993 | */ |
||
| 994 | public function getReceiverInstruction(): string |
||
| 998 | |||
| 999 | /** |
||
| 1000 | * @param string $receiverInstruction |
||
| 1001 | * @return Label |
||
| 1002 | */ |
||
| 1003 | public function setReceiverInstruction(string $receiverInstruction) |
||
| 1008 | } |
||
| 1009 |