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 | * Pakkelabels properties * |
||
71 | *************************/ |
||
72 | /** |
||
73 | * @var string |
||
74 | * |
||
75 | * @ORM\Column(type="string", nullable=true) |
||
76 | */ |
||
77 | protected $orderId; |
||
78 | |||
79 | /** |
||
80 | * @var string |
||
81 | * |
||
82 | * @ORM\Column(type="string", nullable=true) |
||
83 | */ |
||
84 | protected $reference; |
||
85 | |||
86 | /** |
||
87 | * @var string |
||
88 | * |
||
89 | * @ORM\Column(type="string", nullable=true) |
||
90 | */ |
||
91 | protected $source; |
||
92 | |||
93 | /** |
||
94 | * @var bool |
||
95 | * |
||
96 | * @Assert\NotBlank() |
||
97 | * |
||
98 | * @ORM\Column(type="boolean") |
||
99 | */ |
||
100 | protected $ownAgreement; |
||
101 | |||
102 | /** |
||
103 | * @var string |
||
104 | * |
||
105 | * @ORM\Column(type="string", nullable=true) |
||
106 | */ |
||
107 | protected $labelFormat; |
||
108 | |||
109 | /** |
||
110 | * @var string |
||
111 | * |
||
112 | * @ORM\Column(type="string", nullable=true) |
||
113 | */ |
||
114 | protected $productCode; |
||
115 | |||
116 | /** |
||
117 | * @var string |
||
118 | * |
||
119 | * @ORM\Column(type="string", nullable=true) |
||
120 | */ |
||
121 | protected $serviceCodes; |
||
122 | |||
123 | /** |
||
124 | * @var bool |
||
125 | * |
||
126 | * @Assert\NotBlank() |
||
127 | * |
||
128 | * @ORM\Column(type="boolean") |
||
129 | */ |
||
130 | protected $automaticSelectServicePoint; |
||
131 | |||
132 | /** |
||
133 | * @var string |
||
134 | * |
||
135 | * @ORM\Column(type="string", nullable=true) |
||
136 | */ |
||
137 | protected $servicePointId; |
||
138 | |||
139 | /** |
||
140 | * @var bool |
||
141 | * |
||
142 | * @Assert\NotBlank() |
||
143 | * |
||
144 | * @ORM\Column(type="boolean") |
||
145 | */ |
||
146 | protected $smsNotification; |
||
147 | |||
148 | /** |
||
149 | * @var bool |
||
150 | * |
||
151 | * @Assert\NotBlank() |
||
152 | * |
||
153 | * @ORM\Column(type="boolean") |
||
154 | */ |
||
155 | protected $emailNotification; |
||
156 | |||
157 | /** |
||
158 | * @var string |
||
159 | * |
||
160 | * @Assert\NotBlank() |
||
161 | * |
||
162 | * @ORM\Column(type="string") |
||
163 | */ |
||
164 | protected $senderName; |
||
165 | |||
166 | /** |
||
167 | * @var string |
||
168 | * |
||
169 | * @Assert\NotBlank() |
||
170 | * |
||
171 | * @ORM\Column(type="string") |
||
172 | */ |
||
173 | protected $senderAddress1; |
||
174 | |||
175 | /** |
||
176 | * @var string |
||
177 | * |
||
178 | * @ORM\Column(type="string", nullable=true) |
||
179 | */ |
||
180 | protected $senderAddress2; |
||
181 | |||
182 | /** |
||
183 | * @var string |
||
184 | * |
||
185 | * @Assert\NotBlank() |
||
186 | * |
||
187 | * @ORM\Column(type="string") |
||
188 | */ |
||
189 | protected $senderCountryCode; |
||
190 | |||
191 | /** |
||
192 | * @var string |
||
193 | * |
||
194 | * @Assert\NotBlank() |
||
195 | * |
||
196 | * @ORM\Column(type="string") |
||
197 | */ |
||
198 | protected $senderZipCode; |
||
199 | |||
200 | /** |
||
201 | * @var string |
||
202 | * |
||
203 | * @Assert\NotBlank() |
||
204 | * |
||
205 | * @ORM\Column(type="string") |
||
206 | */ |
||
207 | protected $senderCity; |
||
208 | |||
209 | /** |
||
210 | * @var string |
||
211 | * |
||
212 | * @ORM\Column(type="string", nullable=true) |
||
213 | */ |
||
214 | protected $senderAttention; |
||
215 | |||
216 | /** |
||
217 | * @var string |
||
218 | * |
||
219 | * @Assert\NotBlank() |
||
220 | * |
||
221 | * @ORM\Column(type="string") |
||
222 | */ |
||
223 | protected $senderEmail; |
||
224 | |||
225 | /** |
||
226 | * @var string |
||
227 | * |
||
228 | * @ORM\Column(type="string", nullable=true) |
||
229 | */ |
||
230 | protected $senderTelephone; |
||
231 | |||
232 | /** |
||
233 | * @var string |
||
234 | * |
||
235 | * @ORM\Column(type="string", nullable=true) |
||
236 | */ |
||
237 | protected $senderMobile; |
||
238 | |||
239 | /** |
||
240 | * @var string |
||
241 | * |
||
242 | * @Assert\NotBlank() |
||
243 | * |
||
244 | * @ORM\Column(type="string") |
||
245 | */ |
||
246 | protected $receiverName; |
||
247 | |||
248 | /** |
||
249 | * @var string |
||
250 | * |
||
251 | * @Assert\NotBlank() |
||
252 | * |
||
253 | * @ORM\Column(type="string") |
||
254 | */ |
||
255 | protected $receiverAddress1; |
||
256 | |||
257 | /** |
||
258 | * @var string |
||
259 | * |
||
260 | * @ORM\Column(type="string", nullable=true) |
||
261 | */ |
||
262 | protected $receiverAddress2; |
||
263 | |||
264 | /** |
||
265 | * @var string |
||
266 | * |
||
267 | * @Assert\NotBlank() |
||
268 | * |
||
269 | * @ORM\Column(type="string") |
||
270 | */ |
||
271 | protected $receiverCountryCode; |
||
272 | |||
273 | /** |
||
274 | * @var string |
||
275 | * |
||
276 | * @Assert\NotBlank() |
||
277 | * |
||
278 | * @ORM\Column(type="string") |
||
279 | */ |
||
280 | protected $receiverZipCode; |
||
281 | |||
282 | /** |
||
283 | * @var string |
||
284 | * |
||
285 | * @Assert\NotBlank() |
||
286 | * |
||
287 | * @ORM\Column(type="string") |
||
288 | */ |
||
289 | protected $receiverCity; |
||
290 | |||
291 | /** |
||
292 | * @var string |
||
293 | * |
||
294 | * @ORM\Column(type="string", nullable=true) |
||
295 | */ |
||
296 | protected $receiverAttention; |
||
297 | |||
298 | /** |
||
299 | * @var string |
||
300 | * |
||
301 | * @Assert\NotBlank() |
||
302 | * |
||
303 | * @ORM\Column(type="string") |
||
304 | */ |
||
305 | protected $receiverEmail; |
||
306 | |||
307 | /** |
||
308 | * @var string |
||
309 | * |
||
310 | * @ORM\Column(type="string", nullable=true) |
||
311 | */ |
||
312 | protected $receiverTelephone; |
||
313 | |||
314 | /** |
||
315 | * @var string |
||
316 | * |
||
317 | * @ORM\Column(type="string", nullable=true) |
||
318 | */ |
||
319 | protected $receiverMobile; |
||
320 | |||
321 | /** |
||
322 | * @var string |
||
323 | * |
||
324 | * @ORM\Column(type="text", nullable=true) |
||
325 | */ |
||
326 | protected $receiverInstruction; |
||
327 | |||
328 | public function __construct() |
||
335 | |||
336 | public function arrayForApi(): array |
||
386 | |||
387 | public function markAsError(string $error) |
||
392 | |||
393 | public function markAsSuccess() |
||
398 | |||
399 | /** |
||
400 | * Returns the available label formats |
||
401 | * |
||
402 | * @return array |
||
403 | */ |
||
404 | public static function getLabelFormats() : array |
||
413 | |||
414 | /********************* |
||
415 | * Getters / Setters * |
||
416 | ********************/ |
||
417 | |||
418 | /** |
||
419 | * @return int |
||
420 | */ |
||
421 | public function getId(): int |
||
425 | |||
426 | /** |
||
427 | * @param int $id |
||
428 | * |
||
429 | * @return Label |
||
430 | */ |
||
431 | public function setId(int $id) |
||
437 | |||
438 | /** |
||
439 | * @return int |
||
440 | */ |
||
441 | public function getExternalId(): ?int |
||
445 | |||
446 | /** |
||
447 | * @param int $externalId |
||
448 | * |
||
449 | * @return Label |
||
450 | */ |
||
451 | public function setExternalId(int $externalId) |
||
457 | |||
458 | /** |
||
459 | * @return string |
||
460 | */ |
||
461 | public function getStatus(): string |
||
465 | |||
466 | /** |
||
467 | * @param string $status |
||
468 | * |
||
469 | * @return Label |
||
470 | */ |
||
471 | public function setStatus(string $status) |
||
477 | |||
478 | /** |
||
479 | * @return string |
||
480 | */ |
||
481 | public function getError(): ?string |
||
485 | |||
486 | /** |
||
487 | * @param string $error |
||
488 | * |
||
489 | * @return Label |
||
490 | */ |
||
491 | public function setError(string $error) |
||
497 | |||
498 | /** |
||
499 | * @return string |
||
500 | */ |
||
501 | public function getShippingMethod(): ?string |
||
505 | |||
506 | /** |
||
507 | * @param string $shippingMethod |
||
508 | * |
||
509 | * @return Label |
||
510 | */ |
||
511 | public function setShippingMethod(string $shippingMethod) |
||
517 | |||
518 | /** |
||
519 | * @return string |
||
520 | */ |
||
521 | public function getOrderId(): ?string |
||
525 | |||
526 | /** |
||
527 | * @param string $orderId |
||
528 | * |
||
529 | * @return Label |
||
530 | */ |
||
531 | public function setOrderId(string $orderId) |
||
537 | |||
538 | /** |
||
539 | * @return string |
||
540 | */ |
||
541 | public function getReference(): ?string |
||
545 | |||
546 | /** |
||
547 | * @param string $reference |
||
548 | * |
||
549 | * @return Label |
||
550 | */ |
||
551 | public function setReference(string $reference) |
||
557 | |||
558 | /** |
||
559 | * @return string |
||
560 | */ |
||
561 | public function getSource(): ?string |
||
565 | |||
566 | /** |
||
567 | * @param string $source |
||
568 | * |
||
569 | * @return Label |
||
570 | */ |
||
571 | public function setSource(string $source) |
||
577 | |||
578 | /** |
||
579 | * @return bool |
||
580 | */ |
||
581 | public function isOwnAgreement(): bool |
||
585 | |||
586 | /** |
||
587 | * @param bool $ownAgreement |
||
588 | * |
||
589 | * @return Label |
||
590 | */ |
||
591 | public function setOwnAgreement(bool $ownAgreement) |
||
597 | |||
598 | /** |
||
599 | * @return string |
||
600 | */ |
||
601 | public function getLabelFormat(): ?string |
||
605 | |||
606 | /** |
||
607 | * @param string $labelFormat |
||
608 | * |
||
609 | * @return Label |
||
610 | */ |
||
611 | public function setLabelFormat(string $labelFormat) |
||
617 | |||
618 | /** |
||
619 | * @return string |
||
620 | */ |
||
621 | public function getProductCode(): string |
||
625 | |||
626 | /** |
||
627 | * @param string $productCode |
||
628 | * |
||
629 | * @return Label |
||
630 | */ |
||
631 | public function setProductCode(string $productCode) |
||
637 | |||
638 | /** |
||
639 | * @return string |
||
640 | */ |
||
641 | public function getServiceCodes(): string |
||
645 | |||
646 | /** |
||
647 | * @param string $serviceCodes |
||
648 | * |
||
649 | * @return Label |
||
650 | */ |
||
651 | public function setServiceCodes(string $serviceCodes) |
||
657 | |||
658 | /** |
||
659 | * @return bool |
||
660 | */ |
||
661 | public function isAutomaticSelectServicePoint(): bool |
||
665 | |||
666 | /** |
||
667 | * @param bool $automaticSelectServicePoint |
||
668 | * |
||
669 | * @return Label |
||
670 | */ |
||
671 | public function setAutomaticSelectServicePoint(bool $automaticSelectServicePoint) |
||
677 | |||
678 | /** |
||
679 | * @return string |
||
680 | */ |
||
681 | public function getServicePointId(): string |
||
685 | |||
686 | /** |
||
687 | * @param string $servicePointId |
||
688 | * |
||
689 | * @return Label |
||
690 | */ |
||
691 | public function setServicePointId(string $servicePointId) |
||
697 | |||
698 | /** |
||
699 | * @return bool |
||
700 | */ |
||
701 | public function isSmsNotification(): bool |
||
705 | |||
706 | /** |
||
707 | * @param bool $smsNotification |
||
708 | * |
||
709 | * @return Label |
||
710 | */ |
||
711 | public function setSmsNotification(bool $smsNotification) |
||
717 | |||
718 | /** |
||
719 | * @return bool |
||
720 | */ |
||
721 | public function isEmailNotification(): bool |
||
725 | |||
726 | /** |
||
727 | * @param bool $emailNotification |
||
728 | * |
||
729 | * @return Label |
||
730 | */ |
||
731 | public function setEmailNotification(bool $emailNotification) |
||
737 | |||
738 | /** |
||
739 | * @return string |
||
740 | */ |
||
741 | public function getSenderName(): string |
||
745 | |||
746 | /** |
||
747 | * @param string $senderName |
||
748 | * |
||
749 | * @return Label |
||
750 | */ |
||
751 | public function setSenderName(string $senderName) |
||
757 | |||
758 | /** |
||
759 | * @return string |
||
760 | */ |
||
761 | public function getSenderAddress1(): string |
||
765 | |||
766 | /** |
||
767 | * @param string $senderAddress1 |
||
768 | * |
||
769 | * @return Label |
||
770 | */ |
||
771 | public function setSenderAddress1(string $senderAddress1) |
||
777 | |||
778 | /** |
||
779 | * @return string |
||
780 | */ |
||
781 | public function getSenderAddress2(): ?string |
||
785 | |||
786 | /** |
||
787 | * @param string $senderAddress2 |
||
788 | * |
||
789 | * @return Label |
||
790 | */ |
||
791 | public function setSenderAddress2(string $senderAddress2) |
||
797 | |||
798 | /** |
||
799 | * @return string |
||
800 | */ |
||
801 | public function getSenderCountryCode(): string |
||
805 | |||
806 | /** |
||
807 | * @param string $senderCountryCode |
||
808 | * |
||
809 | * @return Label |
||
810 | */ |
||
811 | public function setSenderCountryCode(string $senderCountryCode) |
||
817 | |||
818 | /** |
||
819 | * @return string |
||
820 | */ |
||
821 | public function getSenderZipCode(): string |
||
825 | |||
826 | /** |
||
827 | * @param string $senderZipCode |
||
828 | * |
||
829 | * @return Label |
||
830 | */ |
||
831 | public function setSenderZipCode(string $senderZipCode) |
||
837 | |||
838 | /** |
||
839 | * @return string |
||
840 | */ |
||
841 | public function getSenderCity(): string |
||
845 | |||
846 | /** |
||
847 | * @param string $senderCity |
||
848 | * |
||
849 | * @return Label |
||
850 | */ |
||
851 | public function setSenderCity(string $senderCity) |
||
857 | |||
858 | /** |
||
859 | * @return string |
||
860 | */ |
||
861 | public function getSenderAttention(): ?string |
||
865 | |||
866 | /** |
||
867 | * @param string $senderAttention |
||
868 | * |
||
869 | * @return Label |
||
870 | */ |
||
871 | public function setSenderAttention(string $senderAttention) |
||
877 | |||
878 | /** |
||
879 | * @return string |
||
880 | */ |
||
881 | public function getSenderEmail(): string |
||
885 | |||
886 | /** |
||
887 | * @param string $senderEmail |
||
888 | * |
||
889 | * @return Label |
||
890 | */ |
||
891 | public function setSenderEmail(string $senderEmail) |
||
897 | |||
898 | /** |
||
899 | * @return string |
||
900 | */ |
||
901 | public function getSenderTelephone(): ?string |
||
905 | |||
906 | /** |
||
907 | * @param string $senderTelephone |
||
908 | * |
||
909 | * @return Label |
||
910 | */ |
||
911 | public function setSenderTelephone(string $senderTelephone) |
||
917 | |||
918 | /** |
||
919 | * @return string |
||
920 | */ |
||
921 | public function getSenderMobile(): ?string |
||
925 | |||
926 | /** |
||
927 | * @param string $senderMobile |
||
928 | * |
||
929 | * @return Label |
||
930 | */ |
||
931 | public function setSenderMobile(string $senderMobile) |
||
937 | |||
938 | /** |
||
939 | * @return string |
||
940 | */ |
||
941 | public function getReceiverName(): string |
||
945 | |||
946 | /** |
||
947 | * @param string $receiverName |
||
948 | * |
||
949 | * @return Label |
||
950 | */ |
||
951 | public function setReceiverName(string $receiverName) |
||
957 | |||
958 | /** |
||
959 | * @return string |
||
960 | */ |
||
961 | public function getReceiverAddress1(): string |
||
965 | |||
966 | /** |
||
967 | * @param string $receiverAddress1 |
||
968 | * |
||
969 | * @return Label |
||
970 | */ |
||
971 | public function setReceiverAddress1(string $receiverAddress1) |
||
977 | |||
978 | /** |
||
979 | * @return string |
||
980 | */ |
||
981 | public function getReceiverAddress2(): ?string |
||
985 | |||
986 | /** |
||
987 | * @param string $receiverAddress2 |
||
988 | * |
||
989 | * @return Label |
||
990 | */ |
||
991 | public function setReceiverAddress2(string $receiverAddress2) |
||
997 | |||
998 | /** |
||
999 | * @return string |
||
1000 | */ |
||
1001 | public function getReceiverCountryCode(): string |
||
1005 | |||
1006 | /** |
||
1007 | * @param string $receiverCountryCode |
||
1008 | * |
||
1009 | * @return Label |
||
1010 | */ |
||
1011 | public function setReceiverCountryCode(string $receiverCountryCode) |
||
1017 | |||
1018 | /** |
||
1019 | * @return string |
||
1020 | */ |
||
1021 | public function getReceiverZipCode(): string |
||
1025 | |||
1026 | /** |
||
1027 | * @param string $receiverZipCode |
||
1028 | * |
||
1029 | * @return Label |
||
1030 | */ |
||
1031 | public function setReceiverZipCode(string $receiverZipCode) |
||
1037 | |||
1038 | /** |
||
1039 | * @return string |
||
1040 | */ |
||
1041 | public function getReceiverCity(): string |
||
1045 | |||
1046 | /** |
||
1047 | * @param string $receiverCity |
||
1048 | * |
||
1049 | * @return Label |
||
1050 | */ |
||
1051 | public function setReceiverCity(string $receiverCity) |
||
1057 | |||
1058 | /** |
||
1059 | * @return string |
||
1060 | */ |
||
1061 | public function getReceiverAttention(): ?string |
||
1065 | |||
1066 | /** |
||
1067 | * @param string $receiverAttention |
||
1068 | * |
||
1069 | * @return Label |
||
1070 | */ |
||
1071 | public function setReceiverAttention(string $receiverAttention) |
||
1077 | |||
1078 | /** |
||
1079 | * @return string |
||
1080 | */ |
||
1081 | public function getReceiverEmail(): string |
||
1085 | |||
1086 | /** |
||
1087 | * @param string $receiverEmail |
||
1088 | * |
||
1089 | * @return Label |
||
1090 | */ |
||
1091 | public function setReceiverEmail(string $receiverEmail) |
||
1097 | |||
1098 | /** |
||
1099 | * @return string |
||
1100 | */ |
||
1101 | public function getReceiverTelephone(): ?string |
||
1105 | |||
1106 | /** |
||
1107 | * @param string $receiverTelephone |
||
1108 | * |
||
1109 | * @return Label |
||
1110 | */ |
||
1111 | public function setReceiverTelephone(string $receiverTelephone) |
||
1117 | |||
1118 | /** |
||
1119 | * @return string |
||
1120 | */ |
||
1121 | public function getReceiverMobile(): ?string |
||
1125 | |||
1126 | /** |
||
1127 | * @param string $receiverMobile |
||
1128 | * |
||
1129 | * @return Label |
||
1130 | */ |
||
1131 | public function setReceiverMobile(string $receiverMobile) |
||
1137 | |||
1138 | /** |
||
1139 | * @return string |
||
1140 | */ |
||
1141 | public function getReceiverInstruction(): ?string |
||
1145 | |||
1146 | /** |
||
1147 | * @param string $receiverInstruction |
||
1148 | * |
||
1149 | * @return Label |
||
1150 | */ |
||
1151 | public function setReceiverInstruction(string $receiverInstruction) |
||
1157 | } |
||
1158 |