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 |
||
| 5 | class PhoneMetadata |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * @var string |
||
| 9 | */ |
||
| 10 | protected $id = null; |
||
| 11 | /** |
||
| 12 | * @var int |
||
| 13 | */ |
||
| 14 | protected $countryCode = null; |
||
| 15 | protected $leadingDigits = null; |
||
| 16 | protected $internationalPrefix = null; |
||
| 17 | protected $preferredInternationalPrefix = null; |
||
| 18 | protected $nationalPrefixForParsing = null; |
||
| 19 | protected $nationalPrefixTransformRule = null; |
||
| 20 | protected $nationalPrefix = null; |
||
| 21 | protected $preferredExtnPrefix = null; |
||
| 22 | protected $mainCountryForCode = false; |
||
| 23 | protected $leadingZeroPossible = false; |
||
| 24 | protected $mobileNumberPortableRegion = false; |
||
| 25 | protected $generalDesc = null; |
||
| 26 | /** |
||
| 27 | * @var PhoneNumberDesc |
||
| 28 | */ |
||
| 29 | protected $mobile = null; |
||
| 30 | protected $premiumRate = null; |
||
| 31 | protected $fixedLine = null; |
||
| 32 | protected $sameMobileAndFixedLinePattern = false; |
||
| 33 | protected $numberFormat = array(); |
||
| 34 | protected $tollFree = null; |
||
| 35 | protected $sharedCost = null; |
||
| 36 | protected $personalNumber; |
||
| 37 | protected $voip; |
||
| 38 | protected $pager; |
||
| 39 | protected $uan; |
||
| 40 | protected $emergency; |
||
| 41 | protected $voicemail; |
||
| 42 | /** |
||
| 43 | * @var PhoneNumberDesc |
||
| 44 | */ |
||
| 45 | protected $short_code; |
||
| 46 | /** |
||
| 47 | * @var PhoneNumberDesc |
||
| 48 | */ |
||
| 49 | protected $standard_rate; |
||
| 50 | /** |
||
| 51 | * @var PhoneNumberDesc |
||
| 52 | */ |
||
| 53 | protected $carrierSpecific; |
||
| 54 | /** |
||
| 55 | * @var PhoneNumberDesc |
||
| 56 | */ |
||
| 57 | protected $noInternationalDialling = null; |
||
| 58 | /** |
||
| 59 | * |
||
| 60 | * @var NumberFormat[] |
||
| 61 | */ |
||
| 62 | protected $intlNumberFormat = array(); |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @return boolean |
||
| 66 | */ |
||
| 67 | public function hasId() |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @return boolean |
||
| 74 | */ |
||
| 75 | public function hasCountryCode() |
||
| 79 | |||
| 80 | public function hasInternationalPrefix() |
||
| 84 | |||
| 85 | public function hasMainCountryForCode() |
||
| 89 | |||
| 90 | 2 | public function isMainCountryForCode() |
|
| 94 | |||
| 95 | public function getMainCountryForCode() |
||
| 99 | |||
| 100 | 760 | public function setMainCountryForCode($value) |
|
| 105 | |||
| 106 | public function hasLeadingZeroPossible() |
||
| 110 | |||
| 111 | public function hasMobileNumberPortableRegion() |
||
| 115 | |||
| 116 | 1 | public function hasSameMobileAndFixedLinePattern() |
|
| 120 | |||
| 121 | public function numberFormatSize() |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @param int $index |
||
| 128 | * @return NumberFormat |
||
| 129 | */ |
||
| 130 | 1 | public function getNumberFormat($index) |
|
| 134 | |||
| 135 | public function intlNumberFormatSize() |
||
| 139 | |||
| 140 | 4 | public function getIntlNumberFormat($index) |
|
| 144 | |||
| 145 | 7 | public function clearIntlNumberFormat() |
|
| 150 | |||
| 151 | public function toArray() |
||
| 271 | |||
| 272 | public function hasGeneralDesc() |
||
| 276 | |||
| 277 | /** |
||
| 278 | * @return PhoneNumberDesc |
||
| 279 | */ |
||
| 280 | 293 | public function getGeneralDesc() |
|
| 284 | |||
| 285 | 765 | public function setGeneralDesc(PhoneNumberDesc $value) |
|
| 290 | |||
| 291 | public function hasFixedLine() |
||
| 295 | |||
| 296 | /** |
||
| 297 | * @return PhoneNumberDesc |
||
| 298 | */ |
||
| 299 | 412 | public function getFixedLine() |
|
| 303 | |||
| 304 | 517 | public function setFixedLine(PhoneNumberDesc $value) |
|
| 309 | |||
| 310 | public function hasMobile() |
||
| 314 | |||
| 315 | /** |
||
| 316 | * @return PhoneNumberDesc |
||
| 317 | */ |
||
| 318 | 63 | public function getMobile() |
|
| 322 | |||
| 323 | 517 | public function setMobile(PhoneNumberDesc $value) |
|
| 328 | |||
| 329 | public function hasTollFree() |
||
| 333 | |||
| 334 | /** |
||
| 335 | * @return PhoneNumberDesc |
||
| 336 | */ |
||
| 337 | 591 | public function getTollFree() |
|
| 341 | |||
| 342 | 762 | public function setTollFree(PhoneNumberDesc $value) |
|
| 347 | |||
| 348 | public function hasPremiumRate() |
||
| 352 | |||
| 353 | /** |
||
| 354 | * @return PhoneNumberDesc |
||
| 355 | */ |
||
| 356 | 708 | public function getPremiumRate() |
|
| 360 | |||
| 361 | 762 | public function setPremiumRate(PhoneNumberDesc $value) |
|
| 366 | |||
| 367 | public function hasSharedCost() |
||
| 371 | |||
| 372 | /** |
||
| 373 | * @return PhoneNumberDesc |
||
| 374 | */ |
||
| 375 | 261 | public function getSharedCost() |
|
| 379 | |||
| 380 | 517 | public function setSharedCost(PhoneNumberDesc $value) |
|
| 385 | |||
| 386 | public function hasPersonalNumber() |
||
| 390 | |||
| 391 | /** |
||
| 392 | * @return PhoneNumberDesc |
||
| 393 | */ |
||
| 394 | 248 | public function getPersonalNumber() |
|
| 398 | |||
| 399 | 517 | public function setPersonalNumber(PhoneNumberDesc $value) |
|
| 404 | |||
| 405 | public function hasVoip() |
||
| 409 | |||
| 410 | /** |
||
| 411 | * @return PhoneNumberDesc |
||
| 412 | */ |
||
| 413 | 239 | public function getVoip() |
|
| 417 | |||
| 418 | 517 | public function setVoip(PhoneNumberDesc $value) |
|
| 423 | |||
| 424 | public function hasPager() |
||
| 428 | |||
| 429 | /** |
||
| 430 | * @return PhoneNumberDesc |
||
| 431 | */ |
||
| 432 | 285 | public function getPager() |
|
| 436 | |||
| 437 | 517 | public function setPager(PhoneNumberDesc $value) |
|
| 442 | |||
| 443 | public function hasUan() |
||
| 447 | |||
| 448 | /** |
||
| 449 | * @return PhoneNumberDesc |
||
| 450 | */ |
||
| 451 | 255 | public function getUan() |
|
| 455 | |||
| 456 | 517 | public function setUan(PhoneNumberDesc $value) |
|
| 461 | |||
| 462 | 5 | public function hasEmergency() |
|
| 466 | |||
| 467 | /** |
||
| 468 | * @return PhoneNumberDesc |
||
| 469 | */ |
||
| 470 | 4 | public function getEmergency() |
|
| 474 | |||
| 475 | 250 | public function setEmergency(PhoneNumberDesc $value) |
|
| 480 | |||
| 481 | public function hasVoicemail() |
||
| 485 | |||
| 486 | /** |
||
| 487 | * @return PhoneNumberDesc |
||
| 488 | */ |
||
| 489 | 291 | public function getVoicemail() |
|
| 493 | |||
| 494 | 517 | public function setVoicemail(PhoneNumberDesc $value) |
|
| 499 | |||
| 500 | public function hasShortCode() |
||
| 504 | |||
| 505 | 6 | public function getShortCode() |
|
| 509 | |||
| 510 | 250 | public function setShortCode(PhoneNumberDesc $value) |
|
| 515 | |||
| 516 | public function hasStandardRate() |
||
| 520 | |||
| 521 | 507 | public function getStandardRate() |
|
| 525 | |||
| 526 | 250 | public function setStandardRate(PhoneNumberDesc $value) |
|
| 531 | |||
| 532 | public function hasCarrierSpecific() |
||
| 536 | |||
| 537 | 210 | public function getCarrierSpecific() |
|
| 541 | |||
| 542 | 250 | public function setCarrierSpecific(PhoneNumberDesc $value) |
|
| 547 | |||
| 548 | public function hasNoInternationalDialling() |
||
| 552 | |||
| 553 | 215 | public function getNoInternationalDialling() |
|
| 557 | |||
| 558 | 517 | public function setNoInternationalDialling(PhoneNumberDesc $value) |
|
| 563 | |||
| 564 | /** |
||
| 565 | * @return string |
||
| 566 | */ |
||
| 567 | 12 | public function getId() |
|
| 571 | |||
| 572 | /** |
||
| 573 | * @param string $value |
||
| 574 | * @return PhoneMetadata |
||
| 575 | */ |
||
| 576 | 766 | public function setId($value) |
|
| 581 | |||
| 582 | /** |
||
| 583 | * @return int |
||
| 584 | */ |
||
| 585 | 14 | public function getCountryCode() |
|
| 589 | |||
| 590 | /** |
||
| 591 | * @param int $value |
||
| 592 | * @return PhoneMetadata |
||
| 593 | */ |
||
| 594 | 766 | public function setCountryCode($value) |
|
| 599 | |||
| 600 | 2441 | public function getInternationalPrefix() |
|
| 604 | |||
| 605 | 766 | public function setInternationalPrefix($value) |
|
| 610 | |||
| 611 | 1 | public function hasPreferredInternationalPrefix() |
|
| 615 | |||
| 616 | 3 | public function getPreferredInternationalPrefix() |
|
| 620 | |||
| 621 | 58 | public function setPreferredInternationalPrefix($value) |
|
| 626 | |||
| 627 | 1 | public function hasNationalPrefix() |
|
| 631 | |||
| 632 | 4 | public function getNationalPrefix() |
|
| 636 | |||
| 637 | 3 | public function setNationalPrefix($value) |
|
| 642 | |||
| 643 | public function hasPreferredExtnPrefix() |
||
| 647 | |||
| 648 | 2 | public function getPreferredExtnPrefix() |
|
| 652 | |||
| 653 | 78 | public function setPreferredExtnPrefix($value) |
|
| 658 | |||
| 659 | 3 | public function hasNationalPrefixForParsing() |
|
| 663 | |||
| 664 | 2170 | public function getNationalPrefixForParsing() |
|
| 668 | |||
| 669 | 319 | public function setNationalPrefixForParsing($value) |
|
| 674 | |||
| 675 | public function hasNationalPrefixTransformRule() |
||
| 679 | |||
| 680 | 50 | public function getNationalPrefixTransformRule() |
|
| 684 | |||
| 685 | 29 | public function setNationalPrefixTransformRule($value) |
|
| 690 | |||
| 691 | 59 | public function isSameMobileAndFixedLinePattern() |
|
| 695 | |||
| 696 | 2 | public function setSameMobileAndFixedLinePattern($value) |
|
| 701 | |||
| 702 | /** |
||
| 703 | * @return NumberFormat[] |
||
| 704 | */ |
||
| 705 | 22 | public function numberFormats() |
|
| 709 | |||
| 710 | 23 | public function intlNumberFormats() |
|
| 714 | |||
| 715 | /** |
||
| 716 | * @return bool |
||
| 717 | */ |
||
| 718 | 30 | public function hasLeadingDigits() |
|
| 722 | |||
| 723 | 8 | public function getLeadingDigits() |
|
| 727 | |||
| 728 | 30 | public function setLeadingDigits($value) |
|
| 733 | |||
| 734 | 2 | public function isLeadingZeroPossible() |
|
| 738 | |||
| 739 | 760 | public function setLeadingZeroPossible($value) |
|
| 744 | |||
| 745 | 4 | public function isMobileNumberPortableRegion() |
|
| 749 | |||
| 750 | 760 | public function setMobileNumberPortableRegion($value) |
|
| 755 | |||
| 756 | /** |
||
| 757 | * @param array $input |
||
| 758 | * @return PhoneMetadata |
||
| 759 | */ |
||
| 760 | 759 | public function fromArray(array $input) |
|
| 892 | |||
| 893 | 130 | public function addNumberFormat(NumberFormat $value) |
|
| 898 | |||
| 899 | 80 | public function addIntlNumberFormat(NumberFormat $value) |
|
| 904 | } |
||
| 905 |