Complex classes like Shop 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 Shop, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class Shop extends Model |
||
17 | { |
||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $name; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $email; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $domain; |
||
32 | |||
33 | /** |
||
34 | * @var \DateTimeInterface |
||
35 | */ |
||
36 | protected $createdAt; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $province; |
||
42 | |||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $country; |
||
47 | |||
48 | /** |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $address1; |
||
52 | |||
53 | /** |
||
54 | * @var string |
||
55 | */ |
||
56 | protected $zip; |
||
57 | |||
58 | /** |
||
59 | * @var string |
||
60 | */ |
||
61 | protected $city; |
||
62 | |||
63 | /** |
||
64 | * @var string |
||
65 | */ |
||
66 | protected $source; |
||
67 | |||
68 | /** |
||
69 | * @var string |
||
70 | */ |
||
71 | protected $phone; |
||
72 | |||
73 | /** |
||
74 | * @var string |
||
75 | */ |
||
76 | protected $updatedAt; |
||
77 | |||
78 | /** |
||
79 | * @var string |
||
80 | */ |
||
81 | protected $customerEmail; |
||
82 | |||
83 | /** |
||
84 | * @var float |
||
85 | */ |
||
86 | protected $latitude; |
||
87 | |||
88 | /** |
||
89 | * @var float |
||
90 | */ |
||
91 | protected $longitude; |
||
92 | |||
93 | /** |
||
94 | * @var int |
||
95 | */ |
||
96 | protected $primaryLocationId; |
||
97 | |||
98 | /** |
||
99 | * @var string |
||
100 | */ |
||
101 | protected $primaryLocale; |
||
102 | |||
103 | /** |
||
104 | * @var string |
||
105 | */ |
||
106 | protected $address2; |
||
107 | |||
108 | /** |
||
109 | * @var string |
||
110 | */ |
||
111 | protected $countryCode; |
||
112 | |||
113 | /** |
||
114 | * @var string |
||
115 | */ |
||
116 | protected $countryName; |
||
117 | |||
118 | /** |
||
119 | * @var string |
||
120 | */ |
||
121 | protected $currency; |
||
122 | |||
123 | /** |
||
124 | * @var string |
||
125 | */ |
||
126 | protected $timezone; |
||
127 | |||
128 | /** |
||
129 | * @var string |
||
130 | */ |
||
131 | protected $ianaTimezone; |
||
132 | |||
133 | /** |
||
134 | * @var string |
||
135 | */ |
||
136 | protected $shopOwner; |
||
137 | |||
138 | /** |
||
139 | * @var string |
||
140 | */ |
||
141 | protected $moneyFormat; |
||
142 | |||
143 | /** |
||
144 | * @var string |
||
145 | */ |
||
146 | protected $moneyWithCurrencyFormat; |
||
147 | |||
148 | /** |
||
149 | * @var string |
||
150 | */ |
||
151 | protected $weightUnit; |
||
152 | |||
153 | /** |
||
154 | * @var string |
||
155 | */ |
||
156 | protected $provinceCode; |
||
157 | |||
158 | /** |
||
159 | * @var bool |
||
160 | */ |
||
161 | protected $taxesIncluded; |
||
162 | |||
163 | /** |
||
164 | * @var string |
||
165 | */ |
||
166 | protected $taxShipping; |
||
167 | |||
168 | /** |
||
169 | * @var string |
||
170 | */ |
||
171 | protected $countyTaxes; |
||
172 | |||
173 | /** |
||
174 | * @var string |
||
175 | */ |
||
176 | protected $planDisplayName; |
||
177 | |||
178 | /** |
||
179 | * @var string |
||
180 | */ |
||
181 | protected $planName; |
||
182 | |||
183 | /** |
||
184 | * @var bool |
||
185 | */ |
||
186 | protected $hasDiscounts; |
||
187 | |||
188 | /** |
||
189 | * @var bool |
||
190 | */ |
||
191 | protected $hasGiftCards; |
||
192 | |||
193 | /** |
||
194 | * @var string |
||
195 | */ |
||
196 | protected $myshopifyDomain; |
||
197 | |||
198 | /** |
||
199 | * @var string |
||
200 | */ |
||
201 | protected $googleAppsDomain; |
||
202 | |||
203 | /** |
||
204 | * @var string |
||
205 | */ |
||
206 | protected $googleAppsLoginEnabled; |
||
207 | |||
208 | /** |
||
209 | * @var string |
||
210 | */ |
||
211 | protected $moneyInEmailsFormat; |
||
212 | |||
213 | /** |
||
214 | * @var string |
||
215 | */ |
||
216 | protected $moneyWithCurrencyInEmailsFormat; |
||
217 | |||
218 | /** |
||
219 | * @var bool |
||
220 | */ |
||
221 | protected $eligibleForPayments; |
||
222 | |||
223 | /** |
||
224 | * @var bool |
||
225 | */ |
||
226 | protected $requiresExtraPaymentsAgreement; |
||
227 | |||
228 | /** |
||
229 | * @var bool |
||
230 | */ |
||
231 | protected $passwordEnabled; |
||
232 | |||
233 | /** |
||
234 | * @var bool |
||
235 | */ |
||
236 | protected $hasStoreFront; |
||
237 | |||
238 | /** |
||
239 | * @var bool |
||
240 | */ |
||
241 | protected $eligibleForCardReaderGiveaway; |
||
242 | |||
243 | /** |
||
244 | * @var bool |
||
245 | */ |
||
246 | protected $finances; |
||
247 | |||
248 | /** |
||
249 | * @var bool |
||
250 | */ |
||
251 | protected $setupRequired; |
||
252 | |||
253 | /** |
||
254 | * @var bool |
||
255 | */ |
||
256 | protected $forceSsl; |
||
257 | |||
258 | /** |
||
259 | * @return string |
||
260 | */ |
||
261 | public function getName() |
||
265 | |||
266 | /** |
||
267 | * @param string $name |
||
268 | * |
||
269 | * @return Shop |
||
270 | */ |
||
271 | public function setName($name) |
||
277 | |||
278 | /** |
||
279 | * @return string |
||
280 | */ |
||
281 | public function getEmail() |
||
285 | |||
286 | /** |
||
287 | * @param string $email |
||
288 | * |
||
289 | * @return Shop |
||
290 | */ |
||
291 | public function setEmail($email) |
||
297 | |||
298 | /** |
||
299 | * @return string |
||
300 | */ |
||
301 | public function getDomain() |
||
305 | |||
306 | /** |
||
307 | * @param string $domain |
||
308 | * |
||
309 | * @return Shop |
||
310 | */ |
||
311 | public function setDomain($domain) |
||
317 | |||
318 | /** |
||
319 | * @return \DateTimeInterface |
||
320 | */ |
||
321 | public function getCreatedAt() |
||
325 | |||
326 | /** |
||
327 | * @param \DateTimeInterface $createdAt |
||
328 | * |
||
329 | * @return Shop |
||
330 | */ |
||
331 | public function setCreatedAt($createdAt) |
||
337 | |||
338 | /** |
||
339 | * @return string |
||
340 | */ |
||
341 | public function getProvince() |
||
345 | |||
346 | /** |
||
347 | * @param string $province |
||
348 | * |
||
349 | * @return Shop |
||
350 | */ |
||
351 | public function setProvince($province) |
||
357 | |||
358 | /** |
||
359 | * @return string |
||
360 | */ |
||
361 | public function getCountry() |
||
365 | |||
366 | /** |
||
367 | * @param string $country |
||
368 | * |
||
369 | * @return Shop |
||
370 | */ |
||
371 | public function setCountry($country) |
||
377 | |||
378 | /** |
||
379 | * @return string |
||
380 | */ |
||
381 | public function getAddress1() |
||
385 | |||
386 | /** |
||
387 | * @param string $address1 |
||
388 | * |
||
389 | * @return Shop |
||
390 | */ |
||
391 | public function setAddress1($address1) |
||
397 | |||
398 | /** |
||
399 | * @return string |
||
400 | */ |
||
401 | public function getZip() |
||
405 | |||
406 | /** |
||
407 | * @param string $zip |
||
408 | * |
||
409 | * @return Shop |
||
410 | */ |
||
411 | public function setZip($zip) |
||
417 | |||
418 | /** |
||
419 | * @return string |
||
420 | */ |
||
421 | public function getCity() |
||
425 | |||
426 | /** |
||
427 | * @param string $city |
||
428 | * |
||
429 | * @return Shop |
||
430 | */ |
||
431 | public function setCity($city) |
||
437 | |||
438 | /** |
||
439 | * @return string |
||
440 | */ |
||
441 | public function getSource() |
||
445 | |||
446 | /** |
||
447 | * @param string $source |
||
448 | * |
||
449 | * @return Shop |
||
450 | */ |
||
451 | public function setSource($source) |
||
457 | |||
458 | /** |
||
459 | * @return string |
||
460 | */ |
||
461 | public function getPhone() |
||
465 | |||
466 | /** |
||
467 | * @param string $phone |
||
468 | * |
||
469 | * @return Shop |
||
470 | */ |
||
471 | public function setPhone($phone) |
||
477 | |||
478 | /** |
||
479 | * @return string |
||
480 | */ |
||
481 | public function getUpdatedAt() |
||
485 | |||
486 | /** |
||
487 | * @param string $updatedAt |
||
488 | * |
||
489 | * @return Shop |
||
490 | */ |
||
491 | public function setUpdatedAt($updatedAt) |
||
497 | |||
498 | /** |
||
499 | * @return string |
||
500 | */ |
||
501 | public function getCustomerEmail() |
||
505 | |||
506 | /** |
||
507 | * @param string $customerEmail |
||
508 | * |
||
509 | * @return Shop |
||
510 | */ |
||
511 | public function setCustomerEmail($customerEmail) |
||
517 | |||
518 | /** |
||
519 | * @return float |
||
520 | */ |
||
521 | public function getLatitude() |
||
525 | |||
526 | /** |
||
527 | * @param float $latitude |
||
528 | * |
||
529 | * @return Shop |
||
530 | */ |
||
531 | public function setLatitude($latitude) |
||
537 | |||
538 | /** |
||
539 | * @return float |
||
540 | */ |
||
541 | public function getLongitude() |
||
545 | |||
546 | /** |
||
547 | * @param float $longitude |
||
548 | * |
||
549 | * @return Shop |
||
550 | */ |
||
551 | public function setLongitude($longitude) |
||
557 | |||
558 | /** |
||
559 | * @return integer |
||
560 | */ |
||
561 | public function getPrimaryLocationId() |
||
565 | |||
566 | /** |
||
567 | * @param string $primaryLocationId |
||
568 | * |
||
569 | * @return Shop |
||
570 | */ |
||
571 | public function setPrimaryLocationId($primaryLocationId) |
||
577 | |||
578 | /** |
||
579 | * @return string |
||
580 | */ |
||
581 | public function getPrimaryLocale() |
||
585 | |||
586 | /** |
||
587 | * @param string $primaryLocale |
||
588 | * |
||
589 | * @return Shop |
||
590 | */ |
||
591 | public function setPrimaryLocale($primaryLocale) |
||
597 | |||
598 | /** |
||
599 | * @return string |
||
600 | */ |
||
601 | public function getAddress2() |
||
605 | |||
606 | /** |
||
607 | * @param string $address2 |
||
608 | * |
||
609 | * @return Shop |
||
610 | */ |
||
611 | public function setAddress2($address2) |
||
617 | |||
618 | /** |
||
619 | * @return string |
||
620 | */ |
||
621 | public function getCountryCode() |
||
625 | |||
626 | /** |
||
627 | * @param string $countryCode |
||
628 | * |
||
629 | * @return Shop |
||
630 | */ |
||
631 | public function setCountryCode($countryCode) |
||
637 | |||
638 | /** |
||
639 | * @return string |
||
640 | */ |
||
641 | public function getCountryName() |
||
645 | |||
646 | /** |
||
647 | * @param string $countryName |
||
648 | * |
||
649 | * @return Shop |
||
650 | */ |
||
651 | public function setCountryName($countryName) |
||
657 | |||
658 | /** |
||
659 | * @return string |
||
660 | */ |
||
661 | public function getCurrency() |
||
665 | |||
666 | /** |
||
667 | * @param string $currency |
||
668 | * |
||
669 | * @return Shop |
||
670 | */ |
||
671 | public function setCurrency($currency) |
||
677 | |||
678 | /** |
||
679 | * @return string |
||
680 | */ |
||
681 | public function getTimezone() |
||
685 | |||
686 | /** |
||
687 | * @param string $timezone |
||
688 | * |
||
689 | * @return Shop |
||
690 | */ |
||
691 | public function setTimezone($timezone) |
||
697 | |||
698 | /** |
||
699 | * @return string |
||
700 | */ |
||
701 | public function getIanaTimezone() |
||
705 | |||
706 | /** |
||
707 | * @param string $ianaTimezone |
||
708 | * |
||
709 | * @return Shop |
||
710 | */ |
||
711 | public function setIanaTimezone($ianaTimezone) |
||
717 | |||
718 | /** |
||
719 | * @return string |
||
720 | */ |
||
721 | public function getShopOwner() |
||
725 | |||
726 | /** |
||
727 | * @param string $shopOwner |
||
728 | * |
||
729 | * @return Shop |
||
730 | */ |
||
731 | public function setShopOwner($shopOwner) |
||
737 | |||
738 | /** |
||
739 | * @return string |
||
740 | */ |
||
741 | public function getMoneyFormat() |
||
745 | |||
746 | /** |
||
747 | * @param string $moneyFormat |
||
748 | * |
||
749 | * @return Shop |
||
750 | */ |
||
751 | public function setMoneyFormat($moneyFormat) |
||
757 | |||
758 | /** |
||
759 | * @return string |
||
760 | */ |
||
761 | public function getMoneyWithCurrencyFormat() |
||
765 | |||
766 | /** |
||
767 | * @param string $moneyWithCurrencyFormat |
||
768 | * |
||
769 | * @return Shop |
||
770 | */ |
||
771 | public function setMoneyWithCurrencyFormat($moneyWithCurrencyFormat) |
||
777 | |||
778 | /** |
||
779 | * @return string |
||
780 | */ |
||
781 | public function getWeightUnit() |
||
785 | |||
786 | /** |
||
787 | * @param string $weightUnit |
||
788 | * |
||
789 | * @return Shop |
||
790 | */ |
||
791 | public function setWeightUnit($weightUnit) |
||
797 | |||
798 | /** |
||
799 | * @return string |
||
800 | */ |
||
801 | public function getProvinceCode() |
||
805 | |||
806 | /** |
||
807 | * @param string $provinceCode |
||
808 | * |
||
809 | * @return Shop |
||
810 | */ |
||
811 | public function setProvinceCode($provinceCode) |
||
817 | |||
818 | /** |
||
819 | * @return bool |
||
820 | */ |
||
821 | public function isTaxesIncluded() |
||
825 | |||
826 | /** |
||
827 | * @param bool $taxesIncluded |
||
828 | * |
||
829 | * @return Shop |
||
830 | */ |
||
831 | public function setTaxesIncluded($taxesIncluded) |
||
837 | |||
838 | /** |
||
839 | * @return string |
||
840 | */ |
||
841 | public function getTaxShipping() |
||
845 | |||
846 | /** |
||
847 | * @param string $taxShipping |
||
848 | * |
||
849 | * @return Shop |
||
850 | */ |
||
851 | public function setTaxShipping($taxShipping) |
||
857 | |||
858 | /** |
||
859 | * @return string |
||
860 | */ |
||
861 | public function getCountyTaxes() |
||
865 | |||
866 | /** |
||
867 | * @param string $countyTaxes |
||
868 | * |
||
869 | * @return Shop |
||
870 | */ |
||
871 | public function setCountyTaxes($countyTaxes) |
||
877 | |||
878 | /** |
||
879 | * @return string |
||
880 | */ |
||
881 | public function getPlanDisplayName() |
||
885 | |||
886 | /** |
||
887 | * @param string $planDisplayName |
||
888 | * |
||
889 | * @return Shop |
||
890 | */ |
||
891 | public function setPlanDisplayName($planDisplayName) |
||
897 | |||
898 | /** |
||
899 | * @return string |
||
900 | */ |
||
901 | public function getPlanName() |
||
905 | |||
906 | /** |
||
907 | * @param string $planName |
||
908 | * |
||
909 | * @return Shop |
||
910 | */ |
||
911 | public function setPlanName($planName) |
||
917 | |||
918 | /** |
||
919 | * @return bool |
||
920 | */ |
||
921 | public function isHasDiscounts() |
||
925 | |||
926 | /** |
||
927 | * @param bool $hasDiscounts |
||
928 | * |
||
929 | * @return Shop |
||
930 | */ |
||
931 | public function setHasDiscounts($hasDiscounts) |
||
937 | |||
938 | /** |
||
939 | * @return bool |
||
940 | */ |
||
941 | public function isHasGiftCards() |
||
945 | |||
946 | /** |
||
947 | * @param bool $hasGiftCards |
||
948 | * |
||
949 | * @return Shop |
||
950 | */ |
||
951 | public function setHasGiftCards($hasGiftCards) |
||
957 | |||
958 | /** |
||
959 | * @return string |
||
960 | */ |
||
961 | public function getMyshopifyDomain() |
||
965 | |||
966 | /** |
||
967 | * @param string $myshopifyDomain |
||
968 | * |
||
969 | * @return Shop |
||
970 | */ |
||
971 | public function setMyshopifyDomain($myshopifyDomain) |
||
977 | |||
978 | /** |
||
979 | * @return string |
||
980 | */ |
||
981 | public function getGoogleAppsDomain() |
||
985 | |||
986 | /** |
||
987 | * @param string $googleAppsDomain |
||
988 | * |
||
989 | * @return Shop |
||
990 | */ |
||
991 | public function setGoogleAppsDomain($googleAppsDomain) |
||
997 | |||
998 | /** |
||
999 | * @return string |
||
1000 | */ |
||
1001 | public function getGoogleAppsLoginEnabled() |
||
1005 | |||
1006 | /** |
||
1007 | * @param string $googleAppsLoginEnabled |
||
1008 | * |
||
1009 | * @return Shop |
||
1010 | */ |
||
1011 | public function setGoogleAppsLoginEnabled($googleAppsLoginEnabled) |
||
1017 | |||
1018 | /** |
||
1019 | * @return string |
||
1020 | */ |
||
1021 | public function getMoneyInEmailsFormat() |
||
1025 | |||
1026 | /** |
||
1027 | * @param string $moneyInEmailsFormat |
||
1028 | * |
||
1029 | * @return Shop |
||
1030 | */ |
||
1031 | public function setMoneyInEmailsFormat($moneyInEmailsFormat) |
||
1037 | |||
1038 | /** |
||
1039 | * @return string |
||
1040 | */ |
||
1041 | public function getMoneyWithCurrencyInEmailsFormat() |
||
1045 | |||
1046 | /** |
||
1047 | * @param string $moneyWithCurrencyInEmailsFormat |
||
1048 | * |
||
1049 | * @return Shop |
||
1050 | */ |
||
1051 | public function setMoneyWithCurrencyInEmailsFormat($moneyWithCurrencyInEmailsFormat) |
||
1057 | |||
1058 | /** |
||
1059 | * @return bool |
||
1060 | */ |
||
1061 | public function isEligibleForPayments() |
||
1065 | |||
1066 | /** |
||
1067 | * @param bool $eligibleForPayments |
||
1068 | * |
||
1069 | * @return Shop |
||
1070 | */ |
||
1071 | public function setEligibleForPayments($eligibleForPayments) |
||
1077 | |||
1078 | /** |
||
1079 | * @return bool |
||
1080 | */ |
||
1081 | public function isRequiresExtraPaymentsAgreement() |
||
1085 | |||
1086 | /** |
||
1087 | * @param bool $requiresExtraPaymentsAgreement |
||
1088 | * |
||
1089 | * @return Shop |
||
1090 | */ |
||
1091 | public function setRequiresExtraPaymentsAgreement($requiresExtraPaymentsAgreement) |
||
1097 | |||
1098 | /** |
||
1099 | * @return bool |
||
1100 | */ |
||
1101 | public function isPasswordEnabled() |
||
1105 | |||
1106 | /** |
||
1107 | * @param bool $passwordEnabled |
||
1108 | * |
||
1109 | * @return Shop |
||
1110 | */ |
||
1111 | public function setPasswordEnabled($passwordEnabled) |
||
1117 | |||
1118 | /** |
||
1119 | * @return bool |
||
1120 | */ |
||
1121 | public function isHasStoreFront() |
||
1125 | |||
1126 | /** |
||
1127 | * @param bool $hasStoreFront |
||
1128 | * |
||
1129 | * @return Shop |
||
1130 | */ |
||
1131 | public function setHasStoreFront($hasStoreFront) |
||
1137 | |||
1138 | /** |
||
1139 | * @return bool |
||
1140 | */ |
||
1141 | public function isEligibleForCardReaderGiveaway() |
||
1145 | |||
1146 | /** |
||
1147 | * @param bool $eligibleForCardReaderGiveaway |
||
1148 | * |
||
1149 | * @return Shop |
||
1150 | */ |
||
1151 | public function setEligibleForCardReaderGiveaway($eligibleForCardReaderGiveaway) |
||
1157 | |||
1158 | /** |
||
1159 | * @return bool |
||
1160 | */ |
||
1161 | public function isFinances() |
||
1165 | |||
1166 | /** |
||
1167 | * @param bool $finances |
||
1168 | * |
||
1169 | * @return Shop |
||
1170 | */ |
||
1171 | public function setFinances($finances) |
||
1177 | |||
1178 | /** |
||
1179 | * @return bool |
||
1180 | */ |
||
1181 | public function isSetupRequired() |
||
1185 | |||
1186 | /** |
||
1187 | * @param bool $setupRequired |
||
1188 | * |
||
1189 | * @return Shop |
||
1190 | */ |
||
1191 | public function setSetupRequired($setupRequired) |
||
1197 | |||
1198 | /** |
||
1199 | * @return bool |
||
1200 | */ |
||
1201 | public function isForceSsl() |
||
1205 | |||
1206 | /** |
||
1207 | * @param bool $forceSsl |
||
1208 | * |
||
1209 | * @return Shop |
||
1210 | */ |
||
1211 | public function setForceSsl($forceSsl) |
||
1217 | } |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.