Complex classes like Country 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 Country, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 9 | class Country  | 
            ||
| 10 | { | 
            ||
| 11 | /**  | 
            ||
| 12 | * The attributes array.  | 
            ||
| 13 | *  | 
            ||
| 14 | * @var array  | 
            ||
| 15 | */  | 
            ||
| 16 | protected $attributes;  | 
            ||
| 17 | |||
| 18 | /**  | 
            ||
| 19 | * Create a new Country instance.  | 
            ||
| 20 | *  | 
            ||
| 21 | * @param array $attributes  | 
            ||
| 22 | *  | 
            ||
| 23 | * @throws \Exception  | 
            ||
| 24 | */  | 
            ||
| 25 | public function __construct($attributes)  | 
            ||
| 37 | |||
| 38 | /**  | 
            ||
| 39 | * Set the attributes.  | 
            ||
| 40 | *  | 
            ||
| 41 | * @param array $attributes  | 
            ||
| 42 | *  | 
            ||
| 43 | * @return $this  | 
            ||
| 44 | */  | 
            ||
| 45 | public function setAttributes($attributes)  | 
            ||
| 51 | |||
| 52 | /**  | 
            ||
| 53 | * Get the attributes.  | 
            ||
| 54 | *  | 
            ||
| 55 | * @return array|null  | 
            ||
| 56 | */  | 
            ||
| 57 | public function getAttributes()  | 
            ||
| 61 | |||
| 62 | /**  | 
            ||
| 63 | * Set single attribute.  | 
            ||
| 64 | *  | 
            ||
| 65 | * @param string $key  | 
            ||
| 66 | * @param mixed $value  | 
            ||
| 67 | *  | 
            ||
| 68 | * @return $this  | 
            ||
| 69 | */  | 
            ||
| 70 | public function set($key, $value)  | 
            ||
| 76 | |||
| 77 | /**  | 
            ||
| 78 | * Get an item from attributes array using "dot" notation.  | 
            ||
| 79 | *  | 
            ||
| 80 | * @param string $key  | 
            ||
| 81 | * @param mixed $default  | 
            ||
| 82 | *  | 
            ||
| 83 | * @return mixed  | 
            ||
| 84 | */  | 
            ||
| 85 | public function get($key, $default = null)  | 
            ||
| 107 | |||
| 108 | /**  | 
            ||
| 109 | * Get the common name.  | 
            ||
| 110 | *  | 
            ||
| 111 | * @return string|null  | 
            ||
| 112 | */  | 
            ||
| 113 | public function getName()  | 
            ||
| 117 | |||
| 118 | /**  | 
            ||
| 119 | * Get the official name.  | 
            ||
| 120 | *  | 
            ||
| 121 | * @return string|null  | 
            ||
| 122 | */  | 
            ||
| 123 | public function getOfficialName()  | 
            ||
| 127 | |||
| 128 | /**  | 
            ||
| 129 | * Get the given native name or fallback to first native name.  | 
            ||
| 130 | *  | 
            ||
| 131 | * @param string|null $languageCode  | 
            ||
| 132 | *  | 
            ||
| 133 | * @return string|null  | 
            ||
| 134 | */  | 
            ||
| 135 | public function getNativeName($languageCode = null)  | 
            ||
| 142 | |||
| 143 | /**  | 
            ||
| 144 | * Get the given native official name or fallback to first native official name.  | 
            ||
| 145 | *  | 
            ||
| 146 | * @param string|null $languageCode  | 
            ||
| 147 | *  | 
            ||
| 148 | * @return string|null  | 
            ||
| 149 | */  | 
            ||
| 150 | public function getNativeOfficialName($languageCode = null)  | 
            ||
| 157 | |||
| 158 | /**  | 
            ||
| 159 | * Get the native names.  | 
            ||
| 160 | *  | 
            ||
| 161 | * @return array|null  | 
            ||
| 162 | */  | 
            ||
| 163 | public function getNativeNames()  | 
            ||
| 167 | |||
| 168 | /**  | 
            ||
| 169 | * Get the demonym.  | 
            ||
| 170 | *  | 
            ||
| 171 | * @return string|null  | 
            ||
| 172 | */  | 
            ||
| 173 | public function getDemonym()  | 
            ||
| 177 | |||
| 178 | /**  | 
            ||
| 179 | * Get the capital.  | 
            ||
| 180 | *  | 
            ||
| 181 | * @return string|null  | 
            ||
| 182 | */  | 
            ||
| 183 | public function getCapital()  | 
            ||
| 187 | |||
| 188 | /**  | 
            ||
| 189 | * Get the ISO 3166-1 alpha2.  | 
            ||
| 190 | *  | 
            ||
| 191 | * @return string|null  | 
            ||
| 192 | */  | 
            ||
| 193 | public function getIsoAlpha2()  | 
            ||
| 197 | |||
| 198 | /**  | 
            ||
| 199 | * Get the ISO 3166-1 alpha3.  | 
            ||
| 200 | *  | 
            ||
| 201 | * @return string|null  | 
            ||
| 202 | */  | 
            ||
| 203 | public function getIsoAlpha3()  | 
            ||
| 207 | |||
| 208 | /**  | 
            ||
| 209 | * Get the ISO 3166-1 numeric.  | 
            ||
| 210 | *  | 
            ||
| 211 | * @return string|null  | 
            ||
| 212 | */  | 
            ||
| 213 | public function getIsoNumeric()  | 
            ||
| 217 | |||
| 218 | /**  | 
            ||
| 219 | * Get the given currency or fallback to first currency.  | 
            ||
| 220 | *  | 
            ||
| 221 | * @param string|null $currency  | 
            ||
| 222 | *  | 
            ||
| 223 | * @return string|null  | 
            ||
| 224 | */  | 
            ||
| 225 | public function getCurrency($currency = null)  | 
            ||
| 226 |     { | 
            ||
| 227 | $currency = $currency ? mb_strtoupper($currency) : null;  | 
            ||
| 228 | |||
| 229 |         return $this->get("currency.{$currency}") ?: (current($this->get('currency', [])) ?: null); | 
            ||
| 230 | }  | 
            ||
| 231 | |||
| 232 | /**  | 
            ||
| 233 | * Get the currencies.  | 
            ||
| 234 | *  | 
            ||
| 235 | * @return array|null  | 
            ||
| 236 | */  | 
            ||
| 237 | public function getCurrencies()  | 
            ||
| 241 | |||
| 242 | /**  | 
            ||
| 243 | * Get the default currency or fallback to first currency.  | 
            ||
| 244 | *  | 
            ||
| 245 | * @return string|null  | 
            ||
| 246 | */  | 
            ||
| 247 | public function getDefaultCurrency()  | 
            ||
| 251 | |||
| 252 | /**  | 
            ||
| 253 | * Get the TLD.  | 
            ||
| 254 | *  | 
            ||
| 255 | * @return string|null  | 
            ||
| 256 | */  | 
            ||
| 257 | public function getTld()  | 
            ||
| 261 | |||
| 262 | /**  | 
            ||
| 263 | * Get the TLDs.  | 
            ||
| 264 | *  | 
            ||
| 265 | * @return array|null  | 
            ||
| 266 | */  | 
            ||
| 267 | public function getTlds()  | 
            ||
| 271 | |||
| 272 | /**  | 
            ||
| 273 | * Get the alternative spellings.  | 
            ||
| 274 | *  | 
            ||
| 275 | * @return array|null  | 
            ||
| 276 | */  | 
            ||
| 277 | public function getAltSpellings()  | 
            ||
| 281 | |||
| 282 | /**  | 
            ||
| 283 | * Get the given language or fallback to first language.  | 
            ||
| 284 | *  | 
            ||
| 285 | * @param string|null $languageCode  | 
            ||
| 286 | *  | 
            ||
| 287 | * @return string|null  | 
            ||
| 288 | */  | 
            ||
| 289 | public function getLanguage($languageCode = null)  | 
            ||
| 295 | |||
| 296 | /**  | 
            ||
| 297 | * Get the languages.  | 
            ||
| 298 | *  | 
            ||
| 299 | * @return array|null  | 
            ||
| 300 | */  | 
            ||
| 301 | public function getLanguages()  | 
            ||
| 305 | |||
| 306 | /**  | 
            ||
| 307 | * Get the translations.  | 
            ||
| 308 | *  | 
            ||
| 309 | * @return array  | 
            ||
| 310 | */  | 
            ||
| 311 | public function getTranslations()  | 
            ||
| 336 | |||
| 337 | /**  | 
            ||
| 338 | * Get the translation.  | 
            ||
| 339 | *  | 
            ||
| 340 | * @param string|null $languageCode  | 
            ||
| 341 | *  | 
            ||
| 342 | * @return array  | 
            ||
| 343 | */  | 
            ||
| 344 | public function getTranslation($languageCode = null)  | 
            ||
| 348 | |||
| 349 | /**  | 
            ||
| 350 | * Get the geodata.  | 
            ||
| 351 | *  | 
            ||
| 352 | * @return array|null  | 
            ||
| 353 | */  | 
            ||
| 354 | public function getGeodata()  | 
            ||
| 358 | |||
| 359 | /**  | 
            ||
| 360 | * Get the continent.  | 
            ||
| 361 | *  | 
            ||
| 362 | * @return string|null  | 
            ||
| 363 | */  | 
            ||
| 364 | public function getContinent()  | 
            ||
| 368 | |||
| 369 | /**  | 
            ||
| 370 | * Determine whether the country uses postal code.  | 
            ||
| 371 | *  | 
            ||
| 372 | * @return bool|null  | 
            ||
| 373 | */  | 
            ||
| 374 | public function usesPostalCode()  | 
            ||
| 378 | |||
| 379 | /**  | 
            ||
| 380 | * Get the latitude.  | 
            ||
| 381 | *  | 
            ||
| 382 | * @return string|null  | 
            ||
| 383 | */  | 
            ||
| 384 | public function getLatitude()  | 
            ||
| 388 | |||
| 389 | /**  | 
            ||
| 390 | * Get the longitude.  | 
            ||
| 391 | *  | 
            ||
| 392 | * @return string|null  | 
            ||
| 393 | */  | 
            ||
| 394 | public function getLongitude()  | 
            ||
| 398 | |||
| 399 | /**  | 
            ||
| 400 | * Get the described latitude.  | 
            ||
| 401 | *  | 
            ||
| 402 | * @return string|null  | 
            ||
| 403 | */  | 
            ||
| 404 | public function getLatitudeDesc()  | 
            ||
| 408 | |||
| 409 | /**  | 
            ||
| 410 | * Get the described longitude.  | 
            ||
| 411 | *  | 
            ||
| 412 | * @return string|null  | 
            ||
| 413 | */  | 
            ||
| 414 | public function getLongitudeDesc()  | 
            ||
| 418 | |||
| 419 | /**  | 
            ||
| 420 | * Get the maximum latitude.  | 
            ||
| 421 | *  | 
            ||
| 422 | * @return string|null  | 
            ||
| 423 | */  | 
            ||
| 424 | public function getMaxLatitude()  | 
            ||
| 428 | |||
| 429 | /**  | 
            ||
| 430 | * Get the maximum longitude.  | 
            ||
| 431 | *  | 
            ||
| 432 | * @return string|null  | 
            ||
| 433 | */  | 
            ||
| 434 | public function getMaxLongitude()  | 
            ||
| 438 | |||
| 439 | /**  | 
            ||
| 440 | * Get the minimum latitude.  | 
            ||
| 441 | *  | 
            ||
| 442 | * @return string|null  | 
            ||
| 443 | */  | 
            ||
| 444 | public function getMinLatitude()  | 
            ||
| 448 | |||
| 449 | /**  | 
            ||
| 450 | * Get the minimum longitude.  | 
            ||
| 451 | *  | 
            ||
| 452 | * @return string|null  | 
            ||
| 453 | */  | 
            ||
| 454 | public function getMinLongitude()  | 
            ||
| 458 | |||
| 459 | /**  | 
            ||
| 460 | * Get the area.  | 
            ||
| 461 | *  | 
            ||
| 462 | * @return int|null  | 
            ||
| 463 | */  | 
            ||
| 464 | public function getArea()  | 
            ||
| 468 | |||
| 469 | /**  | 
            ||
| 470 | * Get the region.  | 
            ||
| 471 | *  | 
            ||
| 472 | * @return string|null  | 
            ||
| 473 | */  | 
            ||
| 474 | public function getRegion()  | 
            ||
| 478 | |||
| 479 | /**  | 
            ||
| 480 | * Get the subregion.  | 
            ||
| 481 | *  | 
            ||
| 482 | * @return string|null  | 
            ||
| 483 | */  | 
            ||
| 484 | public function getSubregion()  | 
            ||
| 488 | |||
| 489 | /**  | 
            ||
| 490 | * Get the world region.  | 
            ||
| 491 | *  | 
            ||
| 492 | * @return string|null  | 
            ||
| 493 | */  | 
            ||
| 494 | public function getWorldRegion()  | 
            ||
| 498 | |||
| 499 | /**  | 
            ||
| 500 | * Get the region code.  | 
            ||
| 501 | *  | 
            ||
| 502 | * @return string|null  | 
            ||
| 503 | */  | 
            ||
| 504 | public function getRegionCode()  | 
            ||
| 508 | |||
| 509 | /**  | 
            ||
| 510 | * Get the subregion code.  | 
            ||
| 511 | *  | 
            ||
| 512 | * @return string|null  | 
            ||
| 513 | */  | 
            ||
| 514 | public function getSubregionCode()  | 
            ||
| 518 | |||
| 519 | /**  | 
            ||
| 520 | * Check the landlock status.  | 
            ||
| 521 | *  | 
            ||
| 522 | * @return bool|null  | 
            ||
| 523 | */  | 
            ||
| 524 | public function isLandlocked()  | 
            ||
| 528 | |||
| 529 | /**  | 
            ||
| 530 | * Get the borders.  | 
            ||
| 531 | *  | 
            ||
| 532 | * @return array|null  | 
            ||
| 533 | */  | 
            ||
| 534 | public function getBorders()  | 
            ||
| 538 | |||
| 539 | /**  | 
            ||
| 540 | * Determine whether the country is independent.  | 
            ||
| 541 | *  | 
            ||
| 542 | * @return string|null  | 
            ||
| 543 | */  | 
            ||
| 544 | public function isIndependent()  | 
            ||
| 548 | |||
| 549 | /**  | 
            ||
| 550 | * Get the given calling code or fallback to first calling code.  | 
            ||
| 551 | *  | 
            ||
| 552 | * @return string|null  | 
            ||
| 553 | */  | 
            ||
| 554 | public function getCallingCode()  | 
            ||
| 558 | |||
| 559 | /**  | 
            ||
| 560 | * Get the calling codes.  | 
            ||
| 561 | *  | 
            ||
| 562 | * @return array|null  | 
            ||
| 563 | */  | 
            ||
| 564 | public function getCallingCodes()  | 
            ||
| 568 | |||
| 569 | /**  | 
            ||
| 570 | * Get the national prefix.  | 
            ||
| 571 | *  | 
            ||
| 572 | * @return string|null  | 
            ||
| 573 | */  | 
            ||
| 574 | public function getNationalPrefix()  | 
            ||
| 578 | |||
| 579 | /**  | 
            ||
| 580 | * Get the national number length.  | 
            ||
| 581 | *  | 
            ||
| 582 | * @return int|null  | 
            ||
| 583 | */  | 
            ||
| 584 | public function getNationalNumberLength()  | 
            ||
| 588 | |||
| 589 | /**  | 
            ||
| 590 | * Get the national number lengths.  | 
            ||
| 591 | *  | 
            ||
| 592 | * @return array|null  | 
            ||
| 593 | */  | 
            ||
| 594 | public function getNationalNumberLengths()  | 
            ||
| 598 | |||
| 599 | /**  | 
            ||
| 600 | * Get the national destination code length.  | 
            ||
| 601 | *  | 
            ||
| 602 | * @return int|null  | 
            ||
| 603 | */  | 
            ||
| 604 | public function getNationalDestinationCodeLength()  | 
            ||
| 608 | |||
| 609 | /**  | 
            ||
| 610 | * Get the national destination code lengths.  | 
            ||
| 611 | *  | 
            ||
| 612 | * @return array|null  | 
            ||
| 613 | */  | 
            ||
| 614 | public function getnationaldestinationcodelengths()  | 
            ||
| 618 | |||
| 619 | /**  | 
            ||
| 620 | * Get the international prefix.  | 
            ||
| 621 | *  | 
            ||
| 622 | * @return string|null  | 
            ||
| 623 | */  | 
            ||
| 624 | public function getInternationalPrefix()  | 
            ||
| 628 | |||
| 629 | /**  | 
            ||
| 630 | * Get the extras.  | 
            ||
| 631 | *  | 
            ||
| 632 | * @return array|null  | 
            ||
| 633 | */  | 
            ||
| 634 | public function getExtra()  | 
            ||
| 638 | |||
| 639 | /**  | 
            ||
| 640 | * Get the geonameid.  | 
            ||
| 641 | *  | 
            ||
| 642 | * @return int|null  | 
            ||
| 643 | */  | 
            ||
| 644 | public function getGeonameid()  | 
            ||
| 648 | |||
| 649 | /**  | 
            ||
| 650 | * Get the edgar code.  | 
            ||
| 651 | *  | 
            ||
| 652 | * @return string|null  | 
            ||
| 653 | */  | 
            ||
| 654 | public function getEdgar()  | 
            ||
| 658 | |||
| 659 | /**  | 
            ||
| 660 | * Get the itu code.  | 
            ||
| 661 | *  | 
            ||
| 662 | * @return string|null  | 
            ||
| 663 | */  | 
            ||
| 664 | public function getItu()  | 
            ||
| 668 | |||
| 669 | /**  | 
            ||
| 670 | * Get the marc code.  | 
            ||
| 671 | *  | 
            ||
| 672 | * @return string|null  | 
            ||
| 673 | */  | 
            ||
| 674 | public function getMarc()  | 
            ||
| 678 | |||
| 679 | /**  | 
            ||
| 680 | * Get the wmo code.  | 
            ||
| 681 | *  | 
            ||
| 682 | * @return string|null  | 
            ||
| 683 | */  | 
            ||
| 684 | public function getWmo()  | 
            ||
| 688 | |||
| 689 | /**  | 
            ||
| 690 | * Get the ds code.  | 
            ||
| 691 | *  | 
            ||
| 692 | * @return string|null  | 
            ||
| 693 | */  | 
            ||
| 694 | public function getDs()  | 
            ||
| 698 | |||
| 699 | /**  | 
            ||
| 700 | * Get the fifa code.  | 
            ||
| 701 | *  | 
            ||
| 702 | * @return string|null  | 
            ||
| 703 | */  | 
            ||
| 704 | public function getFifa()  | 
            ||
| 708 | |||
| 709 | /**  | 
            ||
| 710 | * Get the fips code.  | 
            ||
| 711 | *  | 
            ||
| 712 | * @return string|null  | 
            ||
| 713 | */  | 
            ||
| 714 | public function getFips()  | 
            ||
| 718 | |||
| 719 | /**  | 
            ||
| 720 | * Get the gaul code.  | 
            ||
| 721 | *  | 
            ||
| 722 | * @return int|null  | 
            ||
| 723 | */  | 
            ||
| 724 | public function getGaul()  | 
            ||
| 728 | |||
| 729 | /**  | 
            ||
| 730 | * Get the ioc code.  | 
            ||
| 731 | *  | 
            ||
| 732 | * @return string|null  | 
            ||
| 733 | */  | 
            ||
| 734 | public function getIoc()  | 
            ||
| 738 | |||
| 739 | /**  | 
            ||
| 740 | * Get the cowc code.  | 
            ||
| 741 | *  | 
            ||
| 742 | * @return string|null  | 
            ||
| 743 | */  | 
            ||
| 744 | public function getCowc()  | 
            ||
| 748 | |||
| 749 | /**  | 
            ||
| 750 | * Get the cown code.  | 
            ||
| 751 | *  | 
            ||
| 752 | * @return int|null  | 
            ||
| 753 | */  | 
            ||
| 754 | public function getCown()  | 
            ||
| 758 | |||
| 759 | /**  | 
            ||
| 760 | * Get the fao code.  | 
            ||
| 761 | *  | 
            ||
| 762 | * @return int|null  | 
            ||
| 763 | */  | 
            ||
| 764 | public function getFao()  | 
            ||
| 768 | |||
| 769 | /**  | 
            ||
| 770 | * Get the imf code.  | 
            ||
| 771 | *  | 
            ||
| 772 | * @return int|null  | 
            ||
| 773 | */  | 
            ||
| 774 | public function getImf()  | 
            ||
| 778 | |||
| 779 | /**  | 
            ||
| 780 | * Get the ar5 code.  | 
            ||
| 781 | *  | 
            ||
| 782 | * @return string|null  | 
            ||
| 783 | */  | 
            ||
| 784 | public function getAr5()  | 
            ||
| 788 | |||
| 789 | /**  | 
            ||
| 790 | * Get the address format.  | 
            ||
| 791 | *  | 
            ||
| 792 | * @return string|null  | 
            ||
| 793 | */  | 
            ||
| 794 | public function getAddressFormat()  | 
            ||
| 798 | |||
| 799 | /**  | 
            ||
| 800 | * Determine whether the country is EU member.  | 
            ||
| 801 | *  | 
            ||
| 802 | * @return bool|null  | 
            ||
| 803 | */  | 
            ||
| 804 | public function isEuMember()  | 
            ||
| 808 | |||
| 809 | /**  | 
            ||
| 810 | * Get the VAT rates.  | 
            ||
| 811 | *  | 
            ||
| 812 | * @return array|null  | 
            ||
| 813 | */  | 
            ||
| 814 | public function getVatRates()  | 
            ||
| 818 | |||
| 819 | /**  | 
            ||
| 820 | * Get the emoji.  | 
            ||
| 821 | *  | 
            ||
| 822 | * @return array|null  | 
            ||
| 823 | */  | 
            ||
| 824 | public function getEmoji()  | 
            ||
| 828 | |||
| 829 | /**  | 
            ||
| 830 | * Get the geographic data structure.  | 
            ||
| 831 | *  | 
            ||
| 832 | * @return string|null  | 
            ||
| 833 | */  | 
            ||
| 834 | public function getGeoJson()  | 
            ||
| 842 | |||
| 843 | /**  | 
            ||
| 844 | * Get the flag.  | 
            ||
| 845 | *  | 
            ||
| 846 | * @return string|null  | 
            ||
| 847 | */  | 
            ||
| 848 | public function getFlag()  | 
            ||
| 856 | |||
| 857 | /**  | 
            ||
| 858 | * Get the divisions.  | 
            ||
| 859 | *  | 
            ||
| 860 | * @return array|null  | 
            ||
| 861 | */  | 
            ||
| 862 | public function getDivisions()  | 
            ||
| 870 | |||
| 871 | /**  | 
            ||
| 872 | * Get the divisions.  | 
            ||
| 873 | *  | 
            ||
| 874 | * @param string $division  | 
            ||
| 875 | *  | 
            ||
| 876 | * @return array|null  | 
            ||
| 877 | */  | 
            ||
| 878 | public function getDivision($division)  | 
            ||
| 883 | }  | 
            ||
| 884 | 
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.