Complex classes like PhoneMetadata 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 PhoneMetadata, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
10 | class PhoneMetadata |
||
11 | { |
||
12 | /** |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $id = null; |
||
16 | /** |
||
17 | * @var int |
||
18 | */ |
||
19 | protected $countryCode = null; |
||
20 | protected $leadingDigits = null; |
||
21 | protected $internationalPrefix = null; |
||
22 | protected $preferredInternationalPrefix = null; |
||
23 | protected $nationalPrefixForParsing = null; |
||
24 | protected $nationalPrefixTransformRule = null; |
||
25 | protected $nationalPrefix = null; |
||
26 | protected $preferredExtnPrefix = null; |
||
27 | protected $mainCountryForCode = false; |
||
28 | protected $leadingZeroPossible = false; |
||
29 | protected $mobileNumberPortableRegion = false; |
||
30 | protected $generalDesc = null; |
||
31 | /** |
||
32 | * @var PhoneNumberDesc |
||
33 | */ |
||
34 | protected $mobile = null; |
||
35 | protected $premiumRate = null; |
||
36 | protected $fixedLine = null; |
||
37 | protected $sameMobileAndFixedLinePattern = false; |
||
38 | protected $numberFormat = array(); |
||
39 | protected $tollFree = null; |
||
40 | protected $sharedCost = null; |
||
41 | protected $personalNumber; |
||
42 | protected $voip; |
||
43 | protected $pager; |
||
44 | protected $uan; |
||
45 | protected $emergency; |
||
46 | protected $voicemail; |
||
47 | /** |
||
48 | * @var PhoneNumberDesc |
||
49 | */ |
||
50 | protected $short_code; |
||
51 | /** |
||
52 | * @var PhoneNumberDesc |
||
53 | */ |
||
54 | protected $standard_rate; |
||
55 | /** |
||
56 | * @var PhoneNumberDesc |
||
57 | */ |
||
58 | protected $carrierSpecific; |
||
59 | /** |
||
60 | * @var PhoneNumberDesc |
||
61 | */ |
||
62 | protected $noInternationalDialling = null; |
||
63 | /** |
||
64 | * |
||
65 | * @var NumberFormat[] |
||
66 | */ |
||
67 | protected $intlNumberFormat = array(); |
||
68 | |||
69 | /** |
||
70 | * @return boolean |
||
71 | */ |
||
72 | public function hasId() |
||
76 | |||
77 | /** |
||
78 | * @return boolean |
||
79 | */ |
||
80 | public function hasCountryCode() |
||
84 | |||
85 | public function hasInternationalPrefix() |
||
89 | |||
90 | public function hasMainCountryForCode() |
||
94 | |||
95 | public function isMainCountryForCode() |
||
99 | |||
100 | public function getMainCountryForCode() |
||
104 | |||
105 | public function setMainCountryForCode($value) |
||
110 | |||
111 | public function clearMainCountryForCode() |
||
116 | |||
117 | public function hasLeadingZeroPossible() |
||
121 | |||
122 | public function hasMobileNumberPortableRegion() |
||
126 | |||
127 | public function hasSameMobileAndFixedLinePattern() |
||
131 | |||
132 | public function numberFormatSize() |
||
136 | |||
137 | /** |
||
138 | * @param int $index |
||
139 | * @return NumberFormat |
||
140 | */ |
||
141 | public function getNumberFormat($index) |
||
145 | |||
146 | public function intlNumberFormatSize() |
||
150 | |||
151 | public function getIntlNumberFormat($index) |
||
155 | |||
156 | public function clearIntlNumberFormat() |
||
161 | |||
162 | public function toArray() |
||
293 | |||
294 | public function hasGeneralDesc() |
||
298 | |||
299 | /** |
||
300 | * @return PhoneNumberDesc |
||
301 | */ |
||
302 | public function getGeneralDesc() |
||
306 | |||
307 | public function setGeneralDesc(PhoneNumberDesc $value) |
||
312 | |||
313 | public function hasFixedLine() |
||
317 | |||
318 | /** |
||
319 | * @return PhoneNumberDesc |
||
320 | */ |
||
321 | public function getFixedLine() |
||
325 | |||
326 | public function setFixedLine(PhoneNumberDesc $value) |
||
331 | |||
332 | public function hasMobile() |
||
336 | |||
337 | /** |
||
338 | * @return PhoneNumberDesc |
||
339 | */ |
||
340 | public function getMobile() |
||
344 | |||
345 | public function setMobile(PhoneNumberDesc $value) |
||
350 | |||
351 | public function hasTollFree() |
||
355 | |||
356 | /** |
||
357 | * @return PhoneNumberDesc |
||
358 | */ |
||
359 | public function getTollFree() |
||
363 | |||
364 | public function setTollFree(PhoneNumberDesc $value) |
||
369 | |||
370 | public function hasPremiumRate() |
||
374 | |||
375 | /** |
||
376 | * @return PhoneNumberDesc |
||
377 | */ |
||
378 | public function getPremiumRate() |
||
382 | |||
383 | public function setPremiumRate(PhoneNumberDesc $value) |
||
388 | |||
389 | public function hasSharedCost() |
||
393 | |||
394 | /** |
||
395 | * @return PhoneNumberDesc |
||
396 | */ |
||
397 | public function getSharedCost() |
||
401 | |||
402 | public function setSharedCost(PhoneNumberDesc $value) |
||
407 | |||
408 | public function hasPersonalNumber() |
||
412 | |||
413 | /** |
||
414 | * @return PhoneNumberDesc |
||
415 | */ |
||
416 | public function getPersonalNumber() |
||
420 | |||
421 | public function setPersonalNumber(PhoneNumberDesc $value) |
||
426 | |||
427 | public function hasVoip() |
||
431 | |||
432 | /** |
||
433 | * @return PhoneNumberDesc |
||
434 | */ |
||
435 | public function getVoip() |
||
439 | |||
440 | public function setVoip(PhoneNumberDesc $value) |
||
445 | |||
446 | public function hasPager() |
||
450 | |||
451 | /** |
||
452 | * @return PhoneNumberDesc |
||
453 | */ |
||
454 | public function getPager() |
||
458 | |||
459 | public function setPager(PhoneNumberDesc $value) |
||
464 | |||
465 | public function hasUan() |
||
469 | |||
470 | /** |
||
471 | * @return PhoneNumberDesc |
||
472 | */ |
||
473 | public function getUan() |
||
477 | |||
478 | public function setUan(PhoneNumberDesc $value) |
||
483 | |||
484 | public function hasEmergency() |
||
488 | |||
489 | /** |
||
490 | * @return PhoneNumberDesc |
||
491 | */ |
||
492 | public function getEmergency() |
||
496 | |||
497 | public function setEmergency(PhoneNumberDesc $value) |
||
502 | |||
503 | public function hasVoicemail() |
||
507 | |||
508 | /** |
||
509 | * @return PhoneNumberDesc |
||
510 | */ |
||
511 | public function getVoicemail() |
||
515 | |||
516 | public function setVoicemail(PhoneNumberDesc $value) |
||
521 | |||
522 | public function hasShortCode() |
||
526 | |||
527 | public function getShortCode() |
||
531 | |||
532 | public function setShortCode(PhoneNumberDesc $value) |
||
537 | |||
538 | public function hasStandardRate() |
||
542 | |||
543 | public function getStandardRate() |
||
547 | |||
548 | public function setStandardRate(PhoneNumberDesc $value) |
||
553 | |||
554 | public function hasCarrierSpecific() |
||
558 | |||
559 | public function getCarrierSpecific() |
||
563 | |||
564 | public function setCarrierSpecific(PhoneNumberDesc $value) |
||
569 | |||
570 | public function hasNoInternationalDialling() |
||
574 | |||
575 | public function getNoInternationalDialling() |
||
579 | |||
580 | public function setNoInternationalDialling(PhoneNumberDesc $value) |
||
585 | |||
586 | /** |
||
587 | * @return string |
||
588 | */ |
||
589 | public function getId() |
||
593 | |||
594 | /** |
||
595 | * @param string $value |
||
596 | * @return PhoneMetadata |
||
597 | */ |
||
598 | public function setId($value) |
||
603 | |||
604 | /** |
||
605 | * @return int |
||
606 | */ |
||
607 | public function getCountryCode() |
||
611 | |||
612 | /** |
||
613 | * @param int $value |
||
614 | * @return PhoneMetadata |
||
615 | */ |
||
616 | public function setCountryCode($value) |
||
621 | |||
622 | public function getInternationalPrefix() |
||
626 | |||
627 | public function setInternationalPrefix($value) |
||
632 | |||
633 | public function hasPreferredInternationalPrefix() |
||
637 | |||
638 | public function getPreferredInternationalPrefix() |
||
642 | |||
643 | public function setPreferredInternationalPrefix($value) |
||
648 | |||
649 | public function clearPreferredInternationalPrefix() |
||
654 | |||
655 | public function hasNationalPrefix() |
||
659 | |||
660 | public function getNationalPrefix() |
||
664 | |||
665 | public function setNationalPrefix($value) |
||
670 | |||
671 | public function clearNationalPrefix() |
||
676 | |||
677 | public function hasPreferredExtnPrefix() |
||
681 | |||
682 | public function getPreferredExtnPrefix() |
||
686 | |||
687 | public function setPreferredExtnPrefix($value) |
||
692 | |||
693 | public function clearPreferredExtnPrefix() |
||
698 | |||
699 | public function hasNationalPrefixForParsing() |
||
703 | |||
704 | public function getNationalPrefixForParsing() |
||
708 | |||
709 | public function setNationalPrefixForParsing($value) |
||
714 | |||
715 | public function hasNationalPrefixTransformRule() |
||
719 | |||
720 | public function getNationalPrefixTransformRule() |
||
724 | |||
725 | public function setNationalPrefixTransformRule($value) |
||
730 | |||
731 | public function clearNationalPrefixTransformRule() |
||
736 | |||
737 | public function getSameMobileAndFixedLinePattern() |
||
738 | { |
||
739 | return $this->sameMobileAndFixedLinePattern; |
||
740 | } |
||
741 | |||
742 | public function setSameMobileAndFixedLinePattern($value) |
||
747 | |||
748 | public function clearSameMobileAndFixedLinePattern() |
||
753 | |||
754 | /** |
||
755 | * @return NumberFormat[] |
||
756 | */ |
||
757 | public function numberFormats() |
||
761 | |||
762 | public function intlNumberFormats() |
||
766 | |||
767 | /** |
||
768 | * @return bool |
||
769 | */ |
||
770 | public function hasLeadingDigits() |
||
774 | |||
775 | public function getLeadingDigits() |
||
779 | |||
780 | public function setLeadingDigits($value) |
||
785 | |||
786 | public function isLeadingZeroPossible() |
||
790 | |||
791 | public function setLeadingZeroPossible($value) |
||
796 | |||
797 | public function clearLeadingZeroPossible() |
||
802 | |||
803 | public function isMobileNumberPortableRegion() |
||
807 | |||
808 | public function setMobileNumberPortableRegion($value) |
||
813 | |||
814 | public function clearMobileNumberPortableRegion() |
||
819 | |||
820 | /** |
||
821 | * @param array $input |
||
822 | * @return PhoneMetadata |
||
823 | */ |
||
824 | public function fromArray(array $input) |
||
960 | |||
961 | public function addNumberFormat(NumberFormat $value) |
||
966 | |||
967 | public function addIntlNumberFormat(NumberFormat $value) |
||
972 | } |
||
973 |