Complex classes like User 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 User, and based on these observations, apply Extract Interface, too.
| 1 | <?php | ||
| 21 | class User extends \SerializableObject | ||
| 22 | { | ||
| 23 | /** | ||
| 24 | * An array to cache the title to string mappings so that they don't need to be pulled from the database | ||
| 25 | * everytime | ||
| 26 | */ | ||
| 27 | public static $titlenames = null; | ||
| 28 | |||
| 29 | /** | ||
| 30 | * Is this user in the Group or a child of that group? | ||
| 31 | * | ||
| 32 | * @param string $name The name of the group to check if the user is in | ||
| 33 | * | ||
| 34 | * @return true|false True if the user is in the group, false otherwise | ||
| 35 | */ | ||
| 36 | public function isInGroupNamed($name) | ||
| 40 | |||
| 41 | /** | ||
| 42 | * The name the user should be displayed as | ||
| 43 | * | ||
| 44 | * @return string The name the user should be displayed as | ||
| 45 | */ | ||
| 46 | public function getDisplayName() | ||
| 50 | |||
| 51 | /** | ||
| 52 | * The given (or first) name for the user | ||
| 53 | * | ||
| 54 | * @return string The user's first name | ||
| 55 | */ | ||
| 56 | public function getGivenName() | ||
| 60 | |||
| 61 | /** | ||
| 62 | * The email address for the user | ||
| 63 | * | ||
| 64 | * @return string The user's email address | ||
| 65 | */ | ||
| 66 | public function getEmail() | ||
| 70 | |||
| 71 | /** | ||
| 72 | * The user ID for the user | ||
| 73 | * | ||
| 74 | * @return string The user's ID or username | ||
| 75 | */ | ||
| 76 | public function getUid() | ||
| 80 | |||
| 81 | /** | ||
| 82 | * The photo for the user | ||
| 83 | * | ||
| 84 | * @return string The user's photo as a binary string | ||
| 85 | */ | ||
| 86 | public function getPhoto() | ||
| 90 | |||
| 91 | /** | ||
| 92 | * The phone number for the user | ||
| 93 | * | ||
| 94 | * @return false|string The user's phone number | ||
| 95 | */ | ||
| 96 | public function getPhoneNumber() | ||
| 100 | |||
| 101 | /** | ||
| 102 | * The organziation for the user | ||
| 103 | * | ||
| 104 | * @return false|string The user's organization | ||
| 105 | */ | ||
| 106 | public function getOrganization() | ||
| 110 | |||
| 111 | /** | ||
| 112 | * The list of titles for the user | ||
| 113 | * | ||
| 114 | * @return array The user's title(s) in short format | ||
| 115 | */ | ||
| 116 | public function getTitles() | ||
| 120 | |||
| 121 | /** | ||
| 122 | * The list of titles for the user | ||
| 123 | * | ||
| 124 | * @return array The user's title(s) in user friendly strings | ||
| 125 | * | ||
| 126 |      * @SuppressWarnings("StaticAccess") | ||
| 127 | */ | ||
| 128 | public function getTitleNames() | ||
| 158 | |||
| 159 | /** | ||
| 160 | * The state the user's mailing address is in | ||
| 161 | * | ||
| 162 | * @return string The user's state from their mailing address | ||
| 163 | */ | ||
| 164 | public function getState() | ||
| 168 | |||
| 169 | /** | ||
| 170 | * The city the user's mailing address is in | ||
| 171 | * | ||
| 172 | * @return string The user's city from their mailing address | ||
| 173 | */ | ||
| 174 | public function getCity() | ||
| 178 | |||
| 179 | /** | ||
| 180 | * The last name for the user | ||
| 181 | * | ||
| 182 | * @return string The user's last name | ||
| 183 | */ | ||
| 184 | public function getLastName() | ||
| 188 | |||
| 189 | /** | ||
| 190 | * The nick name for the user | ||
| 191 | * | ||
| 192 | * @return string The user's nick name | ||
| 193 | */ | ||
| 194 | public function getNickName() | ||
| 198 | |||
| 199 | /** | ||
| 200 | * The street address for the user | ||
| 201 | * | ||
| 202 | * @return string The user's street address | ||
| 203 | */ | ||
| 204 | public function getAddress() | ||
| 208 | |||
| 209 | /** | ||
| 210 | * The postal (zip) code for the user's mailing address | ||
| 211 | * | ||
| 212 | * @return string The user's postal code | ||
| 213 | */ | ||
| 214 | public function getPostalCode() | ||
| 218 | |||
| 219 | /** | ||
| 220 | * The country the user's mailing address is in | ||
| 221 | * | ||
| 222 | * @return string The user's country from their mailing address | ||
| 223 | */ | ||
| 224 | public function getCountry() | ||
| 228 | |||
| 229 | /** | ||
| 230 | * The organizational units the user is in | ||
| 231 | * | ||
| 232 | * This is the same as Areas in Flipside speak. | ||
| 233 | * | ||
| 234 | * @return array The user's orgnaiational units | ||
| 235 | */ | ||
| 236 | public function getOrganizationUnits() | ||
| 240 | |||
| 241 | /** | ||
| 242 | * The supplemental login types that the user can use to login | ||
| 243 | * | ||
| 244 | * @return array The user's login providers | ||
| 245 | */ | ||
| 246 | public function getLoginProviders() | ||
| 250 | |||
| 251 | /** | ||
| 252 | * The groups the user is a part of | ||
| 253 | * | ||
| 254 | * @return false|array The user's Auth\Group structures | ||
| 255 | */ | ||
| 256 | public function getGroups() | ||
| 257 |     { | ||
| 258 | return false; | ||
| 259 | } | ||
| 260 | |||
| 261 | /** | ||
| 262 | * Add a supplemental login type that the user can use to login | ||
| 263 | * | ||
| 264 | * @param string $provider The hostname for the provider | ||
| 265 | * | ||
| 266 | * @return true|false true if the addition worked, false otherwise | ||
| 267 | */ | ||
| 268 | public function addLoginProvider($provider) | ||
| 272 | |||
| 273 | /** | ||
| 274 | * Can the user login with this provider? | ||
| 275 | * | ||
| 276 | * @param string $provider The hostname for the provider | ||
| 277 | * | ||
| 278 | * @return true|false true if they can login with the provider, false otherwise | ||
| 279 | */ | ||
| 280 | public function canLoginWith($provider) | ||
| 291 | |||
| 292 | /** | ||
| 293 | * Set the user's password without verifying the current password | ||
| 294 | * | ||
| 295 | * @param string $password The new user password | ||
| 296 | * | ||
| 297 | * @return true|false true if the user's password was changed, false otherwise | ||
| 298 | */ | ||
| 299 | protected function setPass($password) | ||
| 303 | |||
| 304 | /** | ||
| 305 | * Has the user completely filled out their user profile? | ||
| 306 | * | ||
| 307 | * @return true|false true if the user's profile is complete, false otherwise | ||
| 308 | */ | ||
| 309 | public function isProfileComplete() | ||
| 319 | |||
| 320 | /** | ||
| 321 | * Validate that the user's password is the specified password | ||
| 322 | * | ||
| 323 | * @param string $password The user's current password | ||
| 324 | * | ||
| 325 | * @return true|false true if the user's password is correct, false otherwise | ||
| 326 | * | ||
| 327 |      * @SuppressWarnings("UnusedFormalParameter") | ||
| 328 | */ | ||
| 329 | public function validate_password($password) | ||
| 333 | |||
| 334 | /** | ||
| 335 | * Validate that the user's reset hash is the sepcified hash | ||
| 336 | * | ||
| 337 | * @param string $hash The user's reset hash | ||
| 338 | * | ||
| 339 | * @return true|false true if the user's hash is correct, false otherwise | ||
| 340 | * | ||
| 341 |      * @SuppressWarnings("UnusedFormalParameter") | ||
| 342 | */ | ||
| 343 | public function validate_reset_hash($hash) | ||
| 347 | |||
| 348 | /** | ||
| 349 | * Change the user's password, validating the old password or reset hash | ||
| 350 | * | ||
| 351 | * @param string $oldpass The user's original password or reset hash if $isHash is true | ||
| 352 | * @param string $newpass The user's new password | ||
| 353 | * @param boolean $isHash Is $old_pass a password or a hash | ||
| 354 | * | ||
| 355 | * @return true|false true if the user's password was changed, false otherwise | ||
| 356 | */ | ||
| 357 | public function change_pass($oldpass, $newpass, $isHash=false) | ||
| 373 | |||
| 374 | /** | ||
| 375 | * Set the user's display name | ||
| 376 | * | ||
| 377 | * @param string $name The user's new display name | ||
| 378 | * | ||
| 379 | * @return true|false true if the user's display name was changed, false otherwise | ||
| 380 | */ | ||
| 381 | public function setDisplayName($name) | ||
| 385 | |||
| 386 | /** | ||
| 387 | * Set the user's given (first) name | ||
| 388 | * | ||
| 389 | * @param string $name The user's new given name | ||
| 390 | * | ||
| 391 | * @return true|false true if the user's given name was changed, false otherwise | ||
| 392 | */ | ||
| 393 | public function setGivenName($name) | ||
| 394 |     { | ||
| 395 | return $this->setUid($name); | ||
| 396 | } | ||
| 397 | |||
| 398 | /** | ||
| 399 | * Set the user's email address | ||
| 400 | * | ||
| 401 | * @param string $email The user's new email address | ||
| 402 | * | ||
| 403 | * @return true|false true if the user's email address was changed, false otherwise | ||
| 404 | * | ||
| 405 |      * @SuppressWarnings("UnusedFormalParameter") | ||
| 406 | */ | ||
| 407 | public function setEmail($email) | ||
| 411 | |||
| 412 | /** | ||
| 413 | * Set the user's user ID or user name | ||
| 414 | * | ||
| 415 | * @param string $uid The user's new user ID | ||
| 416 | * | ||
| 417 | * @return true|false true if the user's ID was changed, false otherwise | ||
| 418 | * | ||
| 419 |      * @SuppressWarnings("UnusedFormalParameter") | ||
| 420 | */ | ||
| 421 | public function setUid($uid) | ||
| 425 | |||
| 426 | /** | ||
| 427 | * Set the user's photo | ||
| 428 | * | ||
| 429 | * @param string $photo The user's new photo as a binary string | ||
| 430 | * | ||
| 431 | * @return true|false true if the user's photo was changed, false otherwise | ||
| 432 | * | ||
| 433 |      * @SuppressWarnings("UnusedFormalParameter") | ||
| 434 | */ | ||
| 435 | public function setPhoto($photo) | ||
| 439 | |||
| 440 | /** | ||
| 441 | * Set the user's phone number | ||
| 442 | * | ||
| 443 | * @param string $phone The user's new phonew number | ||
| 444 | * | ||
| 445 | * @return true|false true if the user's phone number was changed, false otherwise | ||
| 446 | * | ||
| 447 |      * @SuppressWarnings("UnusedFormalParameter") | ||
| 448 | */ | ||
| 449 | public function setPhoneNumber($phone) | ||
| 453 | |||
| 454 | /** | ||
| 455 | * Set the user's organization | ||
| 456 | * | ||
| 457 | * @param string $org The user's new organization | ||
| 458 | * | ||
| 459 | * @return true|false true if the user's organization was changed, false otherwise | ||
| 460 | * | ||
| 461 |      * @SuppressWarnings("UnusedFormalParameter") | ||
| 462 | */ | ||
| 463 | public function setOrganization($org) | ||
| 467 | |||
| 468 | /** | ||
| 469 | * Set the user's titles | ||
| 470 | * | ||
| 471 | * @param string $titles The user's new titles | ||
| 472 | * | ||
| 473 | * @return true|false true if the user's titles were changed, false otherwise | ||
| 474 | * | ||
| 475 |      * @SuppressWarnings("UnusedFormalParameter") | ||
| 476 | */ | ||
| 477 | public function setTitles($titles) | ||
| 481 | |||
| 482 | /** | ||
| 483 | * Set the user's state | ||
| 484 | * | ||
| 485 | * @param string $state The user's new state | ||
| 486 | * | ||
| 487 | * @return true|false true if the user's state was changed, false otherwise | ||
| 488 | * | ||
| 489 |      * @SuppressWarnings("UnusedFormalParameter") | ||
| 490 | */ | ||
| 491 | public function setState($state) | ||
| 495 | |||
| 496 | /** | ||
| 497 | * Set the user's city | ||
| 498 | * | ||
| 499 | * @param string $city The user's new city | ||
| 500 | * | ||
| 501 | * @return true|false true if the user's city was changed, false otherwise | ||
| 502 | * | ||
| 503 |      * @SuppressWarnings("UnusedFormalParameter") | ||
| 504 | */ | ||
| 505 | public function setCity($city) | ||
| 509 | |||
| 510 | /** | ||
| 511 | * Set the user's last name | ||
| 512 | * | ||
| 513 | * @param string $sn The user's new last name | ||
| 514 | * | ||
| 515 | * @return true|false true if the user's last name was changed, false otherwise | ||
| 516 | * | ||
| 517 |      * @SuppressWarnings("UnusedFormalParameter") | ||
| 518 | */ | ||
| 519 | public function setLastName($sn) | ||
| 523 | |||
| 524 | /** | ||
| 525 | * Set the user's nick name | ||
| 526 | * | ||
| 527 | * @param string $displayName The user's new nick name | ||
| 528 | * | ||
| 529 | * @return true|false true if the user's nick name was changed, false otherwise | ||
| 530 | */ | ||
| 531 | public function setNickName($displayName) | ||
| 535 | |||
| 536 | /** | ||
| 537 | * Set the user's mailing address | ||
| 538 | * | ||
| 539 | * @param string $address The user's new mailing address | ||
| 540 | * | ||
| 541 | * @return true|false true if the user's mailing address was changed, false otherwise | ||
| 542 | * | ||
| 543 |      * @SuppressWarnings("UnusedFormalParameter") | ||
| 544 | */ | ||
| 545 | public function setAddress($address) | ||
| 549 | |||
| 550 | /** | ||
| 551 | * Set the user's postal or zip code | ||
| 552 | * | ||
| 553 | * @param string $postalcode The user's new postal code | ||
| 554 | * | ||
| 555 | * @return true|false true if the user's postal code was changed, false otherwise | ||
| 556 | * | ||
| 557 |      * @SuppressWarnings("UnusedFormalParameter") | ||
| 558 | */ | ||
| 559 | public function setPostalCode($postalcode) | ||
| 563 | |||
| 564 | /** | ||
| 565 | * Set the user's country | ||
| 566 | * | ||
| 567 | * @param string $country The user's new country | ||
| 568 | * | ||
| 569 | * @return true|false true if the user's country was changed, false otherwise | ||
| 570 | * | ||
| 571 |      * @SuppressWarnings("UnusedFormalParameter") | ||
| 572 | */ | ||
| 573 | public function setCountry($country) | ||
| 577 | |||
| 578 | /** | ||
| 579 | * Set the user's organizations | ||
| 580 | * | ||
| 581 | * @param string $ous The user's new organizations | ||
| 582 | * | ||
| 583 | * @return true|false true if the user's organizations was changed, false otherwise | ||
| 584 | * | ||
| 585 |      * @SuppressWarnings("UnusedFormalParameter") | ||
| 586 | */ | ||
| 587 | public function setOrganizationUnits($ous) | ||
| 591 | |||
| 592 | /** | ||
| 593 | * Allow write for the user | ||
| 594 | */ | ||
| 595 | protected function enableReadWrite() | ||
| 602 | |||
| 603 | /** | ||
| 604 | * Update the user password if required | ||
| 605 | */ | ||
| 606 | private function editUserPassword($data) | ||
| 623 | |||
| 624 | private function editNames($data) | ||
| 647 | |||
| 648 | private function checkForUnsettableElements($data) | ||
| 667 | |||
| 668 | private function editAddressElements($data) | ||
| 696 | |||
| 697 | private function editOrganizationElements($data) | ||
| 715 | |||
| 716 | /** | ||
| 717 | * Modify the user given the provided data object | ||
| 718 | * | ||
| 719 | * @param stdClass $data The user's new data | ||
| 720 | * | ||
| 721 | * @return true|false true if the user's data was changed, false otherwise | ||
| 722 | */ | ||
| 723 | public function editUser($data) | ||
| 744 | |||
| 745 | /** | ||
| 746 | * Obtain the user's password reset hash | ||
| 747 | * | ||
| 748 | * @return string|false A hash if available, false otherwise | ||
| 749 | */ | ||
| 750 | public function getPasswordResetHash() | ||
| 754 | |||
| 755 | /** | ||
| 756 | * Serialize the user data into a format usable by the json_encode method | ||
| 757 | * | ||
| 758 | * @return array A simple keyed array representing the user | ||
| 759 | */ | ||
| 760 | public function jsonSerialize() | ||
| 784 | |||
| 785 | /** | ||
| 786 | * Serialize the user data into a VCARD 2.1 format | ||
| 787 | * | ||
| 788 | * @return string The VCARD for the user | ||
| 789 | */ | ||
| 790 | public function getVcard() | ||
| 802 | } | ||
| 803 | /* vim: set tabstop=4 shiftwidth=4 expandtab: */ | ||
| 805 | 
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.