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 | 2 | public function isMainCountryForCode() |
|
99 | |||
100 | public function getMainCountryForCode() |
||
104 | |||
105 | 760 | public function setMainCountryForCode($value) |
|
110 | |||
111 | public function hasLeadingZeroPossible() |
||
115 | |||
116 | public function hasMobileNumberPortableRegion() |
||
120 | |||
121 | 1 | public function hasSameMobileAndFixedLinePattern() |
|
125 | |||
126 | public function numberFormatSize() |
||
130 | |||
131 | /** |
||
132 | * @param int $index |
||
133 | * @return NumberFormat |
||
134 | */ |
||
135 | 1 | public function getNumberFormat($index) |
|
139 | |||
140 | public function intlNumberFormatSize() |
||
144 | |||
145 | 4 | public function getIntlNumberFormat($index) |
|
149 | |||
150 | 7 | public function clearIntlNumberFormat() |
|
155 | |||
156 | public function toArray() |
||
276 | |||
277 | public function hasGeneralDesc() |
||
281 | |||
282 | /** |
||
283 | * @return PhoneNumberDesc |
||
284 | */ |
||
285 | 294 | public function getGeneralDesc() |
|
289 | |||
290 | 765 | public function setGeneralDesc(PhoneNumberDesc $value) |
|
295 | |||
296 | public function hasFixedLine() |
||
300 | |||
301 | /** |
||
302 | * @return PhoneNumberDesc |
||
303 | */ |
||
304 | 418 | public function getFixedLine() |
|
308 | |||
309 | 517 | public function setFixedLine(PhoneNumberDesc $value) |
|
314 | |||
315 | public function hasMobile() |
||
319 | |||
320 | /** |
||
321 | * @return PhoneNumberDesc |
||
322 | */ |
||
323 | 58 | public function getMobile() |
|
327 | |||
328 | 517 | public function setMobile(PhoneNumberDesc $value) |
|
333 | |||
334 | public function hasTollFree() |
||
338 | |||
339 | /** |
||
340 | * @return PhoneNumberDesc |
||
341 | */ |
||
342 | 585 | public function getTollFree() |
|
346 | |||
347 | 762 | public function setTollFree(PhoneNumberDesc $value) |
|
352 | |||
353 | public function hasPremiumRate() |
||
357 | |||
358 | /** |
||
359 | * @return PhoneNumberDesc |
||
360 | */ |
||
361 | 705 | public function getPremiumRate() |
|
365 | |||
366 | 762 | public function setPremiumRate(PhoneNumberDesc $value) |
|
371 | |||
372 | public function hasSharedCost() |
||
376 | |||
377 | /** |
||
378 | * @return PhoneNumberDesc |
||
379 | */ |
||
380 | 256 | public function getSharedCost() |
|
384 | |||
385 | 517 | public function setSharedCost(PhoneNumberDesc $value) |
|
390 | |||
391 | public function hasPersonalNumber() |
||
395 | |||
396 | /** |
||
397 | * @return PhoneNumberDesc |
||
398 | */ |
||
399 | 243 | public function getPersonalNumber() |
|
403 | |||
404 | 517 | public function setPersonalNumber(PhoneNumberDesc $value) |
|
409 | |||
410 | public function hasVoip() |
||
414 | |||
415 | /** |
||
416 | * @return PhoneNumberDesc |
||
417 | */ |
||
418 | 234 | public function getVoip() |
|
422 | |||
423 | 517 | public function setVoip(PhoneNumberDesc $value) |
|
428 | |||
429 | public function hasPager() |
||
433 | |||
434 | /** |
||
435 | * @return PhoneNumberDesc |
||
436 | */ |
||
437 | 280 | public function getPager() |
|
441 | |||
442 | 517 | public function setPager(PhoneNumberDesc $value) |
|
447 | |||
448 | public function hasUan() |
||
452 | |||
453 | /** |
||
454 | * @return PhoneNumberDesc |
||
455 | */ |
||
456 | 250 | public function getUan() |
|
460 | |||
461 | 517 | public function setUan(PhoneNumberDesc $value) |
|
466 | |||
467 | 5 | public function hasEmergency() |
|
471 | |||
472 | /** |
||
473 | * @return PhoneNumberDesc |
||
474 | */ |
||
475 | 4 | public function getEmergency() |
|
479 | |||
480 | 250 | public function setEmergency(PhoneNumberDesc $value) |
|
485 | |||
486 | public function hasVoicemail() |
||
490 | |||
491 | /** |
||
492 | * @return PhoneNumberDesc |
||
493 | */ |
||
494 | 286 | public function getVoicemail() |
|
498 | |||
499 | 517 | public function setVoicemail(PhoneNumberDesc $value) |
|
504 | |||
505 | public function hasShortCode() |
||
509 | |||
510 | 6 | public function getShortCode() |
|
514 | |||
515 | 250 | public function setShortCode(PhoneNumberDesc $value) |
|
520 | |||
521 | public function hasStandardRate() |
||
525 | |||
526 | 508 | public function getStandardRate() |
|
530 | |||
531 | 250 | public function setStandardRate(PhoneNumberDesc $value) |
|
536 | |||
537 | public function hasCarrierSpecific() |
||
541 | |||
542 | 208 | public function getCarrierSpecific() |
|
546 | |||
547 | 250 | public function setCarrierSpecific(PhoneNumberDesc $value) |
|
552 | |||
553 | public function hasNoInternationalDialling() |
||
557 | |||
558 | 215 | public function getNoInternationalDialling() |
|
562 | |||
563 | 517 | public function setNoInternationalDialling(PhoneNumberDesc $value) |
|
568 | |||
569 | /** |
||
570 | * @return string |
||
571 | */ |
||
572 | 12 | public function getId() |
|
576 | |||
577 | /** |
||
578 | * @param string $value |
||
579 | * @return PhoneMetadata |
||
580 | */ |
||
581 | 766 | public function setId($value) |
|
586 | |||
587 | /** |
||
588 | * @return int |
||
589 | */ |
||
590 | 14 | public function getCountryCode() |
|
594 | |||
595 | /** |
||
596 | * @param int $value |
||
597 | * @return PhoneMetadata |
||
598 | */ |
||
599 | 766 | public function setCountryCode($value) |
|
604 | |||
605 | 2443 | public function getInternationalPrefix() |
|
609 | |||
610 | 766 | public function setInternationalPrefix($value) |
|
615 | |||
616 | 1 | public function hasPreferredInternationalPrefix() |
|
620 | |||
621 | 3 | public function getPreferredInternationalPrefix() |
|
625 | |||
626 | 58 | public function setPreferredInternationalPrefix($value) |
|
631 | |||
632 | 1 | public function hasNationalPrefix() |
|
636 | |||
637 | 4 | public function getNationalPrefix() |
|
641 | |||
642 | 3 | public function setNationalPrefix($value) |
|
647 | |||
648 | public function hasPreferredExtnPrefix() |
||
652 | |||
653 | 2 | public function getPreferredExtnPrefix() |
|
657 | |||
658 | 78 | public function setPreferredExtnPrefix($value) |
|
663 | |||
664 | 3 | public function hasNationalPrefixForParsing() |
|
668 | |||
669 | 2171 | public function getNationalPrefixForParsing() |
|
673 | |||
674 | 319 | public function setNationalPrefixForParsing($value) |
|
679 | |||
680 | public function hasNationalPrefixTransformRule() |
||
684 | |||
685 | 51 | public function getNationalPrefixTransformRule() |
|
689 | |||
690 | 29 | public function setNationalPrefixTransformRule($value) |
|
695 | |||
696 | 54 | public function isSameMobileAndFixedLinePattern() |
|
700 | |||
701 | 2 | public function setSameMobileAndFixedLinePattern($value) |
|
706 | |||
707 | /** |
||
708 | * @return NumberFormat[] |
||
709 | */ |
||
710 | 22 | public function numberFormats() |
|
714 | |||
715 | 23 | public function intlNumberFormats() |
|
719 | |||
720 | /** |
||
721 | * @return bool |
||
722 | */ |
||
723 | 30 | public function hasLeadingDigits() |
|
727 | |||
728 | 8 | public function getLeadingDigits() |
|
732 | |||
733 | 30 | public function setLeadingDigits($value) |
|
738 | |||
739 | 2 | public function isLeadingZeroPossible() |
|
743 | |||
744 | 760 | public function setLeadingZeroPossible($value) |
|
749 | |||
750 | 4 | public function isMobileNumberPortableRegion() |
|
754 | |||
755 | 760 | public function setMobileNumberPortableRegion($value) |
|
760 | |||
761 | /** |
||
762 | * @param array $input |
||
763 | * @return PhoneMetadata |
||
764 | */ |
||
765 | 759 | public function fromArray(array $input) |
|
897 | |||
898 | 130 | public function addNumberFormat(NumberFormat $value) |
|
903 | |||
904 | 80 | public function addIntlNumberFormat(NumberFormat $value) |
|
909 | } |
||
910 |