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 |
||
12 | class Label |
||
13 | { |
||
14 | const STATUS_PENDING_NORMALIZATION = 'pending_normalization'; |
||
15 | const STATUS_PENDING_CREATION = 'pending_creation'; |
||
16 | const STATUS_ERROR = 'error'; |
||
17 | const STATUS_SUCCESS = 'success'; |
||
18 | |||
19 | const LABEL_FORMAT_A4_PDF = 'a4_pdf'; |
||
20 | const LABEL_FORMAT_10_X_19_PDF = '10x19_pdf'; |
||
21 | const LABEL_FORMAT_PNG = 'png'; |
||
22 | const LABEL_FORMAT_ZPL = 'zpl'; |
||
23 | |||
24 | /** |
||
25 | * @var int |
||
26 | * |
||
27 | * @ORM\Id |
||
28 | * @ORM\GeneratedValue |
||
29 | * @ORM\Column(type="integer") |
||
30 | */ |
||
31 | protected $id; |
||
32 | |||
33 | /** |
||
34 | * This is the shipment id from Pakkelabels. |
||
35 | * |
||
36 | * @var int |
||
37 | * |
||
38 | * @ORM\Column(type="integer", unique=true, nullable=true) |
||
39 | */ |
||
40 | protected $externalId; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | * |
||
45 | * @Assert\NotBlank() |
||
46 | * |
||
47 | * @ORM\Column(type="string") |
||
48 | */ |
||
49 | protected $status; |
||
50 | |||
51 | /** |
||
52 | * @var string |
||
53 | * |
||
54 | * @ORM\Column(type="text", nullable=true) |
||
55 | */ |
||
56 | protected $error; |
||
57 | |||
58 | /** |
||
59 | * The shipping method property is used in normalization. We check the mappings table to see |
||
60 | * if there is a shipping method matching this. If there is, we will populate the product code |
||
61 | * and services codes properties. |
||
62 | * |
||
63 | * @var string |
||
64 | * |
||
65 | * @ORM\Column(type="string", nullable=true) |
||
66 | */ |
||
67 | protected $shippingMethod; |
||
68 | |||
69 | /** |
||
70 | * This property indiciates whether this label is a return label or not |
||
71 | * |
||
72 | * @var boolean |
||
73 | * |
||
74 | * @Assert\NotNull() |
||
75 | * |
||
76 | * @ORM\Column(type="boolean") |
||
77 | */ |
||
78 | protected $returnLabel; |
||
79 | |||
80 | /************************** |
||
81 | * Pakkelabels properties * |
||
82 | *************************/ |
||
83 | /** |
||
84 | * @var string |
||
85 | * |
||
86 | * @ORM\Column(type="string", nullable=true) |
||
87 | */ |
||
88 | protected $orderId; |
||
89 | |||
90 | /** |
||
91 | * @var string |
||
92 | * |
||
93 | * @ORM\Column(type="string", nullable=true) |
||
94 | */ |
||
95 | protected $reference; |
||
96 | |||
97 | /** |
||
98 | * @var string |
||
99 | * |
||
100 | * @ORM\Column(type="string", nullable=true) |
||
101 | */ |
||
102 | protected $source; |
||
103 | |||
104 | /** |
||
105 | * @var bool |
||
106 | * |
||
107 | * @Assert\NotBlank() |
||
108 | * |
||
109 | * @ORM\Column(type="boolean") |
||
110 | */ |
||
111 | protected $ownAgreement; |
||
112 | |||
113 | /** |
||
114 | * @var string |
||
115 | * |
||
116 | * @ORM\Column(type="string", nullable=true) |
||
117 | */ |
||
118 | protected $labelFormat; |
||
119 | |||
120 | /** |
||
121 | * @var string |
||
122 | * |
||
123 | * @ORM\Column(type="string", nullable=true) |
||
124 | */ |
||
125 | protected $productCode; |
||
126 | |||
127 | /** |
||
128 | * @var string |
||
129 | * |
||
130 | * @ORM\Column(type="string", nullable=true) |
||
131 | */ |
||
132 | protected $serviceCodes; |
||
133 | |||
134 | /** |
||
135 | * @var bool |
||
136 | * |
||
137 | * @Assert\NotBlank() |
||
138 | * |
||
139 | * @ORM\Column(type="boolean") |
||
140 | */ |
||
141 | protected $automaticSelectServicePoint; |
||
142 | |||
143 | /** |
||
144 | * @var string |
||
145 | * |
||
146 | * @ORM\Column(type="string", nullable=true) |
||
147 | */ |
||
148 | protected $servicePointId; |
||
149 | |||
150 | /** |
||
151 | * @var bool |
||
152 | * |
||
153 | * @Assert\NotBlank() |
||
154 | * |
||
155 | * @ORM\Column(type="boolean") |
||
156 | */ |
||
157 | protected $smsNotification; |
||
158 | |||
159 | /** |
||
160 | * @var bool |
||
161 | * |
||
162 | * @Assert\NotBlank() |
||
163 | * |
||
164 | * @ORM\Column(type="boolean") |
||
165 | */ |
||
166 | protected $emailNotification; |
||
167 | |||
168 | /** |
||
169 | * @var string |
||
170 | * |
||
171 | * @Assert\NotBlank() |
||
172 | * |
||
173 | * @ORM\Column(type="string") |
||
174 | */ |
||
175 | protected $senderName; |
||
176 | |||
177 | /** |
||
178 | * @var string |
||
179 | * |
||
180 | * @Assert\NotBlank() |
||
181 | * |
||
182 | * @ORM\Column(type="string") |
||
183 | */ |
||
184 | protected $senderAddress1; |
||
185 | |||
186 | /** |
||
187 | * @var string |
||
188 | * |
||
189 | * @ORM\Column(type="string", nullable=true) |
||
190 | */ |
||
191 | protected $senderAddress2; |
||
192 | |||
193 | /** |
||
194 | * @var string |
||
195 | * |
||
196 | * @Assert\NotBlank() |
||
197 | * |
||
198 | * @ORM\Column(type="string") |
||
199 | */ |
||
200 | protected $senderCountryCode; |
||
201 | |||
202 | /** |
||
203 | * @var string |
||
204 | * |
||
205 | * @Assert\NotBlank() |
||
206 | * |
||
207 | * @ORM\Column(type="string") |
||
208 | */ |
||
209 | protected $senderZipCode; |
||
210 | |||
211 | /** |
||
212 | * @var string |
||
213 | * |
||
214 | * @Assert\NotBlank() |
||
215 | * |
||
216 | * @ORM\Column(type="string") |
||
217 | */ |
||
218 | protected $senderCity; |
||
219 | |||
220 | /** |
||
221 | * @var string |
||
222 | * |
||
223 | * @ORM\Column(type="string", nullable=true) |
||
224 | */ |
||
225 | protected $senderAttention; |
||
226 | |||
227 | /** |
||
228 | * @var string |
||
229 | * |
||
230 | * @Assert\NotBlank() |
||
231 | * |
||
232 | * @ORM\Column(type="string") |
||
233 | */ |
||
234 | protected $senderEmail; |
||
235 | |||
236 | /** |
||
237 | * @var string |
||
238 | * |
||
239 | * @ORM\Column(type="string", nullable=true) |
||
240 | */ |
||
241 | protected $senderTelephone; |
||
242 | |||
243 | /** |
||
244 | * @var string |
||
245 | * |
||
246 | * @ORM\Column(type="string", nullable=true) |
||
247 | */ |
||
248 | protected $senderMobile; |
||
249 | |||
250 | /** |
||
251 | * @var string |
||
252 | * |
||
253 | * @Assert\NotBlank() |
||
254 | * |
||
255 | * @ORM\Column(type="string") |
||
256 | */ |
||
257 | protected $receiverName; |
||
258 | |||
259 | /** |
||
260 | * @var string |
||
261 | * |
||
262 | * @Assert\NotBlank() |
||
263 | * |
||
264 | * @ORM\Column(type="string") |
||
265 | */ |
||
266 | protected $receiverAddress1; |
||
267 | |||
268 | /** |
||
269 | * @var string |
||
270 | * |
||
271 | * @ORM\Column(type="string", nullable=true) |
||
272 | */ |
||
273 | protected $receiverAddress2; |
||
274 | |||
275 | /** |
||
276 | * @var string |
||
277 | * |
||
278 | * @Assert\NotBlank() |
||
279 | * |
||
280 | * @ORM\Column(type="string") |
||
281 | */ |
||
282 | protected $receiverCountryCode; |
||
283 | |||
284 | /** |
||
285 | * @var string |
||
286 | * |
||
287 | * @Assert\NotBlank() |
||
288 | * |
||
289 | * @ORM\Column(type="string") |
||
290 | */ |
||
291 | protected $receiverZipCode; |
||
292 | |||
293 | /** |
||
294 | * @var string |
||
295 | * |
||
296 | * @Assert\NotBlank() |
||
297 | * |
||
298 | * @ORM\Column(type="string") |
||
299 | */ |
||
300 | protected $receiverCity; |
||
301 | |||
302 | /** |
||
303 | * @var string |
||
304 | * |
||
305 | * @ORM\Column(type="string", nullable=true) |
||
306 | */ |
||
307 | protected $receiverAttention; |
||
308 | |||
309 | /** |
||
310 | * @var string |
||
311 | * |
||
312 | * @Assert\NotBlank() |
||
313 | * |
||
314 | * @ORM\Column(type="string") |
||
315 | */ |
||
316 | protected $receiverEmail; |
||
317 | |||
318 | /** |
||
319 | * @var string |
||
320 | * |
||
321 | * @ORM\Column(type="string", nullable=true) |
||
322 | */ |
||
323 | protected $receiverTelephone; |
||
324 | |||
325 | /** |
||
326 | * @var string |
||
327 | * |
||
328 | * @ORM\Column(type="string", nullable=true) |
||
329 | */ |
||
330 | protected $receiverMobile; |
||
331 | |||
332 | /** |
||
333 | * @var string |
||
334 | * |
||
335 | * @ORM\Column(type="text", nullable=true) |
||
336 | */ |
||
337 | protected $receiverInstruction; |
||
338 | |||
339 | public function __construct() |
||
347 | |||
348 | public function arrayForApi(): array |
||
398 | |||
399 | public function markAsError(string $error) |
||
404 | |||
405 | public function markAsSuccess() |
||
410 | |||
411 | public function resetStatus() |
||
416 | |||
417 | public function isStatus(string $status) : bool |
||
421 | |||
422 | public function isSuccess() : bool |
||
426 | |||
427 | public function isError() : bool |
||
431 | |||
432 | public function getStatusTranslationKey() : string |
||
436 | |||
437 | /** |
||
438 | * Returns the available label formats |
||
439 | * |
||
440 | * @return array |
||
441 | */ |
||
442 | public static function getLabelFormats() : array |
||
451 | |||
452 | /********************* |
||
453 | * Getters / Setters * |
||
454 | ********************/ |
||
455 | |||
456 | /** |
||
457 | * @return int |
||
458 | */ |
||
459 | public function getId(): int |
||
463 | |||
464 | /** |
||
465 | * @param int $id |
||
466 | * |
||
467 | * @return Label |
||
468 | */ |
||
469 | public function setId(int $id) |
||
475 | |||
476 | /** |
||
477 | * @return int |
||
478 | */ |
||
479 | public function getExternalId(): ?int |
||
483 | |||
484 | /** |
||
485 | * @param int $externalId |
||
486 | * |
||
487 | * @return Label |
||
488 | */ |
||
489 | public function setExternalId(int $externalId) |
||
495 | |||
496 | /** |
||
497 | * @return string |
||
498 | */ |
||
499 | public function getStatus(): string |
||
503 | |||
504 | /** |
||
505 | * @param string $status |
||
506 | * |
||
507 | * @return Label |
||
508 | */ |
||
509 | public function setStatus(string $status) |
||
515 | |||
516 | /** |
||
517 | * @return string |
||
518 | */ |
||
519 | public function getError(): ?string |
||
523 | |||
524 | /** |
||
525 | * @param string $error |
||
526 | * |
||
527 | * @return Label |
||
528 | */ |
||
529 | public function setError(string $error) |
||
535 | |||
536 | /** |
||
537 | * @return string |
||
538 | */ |
||
539 | public function getShippingMethod(): ?string |
||
543 | |||
544 | /** |
||
545 | * @param string $shippingMethod |
||
546 | * |
||
547 | * @return Label |
||
548 | */ |
||
549 | public function setShippingMethod(string $shippingMethod) |
||
555 | |||
556 | /** |
||
557 | * @return bool |
||
558 | */ |
||
559 | public function isReturnLabel(): bool |
||
563 | |||
564 | /** |
||
565 | * @param bool $returnLabel |
||
566 | * @return Label |
||
567 | */ |
||
568 | public function setReturnLabel(bool $returnLabel) |
||
573 | |||
574 | /** |
||
575 | * @return string |
||
576 | */ |
||
577 | public function getOrderId(): ?string |
||
581 | |||
582 | /** |
||
583 | * @param string $orderId |
||
584 | * |
||
585 | * @return Label |
||
586 | */ |
||
587 | public function setOrderId(string $orderId) |
||
593 | |||
594 | /** |
||
595 | * @return string |
||
596 | */ |
||
597 | public function getReference(): ?string |
||
601 | |||
602 | /** |
||
603 | * @param string $reference |
||
604 | * |
||
605 | * @return Label |
||
606 | */ |
||
607 | public function setReference(string $reference) |
||
613 | |||
614 | /** |
||
615 | * @return string |
||
616 | */ |
||
617 | public function getSource(): ?string |
||
621 | |||
622 | /** |
||
623 | * @param string $source |
||
624 | * |
||
625 | * @return Label |
||
626 | */ |
||
627 | public function setSource(string $source) |
||
633 | |||
634 | /** |
||
635 | * @return bool |
||
636 | */ |
||
637 | public function isOwnAgreement(): bool |
||
641 | |||
642 | /** |
||
643 | * @param bool $ownAgreement |
||
644 | * |
||
645 | * @return Label |
||
646 | */ |
||
647 | public function setOwnAgreement(bool $ownAgreement) |
||
653 | |||
654 | /** |
||
655 | * @return string |
||
656 | */ |
||
657 | public function getLabelFormat(): ?string |
||
661 | |||
662 | /** |
||
663 | * @param string $labelFormat |
||
664 | * |
||
665 | * @return Label |
||
666 | */ |
||
667 | public function setLabelFormat(string $labelFormat) |
||
673 | |||
674 | /** |
||
675 | * @return string |
||
676 | */ |
||
677 | public function getProductCode(): string |
||
681 | |||
682 | /** |
||
683 | * @param string $productCode |
||
684 | * |
||
685 | * @return Label |
||
686 | */ |
||
687 | public function setProductCode(string $productCode) |
||
693 | |||
694 | /** |
||
695 | * @return string |
||
696 | */ |
||
697 | public function getServiceCodes(): string |
||
701 | |||
702 | /** |
||
703 | * @param string $serviceCodes |
||
704 | * |
||
705 | * @return Label |
||
706 | */ |
||
707 | public function setServiceCodes(string $serviceCodes) |
||
713 | |||
714 | /** |
||
715 | * @return bool |
||
716 | */ |
||
717 | public function isAutomaticSelectServicePoint(): bool |
||
721 | |||
722 | /** |
||
723 | * @param bool $automaticSelectServicePoint |
||
724 | * |
||
725 | * @return Label |
||
726 | */ |
||
727 | public function setAutomaticSelectServicePoint(bool $automaticSelectServicePoint) |
||
733 | |||
734 | /** |
||
735 | * @return string |
||
736 | */ |
||
737 | public function getServicePointId(): string |
||
741 | |||
742 | /** |
||
743 | * @param string $servicePointId |
||
744 | * |
||
745 | * @return Label |
||
746 | */ |
||
747 | public function setServicePointId(string $servicePointId) |
||
753 | |||
754 | /** |
||
755 | * @return bool |
||
756 | */ |
||
757 | public function isSmsNotification(): bool |
||
761 | |||
762 | /** |
||
763 | * @param bool $smsNotification |
||
764 | * |
||
765 | * @return Label |
||
766 | */ |
||
767 | public function setSmsNotification(bool $smsNotification) |
||
773 | |||
774 | /** |
||
775 | * @return bool |
||
776 | */ |
||
777 | public function isEmailNotification(): bool |
||
781 | |||
782 | /** |
||
783 | * @param bool $emailNotification |
||
784 | * |
||
785 | * @return Label |
||
786 | */ |
||
787 | public function setEmailNotification(bool $emailNotification) |
||
793 | |||
794 | /** |
||
795 | * @return string |
||
796 | */ |
||
797 | public function getSenderName(): string |
||
801 | |||
802 | /** |
||
803 | * @param string $senderName |
||
804 | * |
||
805 | * @return Label |
||
806 | */ |
||
807 | public function setSenderName(string $senderName) |
||
813 | |||
814 | /** |
||
815 | * @return string |
||
816 | */ |
||
817 | public function getSenderAddress1(): string |
||
821 | |||
822 | /** |
||
823 | * @param string $senderAddress1 |
||
824 | * |
||
825 | * @return Label |
||
826 | */ |
||
827 | public function setSenderAddress1(string $senderAddress1) |
||
833 | |||
834 | /** |
||
835 | * @return string |
||
836 | */ |
||
837 | public function getSenderAddress2(): ?string |
||
841 | |||
842 | /** |
||
843 | * @param string $senderAddress2 |
||
844 | * |
||
845 | * @return Label |
||
846 | */ |
||
847 | public function setSenderAddress2(string $senderAddress2) |
||
853 | |||
854 | /** |
||
855 | * @return string |
||
856 | */ |
||
857 | public function getSenderCountryCode(): string |
||
861 | |||
862 | /** |
||
863 | * @param string $senderCountryCode |
||
864 | * |
||
865 | * @return Label |
||
866 | */ |
||
867 | public function setSenderCountryCode(string $senderCountryCode) |
||
873 | |||
874 | /** |
||
875 | * @return string |
||
876 | */ |
||
877 | public function getSenderZipCode(): string |
||
881 | |||
882 | /** |
||
883 | * @param string $senderZipCode |
||
884 | * |
||
885 | * @return Label |
||
886 | */ |
||
887 | public function setSenderZipCode(string $senderZipCode) |
||
893 | |||
894 | /** |
||
895 | * @return string |
||
896 | */ |
||
897 | public function getSenderCity(): string |
||
901 | |||
902 | /** |
||
903 | * @param string $senderCity |
||
904 | * |
||
905 | * @return Label |
||
906 | */ |
||
907 | public function setSenderCity(string $senderCity) |
||
913 | |||
914 | /** |
||
915 | * @return string |
||
916 | */ |
||
917 | public function getSenderAttention(): ?string |
||
921 | |||
922 | /** |
||
923 | * @param string $senderAttention |
||
924 | * |
||
925 | * @return Label |
||
926 | */ |
||
927 | public function setSenderAttention(string $senderAttention) |
||
933 | |||
934 | /** |
||
935 | * @return string |
||
936 | */ |
||
937 | public function getSenderEmail(): string |
||
941 | |||
942 | /** |
||
943 | * @param string $senderEmail |
||
944 | * |
||
945 | * @return Label |
||
946 | */ |
||
947 | public function setSenderEmail(string $senderEmail) |
||
953 | |||
954 | /** |
||
955 | * @return string |
||
956 | */ |
||
957 | public function getSenderTelephone(): ?string |
||
961 | |||
962 | /** |
||
963 | * @param string $senderTelephone |
||
964 | * |
||
965 | * @return Label |
||
966 | */ |
||
967 | public function setSenderTelephone(string $senderTelephone) |
||
973 | |||
974 | /** |
||
975 | * @return string |
||
976 | */ |
||
977 | public function getSenderMobile(): ?string |
||
981 | |||
982 | /** |
||
983 | * @param string $senderMobile |
||
984 | * |
||
985 | * @return Label |
||
986 | */ |
||
987 | public function setSenderMobile(string $senderMobile) |
||
993 | |||
994 | /** |
||
995 | * @return string |
||
996 | */ |
||
997 | public function getReceiverName(): string |
||
1001 | |||
1002 | /** |
||
1003 | * @param string $receiverName |
||
1004 | * |
||
1005 | * @return Label |
||
1006 | */ |
||
1007 | public function setReceiverName(string $receiverName) |
||
1013 | |||
1014 | /** |
||
1015 | * @return string |
||
1016 | */ |
||
1017 | public function getReceiverAddress1(): string |
||
1021 | |||
1022 | /** |
||
1023 | * @param string $receiverAddress1 |
||
1024 | * |
||
1025 | * @return Label |
||
1026 | */ |
||
1027 | public function setReceiverAddress1(string $receiverAddress1) |
||
1033 | |||
1034 | /** |
||
1035 | * @return string |
||
1036 | */ |
||
1037 | public function getReceiverAddress2(): ?string |
||
1041 | |||
1042 | /** |
||
1043 | * @param string $receiverAddress2 |
||
1044 | * |
||
1045 | * @return Label |
||
1046 | */ |
||
1047 | public function setReceiverAddress2(string $receiverAddress2) |
||
1053 | |||
1054 | /** |
||
1055 | * @return string |
||
1056 | */ |
||
1057 | public function getReceiverCountryCode(): string |
||
1061 | |||
1062 | /** |
||
1063 | * @param string $receiverCountryCode |
||
1064 | * |
||
1065 | * @return Label |
||
1066 | */ |
||
1067 | public function setReceiverCountryCode(string $receiverCountryCode) |
||
1073 | |||
1074 | /** |
||
1075 | * @return string |
||
1076 | */ |
||
1077 | public function getReceiverZipCode(): string |
||
1081 | |||
1082 | /** |
||
1083 | * @param string $receiverZipCode |
||
1084 | * |
||
1085 | * @return Label |
||
1086 | */ |
||
1087 | public function setReceiverZipCode(string $receiverZipCode) |
||
1093 | |||
1094 | /** |
||
1095 | * @return string |
||
1096 | */ |
||
1097 | public function getReceiverCity(): string |
||
1101 | |||
1102 | /** |
||
1103 | * @param string $receiverCity |
||
1104 | * |
||
1105 | * @return Label |
||
1106 | */ |
||
1107 | public function setReceiverCity(string $receiverCity) |
||
1113 | |||
1114 | /** |
||
1115 | * @return string |
||
1116 | */ |
||
1117 | public function getReceiverAttention(): ?string |
||
1121 | |||
1122 | /** |
||
1123 | * @param string $receiverAttention |
||
1124 | * |
||
1125 | * @return Label |
||
1126 | */ |
||
1127 | public function setReceiverAttention(string $receiverAttention) |
||
1133 | |||
1134 | /** |
||
1135 | * @return string |
||
1136 | */ |
||
1137 | public function getReceiverEmail(): string |
||
1141 | |||
1142 | /** |
||
1143 | * @param string $receiverEmail |
||
1144 | * |
||
1145 | * @return Label |
||
1146 | */ |
||
1147 | public function setReceiverEmail(string $receiverEmail) |
||
1153 | |||
1154 | /** |
||
1155 | * @return string |
||
1156 | */ |
||
1157 | public function getReceiverTelephone(): ?string |
||
1161 | |||
1162 | /** |
||
1163 | * @param string $receiverTelephone |
||
1164 | * |
||
1165 | * @return Label |
||
1166 | */ |
||
1167 | public function setReceiverTelephone(string $receiverTelephone) |
||
1173 | |||
1174 | /** |
||
1175 | * @return string |
||
1176 | */ |
||
1177 | public function getReceiverMobile(): ?string |
||
1181 | |||
1182 | /** |
||
1183 | * @param string $receiverMobile |
||
1184 | * |
||
1185 | * @return Label |
||
1186 | */ |
||
1187 | public function setReceiverMobile(string $receiverMobile) |
||
1193 | |||
1194 | /** |
||
1195 | * @return string |
||
1196 | */ |
||
1197 | public function getReceiverInstruction(): ?string |
||
1201 | |||
1202 | /** |
||
1203 | * @param string $receiverInstruction |
||
1204 | * |
||
1205 | * @return Label |
||
1206 | */ |
||
1207 | public function setReceiverInstruction(string $receiverInstruction) |
||
1213 | } |
||
1214 |