Complex classes like HasVerboseMethods 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 HasVerboseMethods, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
5 | trait HasVerboseMethods |
||
6 | { |
||
7 | /** |
||
8 | * Function to retrieve the name in Afrikaans. |
||
9 | * |
||
10 | * @return string |
||
11 | */ |
||
12 | public function inAfrikaans() : string |
||
16 | |||
17 | /** |
||
18 | * Function to retrieve the name in Albanian. |
||
19 | * |
||
20 | * @return string |
||
21 | */ |
||
22 | public function inAlbanian() : string |
||
26 | |||
27 | /** |
||
28 | * Function to retrieve the name in Amharic. |
||
29 | * |
||
30 | * @return string |
||
31 | */ |
||
32 | public function inAmharic() : string |
||
36 | |||
37 | /** |
||
38 | * Function to retrieve the name in Arabic. |
||
39 | * |
||
40 | * @return string |
||
41 | */ |
||
42 | public function inArabic() : string |
||
46 | |||
47 | /** |
||
48 | * Function to retrieve the name in Armenian. |
||
49 | * |
||
50 | * @return string |
||
51 | */ |
||
52 | public function inArmenian() : string |
||
56 | |||
57 | /** |
||
58 | * Function to retrieve the name in Azerbaijani. |
||
59 | * |
||
60 | * @return string |
||
61 | */ |
||
62 | public function inAzerbaijani() : string |
||
66 | |||
67 | /** |
||
68 | * Function to retrieve the name in Basque. |
||
69 | * |
||
70 | * @return string |
||
71 | */ |
||
72 | public function inBasque() : string |
||
76 | |||
77 | /** |
||
78 | * Function to retrieve the name in Belarusian. |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | public function inBelarusian() : string |
||
86 | |||
87 | /** |
||
88 | * Function to retrieve the name in Bengali. |
||
89 | * |
||
90 | * @return string |
||
91 | */ |
||
92 | public function inBengali() : string |
||
96 | |||
97 | /** |
||
98 | * Function to retrieve the name in Bosnian. |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | public function inBosnian() : string |
||
106 | |||
107 | /** |
||
108 | * Function to retrieve the name in Bulgarian. |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | public function inBulgarian() : string |
||
116 | |||
117 | /** |
||
118 | * Function to retrieve the name in Catalan. |
||
119 | * |
||
120 | * @return string |
||
121 | */ |
||
122 | public function inCatalan() : string |
||
126 | |||
127 | /** |
||
128 | * Function to retrieve the name in Cebuano. |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | public function inCebuano() : string |
||
136 | |||
137 | /** |
||
138 | * Function to retrieve the name in Chichewa. |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | public function inChichewa() : string |
||
146 | |||
147 | /** |
||
148 | * Function to retrieve the name in Chinese (Simplified). |
||
149 | * |
||
150 | * @return string |
||
151 | */ |
||
152 | public function inSimplifiedChinese() : string |
||
156 | |||
157 | /** |
||
158 | * Function to retrieve the name in Chinese (Traditional). |
||
159 | * |
||
160 | * @return string |
||
161 | */ |
||
162 | public function inTraditionalChinese() : string |
||
166 | |||
167 | /** |
||
168 | * Function to retrieve the name in Corsican. |
||
169 | * |
||
170 | * @return string |
||
171 | */ |
||
172 | public function inCorsican() : string |
||
176 | |||
177 | /** |
||
178 | * Function to retrieve the name in Croatian. |
||
179 | * |
||
180 | * @return string |
||
181 | */ |
||
182 | public function inCroatian() : string |
||
186 | |||
187 | /** |
||
188 | * Function to retrieve the name in Czech. |
||
189 | * |
||
190 | * @return string |
||
191 | */ |
||
192 | public function inCzech() : string |
||
196 | |||
197 | /** |
||
198 | * Function to retrieve the name in Danish. |
||
199 | * |
||
200 | * @return string |
||
201 | */ |
||
202 | public function inDanish() : string |
||
206 | |||
207 | /** |
||
208 | * Function to retrieve the name in Dutch. |
||
209 | * |
||
210 | * @return string |
||
211 | */ |
||
212 | public function inDutch() : string |
||
216 | |||
217 | /** |
||
218 | * Function to retrieve the name in English. |
||
219 | * |
||
220 | * @return string |
||
221 | */ |
||
222 | public function inEnglish() : string |
||
226 | |||
227 | /** |
||
228 | * Function to retrieve the name in Esperanto. |
||
229 | * |
||
230 | * @return string |
||
231 | */ |
||
232 | public function inEsperanto() : string |
||
236 | |||
237 | /** |
||
238 | * Function to retrieve the name in Estonian. |
||
239 | * |
||
240 | * @return string |
||
241 | */ |
||
242 | public function inEstonian() : string |
||
246 | |||
247 | /** |
||
248 | * Function to retrieve the name in Filipino. |
||
249 | * |
||
250 | * @return string |
||
251 | */ |
||
252 | public function inFilipino() : string |
||
256 | |||
257 | /** |
||
258 | * Function to retrieve the name in Finnish. |
||
259 | * |
||
260 | * @return string |
||
261 | */ |
||
262 | public function inFinnish() : string |
||
266 | |||
267 | /** |
||
268 | * Function to retrieve the name in French. |
||
269 | * |
||
270 | * @return string |
||
271 | */ |
||
272 | public function inFrench() : string |
||
276 | |||
277 | /** |
||
278 | * Function to retrieve the name in Frisian. |
||
279 | * |
||
280 | * @return string |
||
281 | */ |
||
282 | public function inFrisian() : string |
||
286 | |||
287 | /** |
||
288 | * Function to retrieve the name in Galician. |
||
289 | * |
||
290 | * @return string |
||
291 | */ |
||
292 | public function inGalician() : string |
||
296 | |||
297 | /** |
||
298 | * Function to retrieve the name in Georgian. |
||
299 | * |
||
300 | * @return string |
||
301 | */ |
||
302 | public function inGeorgian() : string |
||
306 | |||
307 | /** |
||
308 | * Function to retrieve the name in German. |
||
309 | * |
||
310 | * @return string |
||
311 | */ |
||
312 | public function inGerman() : string |
||
316 | |||
317 | /** |
||
318 | * Function to retrieve the name in Greek. |
||
319 | * |
||
320 | * @return string |
||
321 | */ |
||
322 | public function inGreek() : string |
||
326 | |||
327 | /** |
||
328 | * Function to retrieve the name in Gujarati. |
||
329 | * |
||
330 | * @return string |
||
331 | */ |
||
332 | public function inGujarati() : string |
||
336 | |||
337 | /** |
||
338 | * Function to retrieve the name in Haitian Creole. |
||
339 | * |
||
340 | * @return string |
||
341 | */ |
||
342 | public function inHaitianCreole() : string |
||
346 | |||
347 | /** |
||
348 | * Function to retrieve the name in Hausa. |
||
349 | * |
||
350 | * @return string |
||
351 | */ |
||
352 | public function inHausa() : string |
||
356 | |||
357 | /** |
||
358 | * Function to retrieve the name in Hawaiian. |
||
359 | * |
||
360 | * @return string |
||
361 | */ |
||
362 | public function inHawaiian() : string |
||
366 | |||
367 | /** |
||
368 | * Function to retrieve the name in Hebrew. |
||
369 | * |
||
370 | * @return string |
||
371 | */ |
||
372 | public function inHebrew() : string |
||
376 | |||
377 | /** |
||
378 | * Function to retrieve the name in Hindi. |
||
379 | * |
||
380 | * @return string |
||
381 | */ |
||
382 | public function inHindi() : string |
||
386 | |||
387 | /** |
||
388 | * Function to retrieve the name in Hmong. |
||
389 | * |
||
390 | * @return string |
||
391 | */ |
||
392 | public function inHmong() : string |
||
396 | |||
397 | /** |
||
398 | * Function to retrieve the name in Hungarian. |
||
399 | * |
||
400 | * @return string |
||
401 | */ |
||
402 | public function inHungarian() : string |
||
406 | |||
407 | /** |
||
408 | * Function to retrieve the name in Icelandic. |
||
409 | * |
||
410 | * @return string |
||
411 | */ |
||
412 | public function inIcelandic() : string |
||
416 | |||
417 | /** |
||
418 | * Function to retrieve the name in Igbo. |
||
419 | * |
||
420 | * @return string |
||
421 | */ |
||
422 | public function inIgbo() : string |
||
426 | |||
427 | /** |
||
428 | * Function to retrieve the name in Indonesian. |
||
429 | * |
||
430 | * @return string |
||
431 | */ |
||
432 | public function inIndonesian() : string |
||
436 | |||
437 | /** |
||
438 | * Function to retrieve the name in Irish. |
||
439 | * |
||
440 | * @return string |
||
441 | */ |
||
442 | public function inIrish() : string |
||
446 | |||
447 | /** |
||
448 | * Function to retrieve the name in Italian. |
||
449 | * |
||
450 | * @return string |
||
451 | */ |
||
452 | public function inItalian() : string |
||
456 | |||
457 | /** |
||
458 | * Function to retrieve the name in Japanese. |
||
459 | * |
||
460 | * @return string |
||
461 | */ |
||
462 | public function inJapanese() : string |
||
466 | |||
467 | /** |
||
468 | * Function to retrieve the name in Javanese. |
||
469 | * |
||
470 | * @return string |
||
471 | */ |
||
472 | public function inJavanese() : string |
||
476 | |||
477 | /** |
||
478 | * Function to retrieve the name in Kannada. |
||
479 | * |
||
480 | * @return string |
||
481 | */ |
||
482 | public function inKannada() : string |
||
486 | |||
487 | /** |
||
488 | * Function to retrieve the name in Kazakh. |
||
489 | * |
||
490 | * @return string |
||
491 | */ |
||
492 | public function inKazakh() : string |
||
496 | |||
497 | /** |
||
498 | * Function to retrieve the name in Khmer. |
||
499 | * |
||
500 | * @return string |
||
501 | */ |
||
502 | public function inKhmer() : string |
||
506 | |||
507 | /** |
||
508 | * Function to retrieve the name in Korean. |
||
509 | * |
||
510 | * @return string |
||
511 | */ |
||
512 | public function inKorean() : string |
||
516 | |||
517 | /** |
||
518 | * Function to retrieve the name in Kurdish (Kurmanji). |
||
519 | * |
||
520 | * @return string |
||
521 | */ |
||
522 | public function inKurmanjiKurdish() : string |
||
526 | |||
527 | /** |
||
528 | * Function to retrieve the name in Kyrgyz. |
||
529 | * |
||
530 | * @return string |
||
531 | */ |
||
532 | public function inKyrgyz() : string |
||
536 | |||
537 | /** |
||
538 | * Function to retrieve the name in Lao. |
||
539 | * |
||
540 | * @return string |
||
541 | */ |
||
542 | public function inLao() : string |
||
546 | |||
547 | /** |
||
548 | * Function to retrieve the name in Latin. |
||
549 | * |
||
550 | * @return string |
||
551 | */ |
||
552 | public function inLatin() : string |
||
556 | |||
557 | /** |
||
558 | * Function to retrieve the name in Latvian. |
||
559 | * |
||
560 | * @return string |
||
561 | */ |
||
562 | public function inLatvian() : string |
||
566 | |||
567 | /** |
||
568 | * Function to retrieve the name in Lithuanian. |
||
569 | * |
||
570 | * @return string |
||
571 | */ |
||
572 | public function inLithuanian() : string |
||
576 | |||
577 | /** |
||
578 | * Function to retrieve the name in Luxembourgish. |
||
579 | * |
||
580 | * @return string |
||
581 | */ |
||
582 | public function inLuxembourgish() : string |
||
586 | |||
587 | /** |
||
588 | * Function to retrieve the name in Macedonian. |
||
589 | * |
||
590 | * @return string |
||
591 | */ |
||
592 | public function inMacedonian() : string |
||
596 | |||
597 | /** |
||
598 | * Function to retrieve the name in Malagasy. |
||
599 | * |
||
600 | * @return string |
||
601 | */ |
||
602 | public function inMalagasy() : string |
||
606 | |||
607 | /** |
||
608 | * Function to retrieve the name in Malay. |
||
609 | * |
||
610 | * @return string |
||
611 | */ |
||
612 | public function inMalay() : string |
||
616 | |||
617 | /** |
||
618 | * Function to retrieve the name in Malayalam. |
||
619 | * |
||
620 | * @return string |
||
621 | */ |
||
622 | public function inMalayalam() : string |
||
626 | |||
627 | /** |
||
628 | * Function to retrieve the name in Maltese. |
||
629 | * |
||
630 | * @return string |
||
631 | */ |
||
632 | public function inMaltese() : string |
||
636 | |||
637 | /** |
||
638 | * Function to retrieve the name in Maori. |
||
639 | * |
||
640 | * @return string |
||
641 | */ |
||
642 | public function inMaori() : string |
||
646 | |||
647 | /** |
||
648 | * Function to retrieve the name in Marathi. |
||
649 | * |
||
650 | * @return string |
||
651 | */ |
||
652 | public function inMarathi() : string |
||
656 | |||
657 | /** |
||
658 | * Function to retrieve the name in Mongolian. |
||
659 | * |
||
660 | * @return string |
||
661 | */ |
||
662 | public function inMongolian() : string |
||
666 | |||
667 | /** |
||
668 | * Function to retrieve the name in Myanmar (Burmese). |
||
669 | * |
||
670 | * @return string |
||
671 | */ |
||
672 | public function inBurmeseMyanmar() : string |
||
676 | |||
677 | /** |
||
678 | * Function to retrieve the name in Nepali. |
||
679 | * |
||
680 | * @return string |
||
681 | */ |
||
682 | public function inNepali() : string |
||
686 | |||
687 | /** |
||
688 | * Function to retrieve the name in Norwegian. |
||
689 | * |
||
690 | * @return string |
||
691 | */ |
||
692 | public function inNorwegian() : string |
||
696 | |||
697 | /** |
||
698 | * Function to retrieve the name in Pashto. |
||
699 | * |
||
700 | * @return string |
||
701 | */ |
||
702 | public function inPashto() : string |
||
706 | |||
707 | /** |
||
708 | * Function to retrieve the name in Persian. |
||
709 | * |
||
710 | * @return string |
||
711 | */ |
||
712 | public function inPersian() : string |
||
716 | |||
717 | /** |
||
718 | * Function to retrieve the name in Polish. |
||
719 | * |
||
720 | * @return string |
||
721 | */ |
||
722 | public function inPolish() : string |
||
726 | |||
727 | /** |
||
728 | * Function to retrieve the name in Portuguese. |
||
729 | * |
||
730 | * @return string |
||
731 | */ |
||
732 | public function inPortuguese() : string |
||
736 | |||
737 | /** |
||
738 | * Function to retrieve the name in Punjabi. |
||
739 | * |
||
740 | * @return string |
||
741 | */ |
||
742 | public function inPunjabi() : string |
||
746 | |||
747 | /** |
||
748 | * Function to retrieve the name in Romanian. |
||
749 | * |
||
750 | * @return string |
||
751 | */ |
||
752 | public function inRomanian() : string |
||
756 | |||
757 | /** |
||
758 | * Function to retrieve the name in Russian. |
||
759 | * |
||
760 | * @return string |
||
761 | */ |
||
762 | public function inRussian() : string |
||
766 | |||
767 | /** |
||
768 | * Function to retrieve the name in Samoan. |
||
769 | * |
||
770 | * @return string |
||
771 | */ |
||
772 | public function inSamoan() : string |
||
776 | |||
777 | /** |
||
778 | * Function to retrieve the name in Scots Gaelic. |
||
779 | * |
||
780 | * @return string |
||
781 | */ |
||
782 | public function inScotsGaelic() : string |
||
786 | |||
787 | /** |
||
788 | * Function to retrieve the name in Serbian. |
||
789 | * |
||
790 | * @return string |
||
791 | */ |
||
792 | public function inSerbian() : string |
||
796 | |||
797 | /** |
||
798 | * Function to retrieve the name in Sesotho. |
||
799 | * |
||
800 | * @return string |
||
801 | */ |
||
802 | public function inSesotho() : string |
||
806 | |||
807 | /** |
||
808 | * Function to retrieve the name in Shona. |
||
809 | * |
||
810 | * @return string |
||
811 | */ |
||
812 | public function inShona() : string |
||
816 | |||
817 | /** |
||
818 | * Function to retrieve the name in Sindhi. |
||
819 | * |
||
820 | * @return string |
||
821 | */ |
||
822 | public function inSindhi() : string |
||
826 | |||
827 | /** |
||
828 | * Function to retrieve the name in Sinhala. |
||
829 | * |
||
830 | * @return string |
||
831 | */ |
||
832 | public function inSinhala() : string |
||
836 | |||
837 | /** |
||
838 | * Function to retrieve the name in Slovak. |
||
839 | * |
||
840 | * @return string |
||
841 | */ |
||
842 | public function inSlovak() : string |
||
846 | |||
847 | /** |
||
848 | * Function to retrieve the name in Slovenian. |
||
849 | * |
||
850 | * @return string |
||
851 | */ |
||
852 | public function inSlovenian() : string |
||
856 | |||
857 | /** |
||
858 | * Function to retrieve the name in Somali. |
||
859 | * |
||
860 | * @return string |
||
861 | */ |
||
862 | public function inSomali() : string |
||
866 | |||
867 | /** |
||
868 | * Function to retrieve the name in Spanish. |
||
869 | * |
||
870 | * @return string |
||
871 | */ |
||
872 | public function inSpanish() : string |
||
876 | |||
877 | /** |
||
878 | * Function to retrieve the name in Sundanese. |
||
879 | * |
||
880 | * @return string |
||
881 | */ |
||
882 | public function inSundanese() : string |
||
886 | |||
887 | /** |
||
888 | * Function to retrieve the name in Swahili. |
||
889 | * |
||
890 | * @return string |
||
891 | */ |
||
892 | public function inSwahili() : string |
||
896 | |||
897 | /** |
||
898 | * Function to retrieve the name in Swedish. |
||
899 | * |
||
900 | * @return string |
||
901 | */ |
||
902 | public function inSwedish() : string |
||
906 | |||
907 | /** |
||
908 | * Function to retrieve the name in Tajik. |
||
909 | * |
||
910 | * @return string |
||
911 | */ |
||
912 | public function inTajik() : string |
||
916 | |||
917 | /** |
||
918 | * Function to retrieve the name in Tamil. |
||
919 | * |
||
920 | * @return string |
||
921 | */ |
||
922 | public function inTamil() : string |
||
926 | |||
927 | /** |
||
928 | * Function to retrieve the name in Telugu. |
||
929 | * |
||
930 | * @return string |
||
931 | */ |
||
932 | public function inTelugu() : string |
||
936 | |||
937 | /** |
||
938 | * Function to retrieve the name in Thai. |
||
939 | * |
||
940 | * @return string |
||
941 | */ |
||
942 | public function inThai() : string |
||
946 | |||
947 | /** |
||
948 | * Function to retrieve the name in Turkish. |
||
949 | * |
||
950 | * @return string |
||
951 | */ |
||
952 | public function inTurkish() : string |
||
956 | |||
957 | /** |
||
958 | * Function to retrieve the name in Ukrainian. |
||
959 | * |
||
960 | * @return string |
||
961 | */ |
||
962 | public function inUkrainian() : string |
||
966 | |||
967 | /** |
||
968 | * Function to retrieve the name in Urdu. |
||
969 | * |
||
970 | * @return string |
||
971 | */ |
||
972 | public function inUrdu() : string |
||
976 | |||
977 | /** |
||
978 | * Function to retrieve the name in Uzbek. |
||
979 | * |
||
980 | * @return string |
||
981 | */ |
||
982 | public function inUzbek() : string |
||
986 | |||
987 | /** |
||
988 | * Function to retrieve the name in Vietnamese. |
||
989 | * |
||
990 | * @return string |
||
991 | */ |
||
992 | public function inVietnamese() : string |
||
996 | |||
997 | /** |
||
998 | * Function to retrieve the name in Welsh. |
||
999 | * |
||
1000 | * @return string |
||
1001 | */ |
||
1002 | public function inWelsh() : string |
||
1006 | |||
1007 | /** |
||
1008 | * Function to retrieve the name in Xhosa. |
||
1009 | * |
||
1010 | * @return string |
||
1011 | */ |
||
1012 | public function inXhosa() : string |
||
1016 | |||
1017 | /** |
||
1018 | * Function to retrieve the name in Yiddish. |
||
1019 | * |
||
1020 | * @return string |
||
1021 | */ |
||
1022 | public function inYiddish() : string |
||
1026 | |||
1027 | /** |
||
1028 | * Function to retrieve the name in Yoruba. |
||
1029 | * |
||
1030 | * @return string |
||
1031 | */ |
||
1032 | public function inYoruba() : string |
||
1036 | |||
1037 | /** |
||
1038 | * Function to retrieve the name in Zulu. |
||
1039 | * |
||
1040 | * @return string |
||
1041 | */ |
||
1042 | public function inZulu() : string |
||
1046 | } |
||
1047 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.