Complex classes like PersonTrait 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 PersonTrait, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 13 | trait PersonTrait |
||
| 14 | { |
||
| 15 | private $_additionalName; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @return string |
||
| 19 | */ |
||
| 20 | public function getAdditionalName() |
||
| 24 | |||
| 25 | /** |
||
| 26 | * An additional name for a Person, can be used for a middle name. |
||
| 27 | * |
||
| 28 | * @param string $additionalName |
||
| 29 | * @return PersonTrait |
||
|
|
|||
| 30 | */ |
||
| 31 | public function setAdditionalName($additionalName) |
||
| 36 | |||
| 37 | private $_address; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @return PostalAddress|string |
||
| 41 | */ |
||
| 42 | public function getAddress() |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Physical address of the item. |
||
| 49 | * |
||
| 50 | * @param PostalAddress|string $address |
||
| 51 | * @return PersonTrait |
||
| 52 | */ |
||
| 53 | public function setAddress(PostalAddress $address) |
||
| 58 | |||
| 59 | private $_affiliation; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @return Organization |
||
| 63 | */ |
||
| 64 | public function getAffiliation() |
||
| 68 | |||
| 69 | /** |
||
| 70 | * An organization that this person is affiliated with. For example, a school/university, a club, or a team. |
||
| 71 | * |
||
| 72 | * @param Organization $affiliation |
||
| 73 | * @return PersonTrait |
||
| 74 | */ |
||
| 75 | public function setAffiliation(Organization $affiliation) |
||
| 80 | |||
| 81 | private $_award; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @return string |
||
| 85 | */ |
||
| 86 | public function getAward() |
||
| 90 | |||
| 91 | /** |
||
| 92 | * An award won by or for this item. |
||
| 93 | * Supersedes awards. |
||
| 94 | * |
||
| 95 | * @param string $award |
||
| 96 | * @return PersonTrait |
||
| 97 | */ |
||
| 98 | public function setAward($award) |
||
| 103 | |||
| 104 | private $_birthDate; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @return string |
||
| 108 | */ |
||
| 109 | public function getBirthDate() |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Date of birth. |
||
| 116 | * |
||
| 117 | * @param DateValue $birthDate |
||
| 118 | * @return PersonTrait |
||
| 119 | */ |
||
| 120 | public function setBirthDate(DateValue $birthDate) |
||
| 125 | |||
| 126 | private $_birthPlace; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @return Place |
||
| 130 | */ |
||
| 131 | public function getBirthPlace() |
||
| 135 | |||
| 136 | /** |
||
| 137 | * The place where the person was born. |
||
| 138 | * |
||
| 139 | * @param Place $birthPlace |
||
| 140 | * @return PersonTrait |
||
| 141 | */ |
||
| 142 | public function setBirthPlace($birthPlace) |
||
| 147 | |||
| 148 | private $_brand; |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @return Brand|Organization |
||
| 152 | */ |
||
| 153 | public function getBrand() |
||
| 157 | |||
| 158 | /** |
||
| 159 | * The brand(s) associated with a product or service, or the brand(s) maintained by an organization or business person. |
||
| 160 | * |
||
| 161 | * @param Brand|Organization $brand |
||
| 162 | * @return PersonTrait |
||
| 163 | */ |
||
| 164 | public function setBrand($brand) |
||
| 169 | |||
| 170 | private $_children; |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @return Person |
||
| 174 | */ |
||
| 175 | public function getChildren() |
||
| 179 | |||
| 180 | /** |
||
| 181 | * A child of the person. |
||
| 182 | * |
||
| 183 | * @param Person $children |
||
| 184 | * @return PersonTrait |
||
| 185 | */ |
||
| 186 | public function setChildren(Person $children) |
||
| 191 | |||
| 192 | private $_colleague; |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @return Person |
||
| 196 | */ |
||
| 197 | public function getColleague() |
||
| 201 | |||
| 202 | /** |
||
| 203 | * A colleague of the person. |
||
| 204 | * |
||
| 205 | * Supersedes colleagues. |
||
| 206 | * |
||
| 207 | * @param Person $colleague |
||
| 208 | * @return PersonTrait |
||
| 209 | */ |
||
| 210 | public function setColleague(Person $colleague) |
||
| 215 | |||
| 216 | private $_contactPoint; |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @return ContactPoint |
||
| 220 | */ |
||
| 221 | public function getContactPoint() |
||
| 225 | |||
| 226 | /** |
||
| 227 | * A contact point for a person or organization. |
||
| 228 | * |
||
| 229 | * Supersedes contactPoints. |
||
| 230 | * |
||
| 231 | * @param ContactPoint $contactPoint |
||
| 232 | * @return PersonTrait |
||
| 233 | */ |
||
| 234 | public function setContactPoint(ContactPoint $contactPoint) |
||
| 239 | |||
| 240 | private $_deathDate; |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @return string |
||
| 244 | */ |
||
| 245 | public function getDeathDate() |
||
| 249 | |||
| 250 | /** |
||
| 251 | * Date of death. |
||
| 252 | * |
||
| 253 | * @param DateValue $deathDate |
||
| 254 | * @return PersonTrait |
||
| 255 | */ |
||
| 256 | public function setDeathDate(DateValue $deathDate) |
||
| 261 | |||
| 262 | private $_deathPlace; |
||
| 263 | |||
| 264 | /** |
||
| 265 | * @return Place |
||
| 266 | */ |
||
| 267 | public function getDeathPlace() |
||
| 271 | |||
| 272 | /** |
||
| 273 | * The place where the person died. |
||
| 274 | * |
||
| 275 | * @param Place $deathPlace |
||
| 276 | * @return PersonTrait |
||
| 277 | */ |
||
| 278 | public function setDeathPlace(Place $deathPlace) |
||
| 283 | |||
| 284 | private $_duns; |
||
| 285 | |||
| 286 | /** |
||
| 287 | * @return string |
||
| 288 | */ |
||
| 289 | public function getDuns() |
||
| 293 | |||
| 294 | /** |
||
| 295 | * The Dun & Bradstreet DUNS number for identifying an organization or business person. |
||
| 296 | * |
||
| 297 | * @param string $duns |
||
| 298 | * @return PersonTrait |
||
| 299 | */ |
||
| 300 | public function setDuns(Person $duns) |
||
| 305 | |||
| 306 | private $_email; |
||
| 307 | |||
| 308 | /** |
||
| 309 | * @return string |
||
| 310 | */ |
||
| 311 | public function getEmail() |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Email address. |
||
| 318 | * |
||
| 319 | * @param string $email |
||
| 320 | * @return PersonTrait |
||
| 321 | */ |
||
| 322 | public function setEmail($email) |
||
| 327 | |||
| 328 | private $_familyName; |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @return string |
||
| 332 | */ |
||
| 333 | public function getFamilyName() |
||
| 337 | |||
| 338 | /** |
||
| 339 | * Family name. In the U.S., the last name of an Person. |
||
| 340 | * This can be used along with givenName instead of the name property. |
||
| 341 | * |
||
| 342 | * @param string $familyName |
||
| 343 | * @return PersonTrait |
||
| 344 | */ |
||
| 345 | public function setFamilyName($familyName) |
||
| 350 | |||
| 351 | private $_faxNumber; |
||
| 352 | |||
| 353 | /** |
||
| 354 | * @return string |
||
| 355 | */ |
||
| 356 | public function getFaxNumber() |
||
| 360 | |||
| 361 | /** |
||
| 362 | * The fax number. |
||
| 363 | * |
||
| 364 | * @param string $faxNumber |
||
| 365 | * @return PersonTrait |
||
| 366 | */ |
||
| 367 | public function setFaxNumber($faxNumber) |
||
| 372 | |||
| 373 | private $_follows; |
||
| 374 | |||
| 375 | /** |
||
| 376 | * @return Person |
||
| 377 | */ |
||
| 378 | public function getFollows() |
||
| 382 | |||
| 383 | /** |
||
| 384 | * The most generic uni-directional social relation. |
||
| 385 | * |
||
| 386 | * @param Person $follows |
||
| 387 | * @return PersonTrait |
||
| 388 | */ |
||
| 389 | public function setFollows(Person $follows) |
||
| 394 | |||
| 395 | private $_funder; |
||
| 396 | |||
| 397 | /** |
||
| 398 | * @return Organization|Person |
||
| 399 | */ |
||
| 400 | public function getFunder() |
||
| 404 | |||
| 405 | /** |
||
| 406 | * A person or organization that supports (sponsors) something through some kind of financial contribution. |
||
| 407 | * |
||
| 408 | * @param Organization|Person $funder |
||
| 409 | * @return PersonTrait |
||
| 410 | */ |
||
| 411 | public function setFunder($funder) |
||
| 416 | |||
| 417 | private $_gender; |
||
| 418 | |||
| 419 | /** |
||
| 420 | * @return GenderType|string |
||
| 421 | */ |
||
| 422 | public function getGender() |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Gender of the person. While http://schema.org/Male and http://schema.org/Female may be used, |
||
| 429 | * text strings are also acceptable for people who do not identify as a binary gender. |
||
| 430 | * |
||
| 431 | * @param GenderType|string $gender |
||
| 432 | * @return PersonTrait |
||
| 433 | */ |
||
| 434 | public function setGender($gender) |
||
| 439 | |||
| 440 | private $_givenName; |
||
| 441 | |||
| 442 | /** |
||
| 443 | * @return string |
||
| 444 | */ |
||
| 445 | public function getGivenName() |
||
| 449 | |||
| 450 | /** |
||
| 451 | * Given name. In the U.S., the first name of a Person. |
||
| 452 | * This can be used along with familyName instead of the name property. |
||
| 453 | * |
||
| 454 | * @param string $givenName |
||
| 455 | * @return PersonTrait |
||
| 456 | */ |
||
| 457 | public function setGivenName($givenName) |
||
| 462 | |||
| 463 | private $_globalLocationNumber; |
||
| 464 | |||
| 465 | /** |
||
| 466 | * @return string |
||
| 467 | */ |
||
| 468 | public function getGlobalLocationNumber() |
||
| 472 | |||
| 473 | /** |
||
| 474 | * The Global Location Number (GLN, sometimes also referred to as International Location Number or ILN) |
||
| 475 | * of the respective organization, person, or place. |
||
| 476 | * The GLN is a 13-digit number used to identify parties and physical locations. |
||
| 477 | * |
||
| 478 | * @param string $globalLocationNumber |
||
| 479 | * @return PersonTrait |
||
| 480 | */ |
||
| 481 | public function setGlobalLocationNumber($globalLocationNumber) |
||
| 486 | |||
| 487 | private $_hasPOS; |
||
| 488 | |||
| 489 | /** |
||
| 490 | * @return Place |
||
| 491 | */ |
||
| 492 | public function getHasPOS() |
||
| 496 | |||
| 497 | /** |
||
| 498 | * Points-of-Sales operated by the organization or person. |
||
| 499 | * |
||
| 500 | * @param Place $hasPOS |
||
| 501 | * @return PersonTrait |
||
| 502 | */ |
||
| 503 | public function setHasPOS($hasPOS) |
||
| 508 | |||
| 509 | private $_height; |
||
| 510 | |||
| 511 | /** |
||
| 512 | * @return Distance|QuantitativeValue |
||
| 513 | */ |
||
| 514 | public function getHeight() |
||
| 518 | |||
| 519 | /** |
||
| 520 | * The height of the item. |
||
| 521 | * |
||
| 522 | * @param Distance|QuantitativeValue $height |
||
| 523 | * @return PersonTrait |
||
| 524 | */ |
||
| 525 | public function setHeight($height) |
||
| 530 | |||
| 531 | private $_homeLocation; |
||
| 532 | |||
| 533 | /** |
||
| 534 | * @return ContactPoint|Place |
||
| 535 | */ |
||
| 536 | public function getHomeLocation() |
||
| 540 | |||
| 541 | /** |
||
| 542 | * A contact location for a person's residence. |
||
| 543 | * |
||
| 544 | * @param ContactPoint|Place $homeLocation |
||
| 545 | * @return PersonTrait |
||
| 546 | */ |
||
| 547 | public function setHomeLocation($homeLocation) |
||
| 552 | |||
| 553 | private $_honorificPrefix; |
||
| 554 | |||
| 555 | /** |
||
| 556 | * @return string |
||
| 557 | */ |
||
| 558 | public function getHonorificPrefix() |
||
| 562 | |||
| 563 | /** |
||
| 564 | * An honorific prefix preceding a Person's name such as Dr/Mrs/Mr. |
||
| 565 | * |
||
| 566 | * @param string $honorificPrefix |
||
| 567 | * @return PersonTrait |
||
| 568 | */ |
||
| 569 | public function setHonorificPrefix($honorificPrefix) |
||
| 574 | |||
| 575 | private $_honorificSuffix; |
||
| 576 | |||
| 577 | /** |
||
| 578 | * @return string |
||
| 579 | */ |
||
| 580 | public function getHonorificSuffix() |
||
| 584 | |||
| 585 | /** |
||
| 586 | * An honorific suffix preceding a Person's name such as M.D. /PhD/MSCSW. |
||
| 587 | * |
||
| 588 | * @param string $honorificSuffix |
||
| 589 | * @return PersonTrait |
||
| 590 | */ |
||
| 591 | public function setHonorificSuffix($honorificSuffix) |
||
| 596 | |||
| 597 | private $_isicV4; |
||
| 598 | |||
| 599 | /** |
||
| 600 | * @return string |
||
| 601 | */ |
||
| 602 | public function getIsicV4() |
||
| 606 | |||
| 607 | /** |
||
| 608 | * The International Standard of Industrial Classification of All Economic Activities (ISIC), |
||
| 609 | * Revision 4 code for a particular organization, business person, or place. |
||
| 610 | * |
||
| 611 | * @param string $isicV4 |
||
| 612 | * @return PersonTrait |
||
| 613 | */ |
||
| 614 | public function setIsicV4($isicV4) |
||
| 619 | |||
| 620 | private $_jobTitle; |
||
| 621 | |||
| 622 | /** |
||
| 623 | * @return string |
||
| 624 | */ |
||
| 625 | public function getJobTitle() |
||
| 629 | |||
| 630 | /** |
||
| 631 | * The job title of the person (for example, Financial Manager). |
||
| 632 | * |
||
| 633 | * @param string $jobTitle |
||
| 634 | * @return PersonTrait |
||
| 635 | */ |
||
| 636 | public function setJobTitle($jobTitle) |
||
| 641 | |||
| 642 | private $_knows; |
||
| 643 | |||
| 644 | /** |
||
| 645 | * @return Person |
||
| 646 | */ |
||
| 647 | public function getKnows() |
||
| 651 | |||
| 652 | /** |
||
| 653 | * The most generic bi-directional social/work relation. |
||
| 654 | * |
||
| 655 | * @param Person $knows |
||
| 656 | * @return PersonTrait |
||
| 657 | */ |
||
| 658 | public function setKnows(Person $knows) |
||
| 663 | |||
| 664 | private $_makesOffer; |
||
| 665 | |||
| 666 | /** |
||
| 667 | * @return Offer |
||
| 668 | */ |
||
| 669 | public function getMakesOffer() |
||
| 673 | |||
| 674 | /** |
||
| 675 | * A pointer to products or services offered by the organization or person. |
||
| 676 | * Inverse property: offeredBy. |
||
| 677 | * |
||
| 678 | * @param Offer $makesOffer |
||
| 679 | * @return PersonTrait |
||
| 680 | */ |
||
| 681 | public function setMakesOffer(Offer $makesOffer) |
||
| 686 | |||
| 687 | private $_memberOf; |
||
| 688 | |||
| 689 | /** |
||
| 690 | * @return Organization|ProgramMembership |
||
| 691 | */ |
||
| 692 | public function getMemberOf() |
||
| 696 | |||
| 697 | /** |
||
| 698 | * An Organization (or ProgramMembership) to which this Person or Organization belongs. |
||
| 699 | * Inverse property: member. |
||
| 700 | * |
||
| 701 | * @param Organization|ProgramMembership $memberOf |
||
| 702 | * @return PersonTrait |
||
| 703 | */ |
||
| 704 | public function setMemberOf($memberOf) |
||
| 709 | |||
| 710 | private $_naics; |
||
| 711 | |||
| 712 | /** |
||
| 713 | * @return string |
||
| 714 | */ |
||
| 715 | public function getNaics() |
||
| 719 | |||
| 720 | /** |
||
| 721 | * The North American Industry Classification System (NAICS) code for a particular organization or business person. |
||
| 722 | * |
||
| 723 | * @param string $naics |
||
| 724 | * @return PersonTrait |
||
| 725 | */ |
||
| 726 | public function setNaics($naics) |
||
| 731 | |||
| 732 | private $_nationality; |
||
| 733 | |||
| 734 | /** |
||
| 735 | * @return Country |
||
| 736 | */ |
||
| 737 | public function getNationality() |
||
| 741 | |||
| 742 | /** |
||
| 743 | * Nationality of the person. |
||
| 744 | * |
||
| 745 | * @param Country $nationality |
||
| 746 | * @return PersonTrait |
||
| 747 | */ |
||
| 748 | public function setNationality(Country $nationality) |
||
| 753 | |||
| 754 | private $_parent; |
||
| 755 | |||
| 756 | /** |
||
| 757 | * @return Person |
||
| 758 | */ |
||
| 759 | public function getParent() |
||
| 763 | |||
| 764 | /** |
||
| 765 | * A parent of this person. Supersedes parents. |
||
| 766 | * |
||
| 767 | * @param Person $parent |
||
| 768 | * @return PersonTrait |
||
| 769 | */ |
||
| 770 | public function setParent(Person $parent) |
||
| 775 | |||
| 776 | private $_performerIn; |
||
| 777 | |||
| 778 | /** |
||
| 779 | * @return Event |
||
| 780 | */ |
||
| 781 | public function getPerformerIn() |
||
| 785 | |||
| 786 | /** |
||
| 787 | * Event that this person is a performer or participant in. |
||
| 788 | * |
||
| 789 | * @param Event $performerIn |
||
| 790 | * @return PersonTrait |
||
| 791 | */ |
||
| 792 | public function setPerformerIn(Event $performerIn) |
||
| 797 | |||
| 798 | private $_publishingPrinciples; |
||
| 799 | |||
| 800 | /** |
||
| 801 | * @return CreativeWork|URL |
||
| 802 | */ |
||
| 803 | public function getPublishingPrinciples() |
||
| 807 | |||
| 808 | /** |
||
| 809 | * The publishingPrinciples property indicates (typically via URL) a document describing the editorial principles |
||
| 810 | * of an Organization (or individual e.g. a Person writing a blog) that relate to their activities as a publisher, |
||
| 811 | * e.g. ethics or diversity policies. When applied to a CreativeWork (e.g. NewsArticle) the principles are those |
||
| 812 | * of the party primarily responsible for the creation of the CreativeWork. |
||
| 813 | * |
||
| 814 | * While such policies are most typically expressed in natural language, sometimes related information |
||
| 815 | * (e.g. indicating a funder) can be expressed using schema.org terminology. |
||
| 816 | * |
||
| 817 | * @param CreativeWork|URL $publishingPrinciples |
||
| 818 | * @return PersonTrait |
||
| 819 | */ |
||
| 820 | public function setPublishingPrinciples($publishingPrinciples) |
||
| 825 | |||
| 826 | private $_relatedTo; |
||
| 827 | |||
| 828 | /** |
||
| 829 | * @return Person |
||
| 830 | */ |
||
| 831 | public function getRelatedTo() |
||
| 835 | |||
| 836 | /** |
||
| 837 | * The most generic familial relation. |
||
| 838 | * |
||
| 839 | * @param Person $relatedTo |
||
| 840 | * @return PersonTrait |
||
| 841 | */ |
||
| 842 | public function setRelatedTo(Person $relatedTo) |
||
| 847 | |||
| 848 | private $_sibling; |
||
| 849 | |||
| 850 | /** |
||
| 851 | * @return Person |
||
| 852 | */ |
||
| 853 | public function getSibling() |
||
| 857 | |||
| 858 | /** |
||
| 859 | * A sibling of the person. Supersedes siblings. |
||
| 860 | * |
||
| 861 | * @param Person $sibling |
||
| 862 | * @return PersonTrait |
||
| 863 | */ |
||
| 864 | public function setSibling(Person $sibling) |
||
| 869 | |||
| 870 | private $_sponsor; |
||
| 871 | |||
| 872 | /** |
||
| 873 | * @return Organization|Person |
||
| 874 | */ |
||
| 875 | public function getSponsor() |
||
| 879 | |||
| 880 | /** |
||
| 881 | * A person or organization that supports a thing through a pledge, promise, or financial contribution. |
||
| 882 | * e.g. a sponsor of a Medical Study or a corporate sponsor of an event. |
||
| 883 | * |
||
| 884 | * @param Organization|Person $sponsor |
||
| 885 | * @return PersonTrait |
||
| 886 | */ |
||
| 887 | public function setSponsor($sponsor) |
||
| 892 | |||
| 893 | private $_spouse; |
||
| 894 | |||
| 895 | /** |
||
| 896 | * @return Person |
||
| 897 | */ |
||
| 898 | public function getSpouse() |
||
| 902 | |||
| 903 | /** |
||
| 904 | * The person's spouse. |
||
| 905 | * |
||
| 906 | * @param Person $spouse |
||
| 907 | * @return PersonTrait |
||
| 908 | */ |
||
| 909 | public function setSpouse(Person $spouse) |
||
| 914 | |||
| 915 | private $_taxID; |
||
| 916 | |||
| 917 | /** |
||
| 918 | * @return string |
||
| 919 | */ |
||
| 920 | public function getTaxID() |
||
| 924 | |||
| 925 | /** |
||
| 926 | * The Tax / Fiscal ID of the organization or person, e.g. the TIN in the US or the CIF/NIF in Spain. |
||
| 927 | * |
||
| 928 | * @param string $taxID |
||
| 929 | * @return PersonTrait |
||
| 930 | */ |
||
| 931 | public function setTaxID($taxID) |
||
| 936 | |||
| 937 | private $_telephone; |
||
| 938 | |||
| 939 | /** |
||
| 940 | * @return string |
||
| 941 | */ |
||
| 942 | public function getTelephone() |
||
| 946 | |||
| 947 | /** |
||
| 948 | * The telephone number. |
||
| 949 | * |
||
| 950 | * @param string $telephone |
||
| 951 | * @return PersonTrait |
||
| 952 | */ |
||
| 953 | public function setTelephone($telephone) |
||
| 958 | |||
| 959 | private $_vatID; |
||
| 960 | |||
| 961 | /** |
||
| 962 | * @return string |
||
| 963 | */ |
||
| 964 | public function getVatID() |
||
| 968 | |||
| 969 | /** |
||
| 970 | * The Value-added Tax ID of the organization or person. |
||
| 971 | * |
||
| 972 | * @param string $vatID |
||
| 973 | * @return PersonTrait |
||
| 974 | */ |
||
| 975 | public function setVatID($vatID) |
||
| 980 | |||
| 981 | private $_workLocation; |
||
| 982 | |||
| 983 | /** |
||
| 984 | * @return ContactPoint|Place |
||
| 985 | */ |
||
| 986 | public function getWorkLocation() |
||
| 990 | |||
| 991 | /** |
||
| 992 | * A contact location for a person's place of work. |
||
| 993 | * |
||
| 994 | * @param ContactPoint|Place $workLocation |
||
| 995 | * @return PersonTrait |
||
| 996 | */ |
||
| 997 | public function setWorkLocation($workLocation) |
||
| 1002 | |||
| 1003 | private $_worksFor; |
||
| 1004 | |||
| 1005 | /** |
||
| 1006 | * @return Organization |
||
| 1007 | */ |
||
| 1008 | public function getWorksFor() |
||
| 1012 | |||
| 1013 | /** |
||
| 1014 | * Organizations that the person works for. |
||
| 1015 | * |
||
| 1016 | * @param Organization $worksFor |
||
| 1017 | * @return PersonTrait |
||
| 1018 | */ |
||
| 1019 | public function setWorksFor(Organization $worksFor) |
||
| 1024 | } |
||
| 1025 |
In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.
If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.