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 | /** |
||
| 9 | * @var string |
||
| 10 | */ |
||
| 11 | protected $id = null; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @return boolean |
||
| 15 | */ |
||
| 16 | public function hasId() |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @return string |
||
| 23 | */ |
||
| 24 | 4 | public function getId() |
|
| 28 | |||
| 29 | /** |
||
| 30 | * @param string $value |
||
| 31 | * @return PhoneMetadata |
||
| 32 | */ |
||
| 33 | 866 | public function setId($value) |
|
| 38 | |||
| 39 | /** |
||
| 40 | * @var int |
||
| 41 | */ |
||
| 42 | protected $countryCode = null; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @return boolean |
||
| 46 | */ |
||
| 47 | public function hasCountryCode() |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @return int |
||
| 54 | */ |
||
| 55 | 2721 | public function getCountryCode() |
|
| 59 | |||
| 60 | /** |
||
| 61 | * @param int $value |
||
| 62 | * @return PhoneMetadata |
||
| 63 | */ |
||
| 64 | 866 | public function setCountryCode($value) |
|
| 69 | |||
| 70 | protected $leadingDigits = null; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @return bool |
||
| 74 | */ |
||
| 75 | 518 | public function hasLeadingDigits() |
|
| 79 | |||
| 80 | 173 | public function getLeadingDigits() |
|
| 84 | |||
| 85 | 53 | public function setLeadingDigits($value) |
|
| 90 | |||
| 91 | protected $internationalPrefix = null; |
||
| 92 | |||
| 93 | public function hasInternationalPrefix() |
||
| 97 | |||
| 98 | 2717 | public function getInternationalPrefix() |
|
| 102 | |||
| 103 | 866 | public function setInternationalPrefix($value) |
|
| 108 | |||
| 109 | protected $preferredInternationalPrefix = null; |
||
| 110 | |||
| 111 | 3 | public function hasPreferredInternationalPrefix() |
|
| 115 | |||
| 116 | 4 | public function getPreferredInternationalPrefix() |
|
| 120 | |||
| 121 | 60 | public function setPreferredInternationalPrefix($value) |
|
| 126 | |||
| 127 | protected $nationalPrefixForParsing = null; |
||
| 128 | |||
| 129 | public function hasNationalPrefixForParsing() |
||
| 133 | |||
| 134 | 2728 | public function getNationalPrefixForParsing() |
|
| 138 | |||
| 139 | 401 | public function setNationalPrefixForParsing($value) |
|
| 144 | |||
| 145 | protected $nationalPrefixTransformRule = null; |
||
| 146 | |||
| 147 | public function hasNationalPrefixTransformRule() |
||
| 151 | |||
| 152 | 71 | public function getNationalPrefixTransformRule() |
|
| 156 | |||
| 157 | 28 | public function setNationalPrefixTransformRule($value) |
|
| 162 | |||
| 163 | protected $nationalPrefix = null; |
||
| 164 | |||
| 165 | 2 | public function hasNationalPrefix() |
|
| 169 | |||
| 170 | 6 | public function getNationalPrefix() |
|
| 174 | |||
| 175 | 390 | public function setNationalPrefix($value) |
|
| 180 | |||
| 181 | protected $preferredExtnPrefix = null; |
||
| 182 | |||
| 183 | 2 | public function hasPreferredExtnPrefix() |
|
| 187 | |||
| 188 | 1 | public function getPreferredExtnPrefix() |
|
| 192 | |||
| 193 | 84 | public function setPreferredExtnPrefix($value) |
|
| 198 | |||
| 199 | protected $mainCountryForCode = false; |
||
| 200 | |||
| 201 | public function hasMainCountryForCode() |
||
| 205 | |||
| 206 | public function isMainCountryForCode() |
||
| 210 | |||
| 211 | public function getMainCountryForCode() |
||
| 215 | |||
| 216 | 866 | public function setMainCountryForCode($value) |
|
| 221 | |||
| 222 | protected $leadingZeroPossible = false; |
||
| 223 | |||
| 224 | public function hasLeadingZeroPossible() |
||
| 228 | |||
| 229 | 2 | public function isLeadingZeroPossible() |
|
| 233 | |||
| 234 | 866 | public function setLeadingZeroPossible($value) |
|
| 239 | |||
| 240 | protected $mobileNumberPortableRegion = false; |
||
| 241 | |||
| 242 | public function hasMobileNumberPortableRegion() |
||
| 243 | { |
||
| 244 | return isset($this->mobileNumberPortableRegion); |
||
| 245 | } |
||
| 246 | |||
| 247 | 3 | public function isMobileNumberPortableRegion() |
|
| 248 | { |
||
| 249 | 3 | return $this->mobileNumberPortableRegion; |
|
| 250 | } |
||
| 251 | |||
| 252 | 866 | public function setMobileNumberPortableRegion($value) |
|
| 253 | { |
||
| 254 | 866 | $this->mobileNumberPortableRegion = $value; |
|
| 255 | 866 | return $this; |
|
| 256 | } |
||
| 257 | |||
| 258 | protected $generalDesc = null; |
||
| 259 | |||
| 260 | public function hasGeneralDesc() |
||
| 264 | |||
| 265 | /** |
||
| 266 | * @return PhoneNumberDesc |
||
| 267 | */ |
||
| 268 | 2769 | public function getGeneralDesc() |
|
| 272 | |||
| 273 | 867 | public function setGeneralDesc(PhoneNumberDesc $value) |
|
| 278 | |||
| 279 | /** |
||
| 280 | * @var PhoneNumberDesc |
||
| 281 | */ |
||
| 282 | protected $mobile = null; |
||
| 283 | |||
| 284 | public function hasMobile() |
||
| 288 | |||
| 289 | /** |
||
| 290 | * @return PhoneNumberDesc |
||
| 291 | */ |
||
| 292 | 1129 | public function getMobile() |
|
| 296 | |||
| 297 | 866 | public function setMobile(PhoneNumberDesc $value) |
|
| 302 | |||
| 303 | protected $premiumRate = null; |
||
| 304 | |||
| 305 | public function hasPremiumRate() |
||
| 309 | |||
| 310 | /** |
||
| 311 | * @return PhoneNumberDesc |
||
| 312 | */ |
||
| 313 | 2374 | public function getPremiumRate() |
|
| 317 | |||
| 318 | 866 | public function setPremiumRate(PhoneNumberDesc $value) |
|
| 323 | |||
| 324 | protected $fixedLine = null; |
||
| 325 | |||
| 326 | public function hasFixedLine() |
||
| 330 | |||
| 331 | /** |
||
| 332 | * @return PhoneNumberDesc |
||
| 333 | */ |
||
| 334 | 1515 | public function getFixedLine() |
|
| 338 | |||
| 339 | 866 | public function setFixedLine(PhoneNumberDesc $value) |
|
| 344 | |||
| 345 | protected $sameMobileAndFixedLinePattern = false; |
||
| 346 | |||
| 347 | public function hasSameMobileAndFixedLinePattern() |
||
| 351 | |||
| 352 | 1125 | public function isSameMobileAndFixedLinePattern() |
|
| 356 | |||
| 357 | public function setSameMobileAndFixedLinePattern($value) |
||
| 362 | |||
| 363 | protected $numberFormat = array(); |
||
| 364 | |||
| 365 | /** |
||
| 366 | * @return NumberFormat[] |
||
| 367 | */ |
||
| 368 | 41 | public function numberFormats() |
|
| 372 | |||
| 373 | 2 | public function numberFormatSize() |
|
| 377 | |||
| 378 | /** |
||
| 379 | * @param int $index |
||
| 380 | * @return NumberFormat |
||
| 381 | */ |
||
| 382 | 4 | public function getNumberFormat($index) |
|
| 386 | |||
| 387 | 556 | public function addNumberFormat(NumberFormat $value) |
|
| 392 | |||
| 393 | protected $tollFree = null; |
||
| 394 | |||
| 395 | public function hasTollFree() |
||
| 399 | |||
| 400 | /** |
||
| 401 | * @return PhoneNumberDesc |
||
| 402 | */ |
||
| 403 | 2149 | public function getTollFree() |
|
| 407 | |||
| 408 | 866 | public function setTollFree(PhoneNumberDesc $value) |
|
| 413 | |||
| 414 | protected $sharedCost = null; |
||
| 415 | |||
| 416 | public function hasSharedCost() |
||
| 420 | |||
| 421 | /** |
||
| 422 | * @return PhoneNumberDesc |
||
| 423 | */ |
||
| 424 | 1603 | public function getSharedCost() |
|
| 428 | |||
| 429 | 866 | public function setSharedCost(PhoneNumberDesc $value) |
|
| 434 | |||
| 435 | protected $personalNumber; |
||
| 436 | |||
| 437 | public function hasPersonalNumber() |
||
| 441 | |||
| 442 | /** |
||
| 443 | * @return PhoneNumberDesc |
||
| 444 | */ |
||
| 445 | 1461 | public function getPersonalNumber() |
|
| 449 | |||
| 450 | 866 | public function setPersonalNumber(PhoneNumberDesc $value) |
|
| 455 | |||
| 456 | protected $voip; |
||
| 457 | |||
| 458 | public function hasVoip() |
||
| 462 | |||
| 463 | /** |
||
| 464 | * @return PhoneNumberDesc |
||
| 465 | */ |
||
| 466 | 1524 | public function getVoip() |
|
| 470 | |||
| 471 | 866 | public function setVoip(PhoneNumberDesc $value) |
|
| 476 | |||
| 477 | protected $pager; |
||
| 478 | |||
| 479 | public function hasPager() |
||
| 483 | |||
| 484 | /** |
||
| 485 | * @return PhoneNumberDesc |
||
| 486 | */ |
||
| 487 | 1436 | public function getPager() |
|
| 491 | |||
| 492 | 866 | public function setPager(PhoneNumberDesc $value) |
|
| 497 | |||
| 498 | protected $uan; |
||
| 499 | |||
| 500 | public function hasUan() |
||
| 504 | |||
| 505 | /** |
||
| 506 | * @return PhoneNumberDesc |
||
| 507 | */ |
||
| 508 | 1384 | public function getUan() |
|
| 512 | |||
| 513 | 866 | public function setUan(PhoneNumberDesc $value) |
|
| 518 | |||
| 519 | protected $emergency; |
||
| 520 | |||
| 521 | 274 | public function hasEmergency() |
|
| 522 | { |
||
| 523 | 274 | return isset($this->emergency); |
|
| 524 | } |
||
| 525 | |||
| 526 | /** |
||
| 527 | * @return PhoneNumberDesc |
||
| 528 | */ |
||
| 529 | 275 | public function getEmergency() |
|
| 530 | { |
||
| 531 | 275 | return $this->emergency; |
|
| 532 | } |
||
| 533 | |||
| 534 | 866 | public function setEmergency(PhoneNumberDesc $value) |
|
| 535 | { |
||
| 536 | 866 | $this->emergency = $value; |
|
| 537 | 866 | return $this; |
|
| 538 | } |
||
| 539 | |||
| 540 | protected $voicemail; |
||
| 541 | |||
| 542 | public function hasVoicemail() |
||
| 543 | { |
||
| 544 | return isset($this->voicemail); |
||
| 545 | } |
||
| 546 | |||
| 547 | /** |
||
| 548 | * @return PhoneNumberDesc |
||
| 549 | */ |
||
| 550 | 1370 | public function getVoicemail() |
|
| 551 | { |
||
| 552 | 1370 | return $this->voicemail; |
|
| 553 | } |
||
| 554 | |||
| 555 | 866 | public function setVoicemail(PhoneNumberDesc $value) |
|
| 560 | |||
| 561 | /** |
||
| 562 | * @var PhoneNumberDesc |
||
| 563 | */ |
||
| 564 | protected $short_code; |
||
| 565 | |||
| 566 | public function hasShortCode() |
||
| 567 | { |
||
| 568 | return isset($this->short_code); |
||
| 569 | } |
||
| 570 | |||
| 571 | 247 | public function getShortCode() |
|
| 572 | { |
||
| 573 | 247 | return $this->short_code; |
|
| 574 | } |
||
| 575 | |||
| 576 | 866 | public function setShortCode(PhoneNumberDesc $value) |
|
| 577 | { |
||
| 578 | 866 | $this->short_code = $value; |
|
| 579 | 866 | return $this; |
|
| 580 | } |
||
| 581 | |||
| 582 | /** |
||
| 583 | * @var PhoneNumberDesc |
||
| 584 | */ |
||
| 585 | protected $standard_rate; |
||
| 586 | |||
| 587 | public function hasStandardRate() |
||
| 588 | { |
||
| 589 | return isset($this->standard_rate); |
||
| 590 | } |
||
| 591 | |||
| 592 | 526 | public function getStandardRate() |
|
| 593 | { |
||
| 594 | 526 | return $this->standard_rate; |
|
| 595 | } |
||
| 596 | |||
| 597 | 866 | public function setStandardRate(PhoneNumberDesc $value) |
|
| 598 | { |
||
| 599 | 866 | $this->standard_rate = $value; |
|
| 600 | 866 | return $this; |
|
| 601 | } |
||
| 602 | |||
| 603 | /** |
||
| 604 | * @var PhoneNumberDesc |
||
| 605 | */ |
||
| 606 | protected $carrierSpecific; |
||
| 607 | |||
| 608 | public function hasCarrierSpecific() |
||
| 609 | { |
||
| 610 | return isset($this->carrierSpecific); |
||
| 611 | } |
||
| 612 | |||
| 613 | 238 | public function getCarrierSpecific() |
|
| 614 | { |
||
| 615 | 238 | return $this->carrierSpecific; |
|
| 616 | } |
||
| 617 | |||
| 618 | 866 | public function setCarrierSpecific(PhoneNumberDesc $value) |
|
| 619 | { |
||
| 620 | 866 | $this->carrierSpecific = $value; |
|
| 621 | 866 | return $this; |
|
| 622 | } |
||
| 623 | |||
| 624 | /** |
||
| 625 | * @var PhoneNumberDesc |
||
| 626 | */ |
||
| 627 | protected $noInternationalDialling = null; |
||
| 628 | |||
| 629 | public function hasNoInternationalDialling() |
||
| 633 | |||
| 634 | 246 | public function getNoInternationalDialling() |
|
| 638 | |||
| 639 | 866 | public function setNoInternationalDialling(PhoneNumberDesc $value) |
|
| 644 | |||
| 645 | /** |
||
| 646 | * |
||
| 647 | * @var NumberFormat[] |
||
| 648 | */ |
||
| 649 | protected $intlNumberFormat = array(); |
||
| 650 | |||
| 651 | 42 | public function intlNumberFormats() |
|
| 655 | |||
| 656 | public function intlNumberFormatSize() |
||
| 660 | |||
| 661 | 1 | public function getIntlNumberFormat($index) |
|
| 665 | |||
| 666 | 122 | public function addIntlNumberFormat(NumberFormat $value) |
|
| 671 | |||
| 672 | public function clearIntlNumberFormat() |
||
| 677 | |||
| 678 | public function toArray() |
||
| 679 | { |
||
| 680 | $output = array(); |
||
| 681 | |||
| 682 | if ($this->hasGeneralDesc()) { |
||
| 683 | $output['generalDesc'] = $this->getGeneralDesc()->toArray(); |
||
| 684 | } |
||
| 685 | |||
| 686 | if ($this->hasFixedLine()) { |
||
| 687 | $output['fixedLine'] = $this->getFixedLine()->toArray(); |
||
| 688 | } |
||
| 689 | |||
| 690 | if ($this->hasMobile()) { |
||
| 691 | $output['mobile'] = $this->getMobile()->toArray(); |
||
| 692 | } |
||
| 693 | |||
| 694 | if ($this->hasTollFree()) { |
||
| 798 | |||
| 799 | /** |
||
| 800 | * @param array $input |
||
| 801 | * @return PhoneMetadata |
||
| 802 | */ |
||
| 803 | 866 | public function fromArray(array $input) |
|
| 935 | } |
||
| 936 |