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() |
||
| 73 | { |
||
| 74 | return isset($this->id); |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @return boolean |
||
| 79 | */ |
||
| 80 | public function hasCountryCode() |
||
| 81 | { |
||
| 82 | return isset($this->countryCode); |
||
| 83 | } |
||
| 84 | |||
| 85 | public function hasInternationalPrefix() |
||
| 86 | { |
||
| 87 | return isset($this->internationalPrefix); |
||
| 88 | } |
||
| 89 | |||
| 90 | public function hasMainCountryForCode() |
||
| 91 | { |
||
| 92 | return isset($this->mainCountryForCode); |
||
| 93 | } |
||
| 94 | |||
| 95 | 2 | public function isMainCountryForCode() |
|
| 99 | |||
| 100 | public function getMainCountryForCode() |
||
| 101 | { |
||
| 102 | return $this->mainCountryForCode; |
||
| 103 | } |
||
| 104 | |||
| 105 | 867 | public function setMainCountryForCode($value) |
|
| 110 | |||
| 111 | public function hasLeadingZeroPossible() |
||
| 112 | { |
||
| 113 | return isset($this->leadingZeroPossible); |
||
| 114 | } |
||
| 115 | |||
| 116 | public function hasMobileNumberPortableRegion() |
||
| 117 | { |
||
| 118 | return isset($this->mobileNumberPortableRegion); |
||
| 119 | } |
||
| 120 | |||
| 121 | 1 | public function hasSameMobileAndFixedLinePattern() |
|
| 125 | |||
| 126 | 2 | public function numberFormatSize() |
|
| 127 | { |
||
| 128 | 2 | return count($this->numberFormat); |
|
| 129 | } |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @param int $index |
||
| 133 | * @return NumberFormat |
||
| 134 | */ |
||
| 135 | 11 | public function getNumberFormat($index) |
|
| 139 | |||
| 140 | public function intlNumberFormatSize() |
||
| 141 | { |
||
| 142 | return count($this->intlNumberFormat); |
||
| 143 | } |
||
| 144 | |||
| 145 | 6 | public function getIntlNumberFormat($index) |
|
| 149 | |||
| 150 | 7 | public function clearIntlNumberFormat() |
|
| 155 | |||
| 156 | public function toArray() |
||
| 157 | { |
||
| 158 | $output = array(); |
||
| 159 | |||
| 160 | if ($this->hasGeneralDesc()) { |
||
| 161 | $output['generalDesc'] = $this->getGeneralDesc()->toArray(); |
||
| 162 | } |
||
| 163 | |||
| 164 | if ($this->hasFixedLine()) { |
||
| 287 | |||
| 288 | public function hasGeneralDesc() |
||
| 292 | |||
| 293 | /** |
||
| 294 | * @return PhoneNumberDesc |
||
| 295 | */ |
||
| 296 | 2780 | public function getGeneralDesc() |
|
| 300 | |||
| 301 | 872 | public function setGeneralDesc(PhoneNumberDesc $value) |
|
| 306 | |||
| 307 | public function hasFixedLine() |
||
| 311 | |||
| 312 | /** |
||
| 313 | * @return PhoneNumberDesc |
||
| 314 | */ |
||
| 315 | 1520 | public function getFixedLine() |
|
| 319 | |||
| 320 | 613 | public function setFixedLine(PhoneNumberDesc $value) |
|
| 325 | |||
| 326 | public function hasMobile() |
||
| 330 | |||
| 331 | /** |
||
| 332 | * @return PhoneNumberDesc |
||
| 333 | */ |
||
| 334 | 1128 | public function getMobile() |
|
| 338 | |||
| 339 | 613 | public function setMobile(PhoneNumberDesc $value) |
|
| 344 | |||
| 345 | public function hasTollFree() |
||
| 349 | |||
| 350 | /** |
||
| 351 | * @return PhoneNumberDesc |
||
| 352 | */ |
||
| 353 | 2149 | public function getTollFree() |
|
| 357 | |||
| 358 | 869 | public function setTollFree(PhoneNumberDesc $value) |
|
| 363 | |||
| 364 | public function hasPremiumRate() |
||
| 368 | |||
| 369 | /** |
||
| 370 | * @return PhoneNumberDesc |
||
| 371 | */ |
||
| 372 | 2377 | public function getPremiumRate() |
|
| 376 | |||
| 377 | 869 | public function setPremiumRate(PhoneNumberDesc $value) |
|
| 382 | |||
| 383 | public function hasSharedCost() |
||
| 387 | |||
| 388 | /** |
||
| 389 | * @return PhoneNumberDesc |
||
| 390 | */ |
||
| 391 | 1602 | public function getSharedCost() |
|
| 395 | |||
| 396 | 613 | public function setSharedCost(PhoneNumberDesc $value) |
|
| 401 | |||
| 402 | public function hasPersonalNumber() |
||
| 406 | |||
| 407 | /** |
||
| 408 | * @return PhoneNumberDesc |
||
| 409 | */ |
||
| 410 | 1458 | public function getPersonalNumber() |
|
| 414 | |||
| 415 | 613 | public function setPersonalNumber(PhoneNumberDesc $value) |
|
| 420 | |||
| 421 | public function hasVoip() |
||
| 425 | |||
| 426 | /** |
||
| 427 | * @return PhoneNumberDesc |
||
| 428 | */ |
||
| 429 | 1521 | public function getVoip() |
|
| 433 | |||
| 434 | 613 | public function setVoip(PhoneNumberDesc $value) |
|
| 439 | |||
| 440 | public function hasPager() |
||
| 444 | |||
| 445 | /** |
||
| 446 | * @return PhoneNumberDesc |
||
| 447 | */ |
||
| 448 | 1433 | public function getPager() |
|
| 452 | |||
| 453 | 613 | public function setPager(PhoneNumberDesc $value) |
|
| 458 | |||
| 459 | public function hasUan() |
||
| 463 | |||
| 464 | /** |
||
| 465 | * @return PhoneNumberDesc |
||
| 466 | */ |
||
| 467 | 1381 | public function getUan() |
|
| 471 | |||
| 472 | 613 | public function setUan(PhoneNumberDesc $value) |
|
| 477 | |||
| 478 | 274 | public function hasEmergency() |
|
| 482 | |||
| 483 | /** |
||
| 484 | * @return PhoneNumberDesc |
||
| 485 | */ |
||
| 486 | 275 | public function getEmergency() |
|
| 490 | |||
| 491 | 263 | public function setEmergency(PhoneNumberDesc $value) |
|
| 496 | |||
| 497 | public function hasVoicemail() |
||
| 501 | |||
| 502 | /** |
||
| 503 | * @return PhoneNumberDesc |
||
| 504 | */ |
||
| 505 | 1365 | public function getVoicemail() |
|
| 509 | |||
| 510 | 613 | public function setVoicemail(PhoneNumberDesc $value) |
|
| 515 | |||
| 516 | public function hasShortCode() |
||
| 520 | |||
| 521 | 251 | public function getShortCode() |
|
| 525 | |||
| 526 | 263 | public function setShortCode(PhoneNumberDesc $value) |
|
| 531 | |||
| 532 | public function hasStandardRate() |
||
| 536 | |||
| 537 | 528 | public function getStandardRate() |
|
| 541 | |||
| 542 | 263 | public function setStandardRate(PhoneNumberDesc $value) |
|
| 547 | |||
| 548 | public function hasCarrierSpecific() |
||
| 552 | |||
| 553 | 239 | public function getCarrierSpecific() |
|
| 557 | |||
| 558 | 263 | public function setCarrierSpecific(PhoneNumberDesc $value) |
|
| 563 | |||
| 564 | public function hasNoInternationalDialling() |
||
| 568 | |||
| 569 | 246 | public function getNoInternationalDialling() |
|
| 573 | |||
| 574 | 613 | public function setNoInternationalDialling(PhoneNumberDesc $value) |
|
| 579 | |||
| 580 | /** |
||
| 581 | * @return string |
||
| 582 | */ |
||
| 583 | 12 | public function getId() |
|
| 587 | |||
| 588 | /** |
||
| 589 | * @param string $value |
||
| 590 | * @return PhoneMetadata |
||
| 591 | */ |
||
| 592 | 873 | public function setId($value) |
|
| 597 | |||
| 598 | /** |
||
| 599 | * @return int |
||
| 600 | */ |
||
| 601 | 2734 | public function getCountryCode() |
|
| 605 | |||
| 606 | /** |
||
| 607 | * @param int $value |
||
| 608 | * @return PhoneMetadata |
||
| 609 | */ |
||
| 610 | 873 | public function setCountryCode($value) |
|
| 615 | |||
| 616 | 2727 | public function getInternationalPrefix() |
|
| 620 | |||
| 621 | 873 | public function setInternationalPrefix($value) |
|
| 626 | |||
| 627 | 3 | public function hasPreferredInternationalPrefix() |
|
| 631 | |||
| 632 | 5 | public function getPreferredInternationalPrefix() |
|
| 636 | |||
| 637 | 63 | public function setPreferredInternationalPrefix($value) |
|
| 642 | |||
| 643 | 2 | public function hasNationalPrefix() |
|
| 647 | |||
| 648 | 8 | public function getNationalPrefix() |
|
| 652 | |||
| 653 | 393 | public function setNationalPrefix($value) |
|
| 658 | |||
| 659 | 2 | public function hasPreferredExtnPrefix() |
|
| 663 | |||
| 664 | 2 | public function getPreferredExtnPrefix() |
|
| 668 | |||
| 669 | 85 | public function setPreferredExtnPrefix($value) |
|
| 674 | |||
| 675 | 3 | public function hasNationalPrefixForParsing() |
|
| 679 | |||
| 680 | 2739 | public function getNationalPrefixForParsing() |
|
| 684 | |||
| 685 | 404 | public function setNationalPrefixForParsing($value) |
|
| 690 | |||
| 691 | public function hasNationalPrefixTransformRule() |
||
| 695 | |||
| 696 | 73 | public function getNationalPrefixTransformRule() |
|
| 700 | |||
| 701 | 29 | public function setNationalPrefixTransformRule($value) |
|
| 706 | |||
| 707 | 1121 | public function isSameMobileAndFixedLinePattern() |
|
| 711 | |||
| 712 | 2 | public function setSameMobileAndFixedLinePattern($value) |
|
| 717 | |||
| 718 | /** |
||
| 719 | * @return NumberFormat[] |
||
| 720 | */ |
||
| 721 | 41 | public function numberFormats() |
|
| 725 | |||
| 726 | 44 | public function intlNumberFormats() |
|
| 730 | |||
| 731 | /** |
||
| 732 | * @return bool |
||
| 733 | */ |
||
| 734 | 521 | public function hasLeadingDigits() |
|
| 738 | |||
| 739 | 175 | public function getLeadingDigits() |
|
| 743 | |||
| 744 | 54 | public function setLeadingDigits($value) |
|
| 749 | |||
| 750 | 4 | public function isLeadingZeroPossible() |
|
| 754 | |||
| 755 | 867 | public function setLeadingZeroPossible($value) |
|
| 760 | |||
| 761 | 5 | public function isMobileNumberPortableRegion() |
|
| 765 | |||
| 766 | 867 | public function setMobileNumberPortableRegion($value) |
|
| 771 | |||
| 772 | /** |
||
| 773 | * @param array $input |
||
| 774 | * @return PhoneMetadata |
||
| 775 | */ |
||
| 776 | 866 | public function fromArray(array $input) |
|
| 912 | |||
| 913 | 564 | public function addNumberFormat(NumberFormat $value) |
|
| 918 | |||
| 919 | 134 | public function addIntlNumberFormat(NumberFormat $value) |
|
| 924 | } |
||
| 925 |