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