Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Job 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 Job, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 29 | class Job extends BaseEntity implements JobInterface, |
||
|
|
|||
| 30 | DraftableEntityInterface, |
||
| 31 | SnapshotGeneratorProviderInterface |
||
| 32 | { |
||
| 33 | |||
| 34 | /** |
||
| 35 | * unique ID of a job posting used by applications to reference |
||
| 36 | * a job |
||
| 37 | * |
||
| 38 | * @var String |
||
| 39 | * @ODM\String @ODM\Index |
||
| 40 | **/ |
||
| 41 | protected $applyId; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * title of a job posting |
||
| 45 | * |
||
| 46 | * @var String |
||
| 47 | * @ODM\String |
||
| 48 | */ |
||
| 49 | protected $title; |
||
| 50 | |||
| 51 | |||
| 52 | /** |
||
| 53 | * name of the publishing company |
||
| 54 | * |
||
| 55 | * @var String |
||
| 56 | * @ODM\String |
||
| 57 | */ |
||
| 58 | protected $company; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * publishing company |
||
| 62 | * |
||
| 63 | * @var OrganizationInterface |
||
| 64 | * @ODM\ReferenceOne (targetDocument="\Organizations\Entity\Organization", simple=true, inversedBy="jobs") |
||
| 65 | * @ODM\Index |
||
| 66 | */ |
||
| 67 | protected $organization; |
||
| 68 | |||
| 69 | |||
| 70 | /** |
||
| 71 | * Email Address, which is used to send notifications about e.g. new applications. |
||
| 72 | * |
||
| 73 | * @var String |
||
| 74 | * @ODM\String |
||
| 75 | **/ |
||
| 76 | protected $contactEmail; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * the owner of a Job Posting |
||
| 80 | * |
||
| 81 | * @var UserInterface $user |
||
| 82 | * @ODM\ReferenceOne(targetDocument="\Auth\Entity\User", simple=true) |
||
| 83 | * @ODM\Index |
||
| 84 | */ |
||
| 85 | protected $user; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * all applications of a certain jobad |
||
| 89 | * |
||
| 90 | * @var Collection |
||
| 91 | * @ODM\ReferenceMany(targetDocument="Applications\Entity\Application", simple=true, mappedBy="job", |
||
| 92 | * repositoryMethod="loadApplicationsForJob") |
||
| 93 | */ |
||
| 94 | protected $applications; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * new applications |
||
| 98 | * |
||
| 99 | * @ODM\ReferenceMany(targetDocument="Applications\Entity\Application", |
||
| 100 | * repositoryMethod="loadUnreadApplicationsForJob", mappedBy="job") |
||
| 101 | * @var Int |
||
| 102 | */ |
||
| 103 | protected $unreadApplications; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * language of the job posting. Languages are ISO 639-1 coded |
||
| 107 | * |
||
| 108 | * @var String |
||
| 109 | * @ODM\String |
||
| 110 | */ |
||
| 111 | protected $language; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * location of the job posting. This is a plain text, which describes the location in |
||
| 115 | * search e.g. results. |
||
| 116 | * |
||
| 117 | * @var String |
||
| 118 | * @ODM\String |
||
| 119 | */ |
||
| 120 | protected $location; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * locations of the job posting. This collection contains structured coordinates, |
||
| 124 | * postal codes, city, region, and country names |
||
| 125 | * |
||
| 126 | * @var Collection |
||
| 127 | * @ODM\EmbedMany(targetDocument="Location") |
||
| 128 | */ |
||
| 129 | protected $locations; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Link which points to the job posting |
||
| 133 | * |
||
| 134 | * @var String |
||
| 135 | * @ODM\String |
||
| 136 | **/ |
||
| 137 | protected $link; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * publishing date of a job posting |
||
| 141 | * |
||
| 142 | * @var String |
||
| 143 | * @ODM\Field(type="tz_date") |
||
| 144 | */ |
||
| 145 | protected $datePublishStart; |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Status of the job posting |
||
| 149 | * |
||
| 150 | * @var Status |
||
| 151 | * @ODM\EmbedOne(targetDocument="Status") |
||
| 152 | * @ODM\Index |
||
| 153 | */ |
||
| 154 | protected $status; |
||
| 155 | |||
| 156 | /** |
||
| 157 | * History on an job posting |
||
| 158 | * |
||
| 159 | * @var Collection |
||
| 160 | * @ODM\EmbedMany(targetDocument="History") |
||
| 161 | */ |
||
| 162 | protected $history; |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Flag, privacy policy is accepted or not. |
||
| 166 | * |
||
| 167 | * @var bool |
||
| 168 | * @ODM\Boolean |
||
| 169 | */ |
||
| 170 | protected $termsAccepted; |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Reference of a job opening, on which an applicant can refer to. |
||
| 174 | * |
||
| 175 | * @var String |
||
| 176 | * @ODM\String |
||
| 177 | */ |
||
| 178 | protected $reference; |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Unified Resource Locator to the company-Logo |
||
| 182 | * |
||
| 183 | * @deprecated (use $organization->image->uri instead) |
||
| 184 | * @var String |
||
| 185 | * @ODM\String |
||
| 186 | */ |
||
| 187 | protected $logoRef; |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Template-Name |
||
| 191 | * |
||
| 192 | * @var String |
||
| 193 | * @ODM\String |
||
| 194 | */ |
||
| 195 | protected $template; |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Application link. |
||
| 199 | * |
||
| 200 | * @var String |
||
| 201 | * @ODM\String |
||
| 202 | */ |
||
| 203 | protected $uriApply; |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Unified Resource Locator the Yawik, which handled this job first - so |
||
| 207 | * does know who is the one who has commited this job. |
||
| 208 | * |
||
| 209 | * @var String |
||
| 210 | * @ODM\String |
||
| 211 | */ |
||
| 212 | protected $uriPublisher; |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @var |
||
| 216 | * @ODM\EmbedMany(targetDocument="Publisher") |
||
| 217 | */ |
||
| 218 | protected $publisher; |
||
| 219 | |||
| 220 | /** |
||
| 221 | * The ATS mode entity. |
||
| 222 | * |
||
| 223 | * @var AtsMode |
||
| 224 | * @ODM\EmbedOne(targetDocument="AtsMode") |
||
| 225 | */ |
||
| 226 | protected $atsMode; |
||
| 227 | |||
| 228 | /** |
||
| 229 | * this must be enabled to use applications forms etc. for this job or |
||
| 230 | * to see number of applications in the list of applications |
||
| 231 | * |
||
| 232 | * @var Boolean |
||
| 233 | * |
||
| 234 | * @ODM\Boolean |
||
| 235 | */ |
||
| 236 | protected $atsEnabled; |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Permissions |
||
| 240 | * |
||
| 241 | * @var PermissionsInterface |
||
| 242 | * @ODM\EmbedOne(targetDocument="\Core\Entity\Permissions") |
||
| 243 | */ |
||
| 244 | protected $permissions; |
||
| 245 | |||
| 246 | /** |
||
| 247 | * The actual name of the organization. |
||
| 248 | * |
||
| 249 | * @var TemplateValues |
||
| 250 | * @ODM\EmbedOne(targetDocument="\Jobs\Entity\TemplateValues") |
||
| 251 | */ |
||
| 252 | protected $templateValues; |
||
| 253 | |||
| 254 | |||
| 255 | /** |
||
| 256 | * Can contain various Portals |
||
| 257 | * |
||
| 258 | * @var array |
||
| 259 | * @ODM\Collection*/ |
||
| 260 | protected $portals = array(); |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Flag indicating draft state of this job. |
||
| 264 | * |
||
| 265 | * @var bool |
||
| 266 | * @ODM\Boolean |
||
| 267 | */ |
||
| 268 | protected $isDraft = false; |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Is this needed? |
||
| 272 | * |
||
| 273 | * @return string |
||
| 274 | */ |
||
| 275 | public function getResourceId() |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @see \Jobs\Entity\JobInterface::setApplyId() |
||
| 282 | * @param String $applyId |
||
| 283 | * @return \Jobs\Entity\JobInterface |
||
| 284 | */ |
||
| 285 | public function setApplyId($applyId) |
||
| 290 | /** |
||
| 291 | * @see \Jobs\Entity\JobInterface::getApplyId() |
||
| 292 | * @return String |
||
| 293 | */ |
||
| 294 | public function getApplyId() |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Gets the title of a job posting |
||
| 305 | * |
||
| 306 | * @return string |
||
| 307 | */ |
||
| 308 | public function getTitle() |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Sets the title of a job posting |
||
| 315 | * |
||
| 316 | * @see \Jobs\Entity\JobInterface::setTitle() |
||
| 317 | * @param String $title |
||
| 318 | * @return \Jobs\Entity\JobInterface |
||
| 319 | */ |
||
| 320 | public function setTitle($title) |
||
| 325 | |||
| 326 | /** |
||
| 327 | * (non-PHPdoc) |
||
| 328 | * @see \Jobs\Entity\JobInterface::getCompany() |
||
| 329 | */ |
||
| 330 | public function getCompany() |
||
| 337 | |||
| 338 | /** |
||
| 339 | * (non-PHPdoc) |
||
| 340 | * @see \Jobs\Entity\JobInterface::setCompany() |
||
| 341 | */ |
||
| 342 | public function setCompany($company) |
||
| 347 | |||
| 348 | /** |
||
| 349 | * (non-PHPdoc) |
||
| 350 | * @see \Jobs\Entity\JobInterface::getOrganization() |
||
| 351 | */ |
||
| 352 | public function getOrganization() |
||
| 356 | |||
| 357 | /** |
||
| 358 | * @inheritdoc |
||
| 359 | */ |
||
| 360 | public function setOrganization(OrganizationInterface $organization = null) |
||
| 372 | |||
| 373 | |||
| 374 | /** |
||
| 375 | * (non-PHPdoc) |
||
| 376 | * @see \Jobs\Entity\JobInterface::getContactEmail() |
||
| 377 | */ |
||
| 378 | public function getContactEmail() |
||
| 390 | /** |
||
| 391 | * (non-PHPdoc) |
||
| 392 | * @see \Jobs\Entity\JobInterface::setContactEmail() |
||
| 393 | */ |
||
| 394 | public function setContactEmail($email) |
||
| 399 | /** |
||
| 400 | * (non-PHPdoc) |
||
| 401 | * @see \Jobs\Entity\JobInterface::setLanguage() |
||
| 402 | */ |
||
| 403 | public function setLanguage($language) |
||
| 408 | /** |
||
| 409 | * (non-PHPdoc) |
||
| 410 | * @see \Jobs\Entity\JobInterface::getLanguage() |
||
| 411 | */ |
||
| 412 | public function getLanguage() |
||
| 416 | /** |
||
| 417 | * (non-PHPdoc) |
||
| 418 | * @see \Jobs\Entity\JobInterface::setLocation() |
||
| 419 | */ |
||
| 420 | public function setLocation($location) |
||
| 425 | /** |
||
| 426 | * (non-PHPdoc) |
||
| 427 | * @see \Jobs\Entity\JobInterface::getLocation() |
||
| 428 | */ |
||
| 429 | public function getLocation() |
||
| 433 | /** |
||
| 434 | * (non-PHPdoc) |
||
| 435 | * @see \Jobs\Entity\JobInterface::setLocations() |
||
| 436 | */ |
||
| 437 | public function setLocations($locations) |
||
| 442 | /** |
||
| 443 | * (non-PHPdoc) |
||
| 444 | * @see \Jobs\Entity\JobInterface::getLocations() |
||
| 445 | */ |
||
| 446 | public function getLocations() |
||
| 453 | /** |
||
| 454 | * (non-PHPdoc) |
||
| 455 | * @see \Jobs\Entity\JobInterface::setUser() |
||
| 456 | */ |
||
| 457 | View Code Duplication | public function setUser(UserInterface $user) |
|
| 466 | /** |
||
| 467 | * (non-PHPdoc) |
||
| 468 | * @see \Jobs\Entity\JobInterface::getUser() |
||
| 469 | */ |
||
| 470 | public function getUser() |
||
| 474 | |||
| 475 | public function unsetUser($removePermissions = true) |
||
| 486 | |||
| 487 | /** |
||
| 488 | * (non-PHPdoc) |
||
| 489 | * @see \Jobs\Entity\JobInterface::setApplications() |
||
| 490 | */ |
||
| 491 | public function setApplications(Collection $applications) |
||
| 496 | /** |
||
| 497 | * (non-PHPdoc) |
||
| 498 | * @see \Jobs\Entity\JobInterface::getApplications() |
||
| 499 | */ |
||
| 500 | public function getApplications() |
||
| 504 | /** |
||
| 505 | * Gets the number of unread applications |
||
| 506 | * @return Collection |
||
| 507 | */ |
||
| 508 | public function getUnreadApplications() |
||
| 512 | /** |
||
| 513 | * (non-PHPdoc) |
||
| 514 | * @see \Jobs\Entity\JobInterface::getLink() |
||
| 515 | */ |
||
| 516 | public function getLink() |
||
| 520 | /** |
||
| 521 | * (non-PHPdoc) |
||
| 522 | * @see \Jobs\Entity\JobInterface::setLink() |
||
| 523 | */ |
||
| 524 | public function setLink($link) |
||
| 529 | /** |
||
| 530 | * (non-PHPdoc) |
||
| 531 | * @see \Jobs\Entity\JobInterface::getDatePublishStart() |
||
| 532 | */ |
||
| 533 | public function getDatePublishStart() |
||
| 537 | /** |
||
| 538 | * (non-PHPdoc) |
||
| 539 | * @param string $datePublishStart |
||
| 540 | * @see \Jobs\Entity\JobInterface::setDatePublishStart() |
||
| 541 | * @return $this |
||
| 542 | */ |
||
| 543 | public function setDatePublishStart($datePublishStart) |
||
| 548 | |||
| 549 | /** |
||
| 550 | * Modifies the state of an application. |
||
| 551 | * |
||
| 552 | * Creates a history entry. |
||
| 553 | * |
||
| 554 | * @param StatusInterface|string $status |
||
| 555 | * @param string $message |
||
| 556 | * @return Job |
||
| 557 | */ |
||
| 558 | View Code Duplication | public function changeStatus($status, $message = '[System]') |
|
| 568 | |||
| 569 | /** |
||
| 570 | * (non-PHPdoc) |
||
| 571 | * @see \Jobs\Entity\JobInterface::getStatus() |
||
| 572 | */ |
||
| 573 | public function getStatus() |
||
| 577 | /** |
||
| 578 | * (non-PHPdoc) |
||
| 579 | * @see \Jobs\Entity\JobInterface::setStatus() |
||
| 580 | */ |
||
| 581 | public function setStatus($status) |
||
| 588 | |||
| 589 | /** |
||
| 590 | * {@inheritDoc} |
||
| 591 | * @see JobInterface::setHistory() |
||
| 592 | * @return Job |
||
| 593 | */ |
||
| 594 | public function setHistory(Collection $history) |
||
| 599 | |||
| 600 | /** |
||
| 601 | * {@inheritDoc} |
||
| 602 | * @see JobInterface::getHistory() |
||
| 603 | */ |
||
| 604 | public function getHistory() |
||
| 611 | |||
| 612 | /** |
||
| 613 | * {@inheritDoc} |
||
| 614 | * @see JobInterface::setTermsAccepted() |
||
| 615 | * @return self |
||
| 616 | */ |
||
| 617 | public function setTermsAccepted($termsAccepted) |
||
| 622 | |||
| 623 | /** |
||
| 624 | * {qinheritDoc} |
||
| 625 | * @see JobInterface::getTermsAccepted() |
||
| 626 | */ |
||
| 627 | public function getTermsAccepted() |
||
| 631 | |||
| 632 | /** |
||
| 633 | * (non-PHPdoc) |
||
| 634 | * @see JobInterface::getReference() |
||
| 635 | */ |
||
| 636 | public function getReference() |
||
| 640 | /** |
||
| 641 | * (non-PHPdoc) |
||
| 642 | * @see JobInterface::setReference() |
||
| 643 | */ |
||
| 644 | public function setReference($reference) |
||
| 649 | |||
| 650 | public function setAtsMode(AtsMode $mode) |
||
| 656 | |||
| 657 | public function getAtsMode() |
||
| 665 | |||
| 666 | |||
| 667 | /** |
||
| 668 | * checks, weather a job is enabled for getting applications |
||
| 669 | * @return boolean |
||
| 670 | */ |
||
| 671 | public function getAtsEnabled() |
||
| 675 | /** |
||
| 676 | * enables a job add to receive applications |
||
| 677 | * |
||
| 678 | * @param boolean $atsEnabled |
||
| 679 | * @return \Jobs\Entity\Job |
||
| 680 | */ |
||
| 681 | public function setAtsEnabled($atsEnabled) |
||
| 686 | /** |
||
| 687 | * returns an uri to the organization logo |
||
| 688 | * |
||
| 689 | * @deprecated |
||
| 690 | * @return string |
||
| 691 | */ |
||
| 692 | public function getLogoRef() |
||
| 702 | /** |
||
| 703 | * Set the uri to the organisations logo |
||
| 704 | * |
||
| 705 | * @deprecated |
||
| 706 | * @param string $logoRef |
||
| 707 | * @return \Jobs\Entity\Job |
||
| 708 | */ |
||
| 709 | public function setLogoRef($logoRef) |
||
| 714 | |||
| 715 | /** |
||
| 716 | * |
||
| 717 | * |
||
| 718 | * @return string |
||
| 719 | */ |
||
| 720 | public function getTemplate() |
||
| 728 | /** |
||
| 729 | * |
||
| 730 | * |
||
| 731 | * @param string $template name of the Template |
||
| 732 | * @return \Jobs\Entity\Job |
||
| 733 | */ |
||
| 734 | public function setTemplate($template) |
||
| 739 | |||
| 740 | |||
| 741 | |||
| 742 | /** |
||
| 743 | * Gets the uri of an application link |
||
| 744 | * |
||
| 745 | * @return String |
||
| 746 | */ |
||
| 747 | public function getUriApply() |
||
| 751 | |||
| 752 | /** |
||
| 753 | * Sets the uri of an application link |
||
| 754 | * |
||
| 755 | * @param String $uriApply |
||
| 756 | * @return \Jobs\Entity\Job |
||
| 757 | */ |
||
| 758 | public function setUriApply($uriApply) |
||
| 763 | |||
| 764 | /** |
||
| 765 | * Gets the uri of a publisher |
||
| 766 | * |
||
| 767 | * @return String |
||
| 768 | */ |
||
| 769 | public function getUriPublisher() |
||
| 773 | /** |
||
| 774 | * |
||
| 775 | * @param String $uriPublisher |
||
| 776 | * @return \Jobs\Entity\Job |
||
| 777 | */ |
||
| 778 | public function setUriPublisher($uriPublisher) |
||
| 783 | |||
| 784 | /** |
||
| 785 | * @param $key |
||
| 786 | * @return mixed |
||
| 787 | */ |
||
| 788 | public function getPublisher($key) |
||
| 803 | |||
| 804 | public function setPublisherReference($key, $reference) |
||
| 810 | |||
| 811 | /** |
||
| 812 | * Get a list of fieldnames, which can be searched by keywords |
||
| 813 | * |
||
| 814 | * @return array |
||
| 815 | */ |
||
| 816 | public function getSearchableProperties() |
||
| 820 | |||
| 821 | /** |
||
| 822 | * (non-PHPdoc) |
||
| 823 | * @see \Core\Entity\PermissionsAwareInterface::getPermissions() |
||
| 824 | */ |
||
| 825 | public function getPermissions() |
||
| 837 | |||
| 838 | /** |
||
| 839 | * (non-PHPdoc) |
||
| 840 | * @see \Core\Entity\PermissionsAwareInterface::setPermissions() |
||
| 841 | */ |
||
| 842 | public function setPermissions(PermissionsInterface $permissions) |
||
| 847 | |||
| 848 | /** |
||
| 849 | * Gets the Values of a job template |
||
| 850 | * |
||
| 851 | * @return TemplateValues |
||
| 852 | */ |
||
| 853 | public function getTemplateValues() |
||
| 860 | |||
| 861 | /** |
||
| 862 | * {@inheritdoc} |
||
| 863 | */ |
||
| 864 | public function setTemplateValues(EntityInterface $templateValues = null) |
||
| 872 | |||
| 873 | /** |
||
| 874 | * Sets the list of channels where a job opening should be published |
||
| 875 | * |
||
| 876 | * @param Array |
||
| 877 | * {@inheritdoc} |
||
| 878 | */ |
||
| 879 | public function setPortals(array $portals) |
||
| 884 | |||
| 885 | /** |
||
| 886 | * Gets the list of channels where the job opening should be published |
||
| 887 | * |
||
| 888 | * {@inheritdoc} |
||
| 889 | * @return Array |
||
| 890 | */ |
||
| 891 | public function getPortals() |
||
| 895 | |||
| 896 | /** |
||
| 897 | * Gets the flag indicating the draft state. |
||
| 898 | * |
||
| 899 | * @return bool |
||
| 900 | */ |
||
| 901 | public function isDraft() |
||
| 905 | |||
| 906 | /** |
||
| 907 | * Sets the flag indicating the draft state. |
||
| 908 | * |
||
| 909 | * @param boolean $flag |
||
| 910 | * @return DraftableEntityInterface |
||
| 911 | */ |
||
| 912 | public function setIsDraft($flag) |
||
| 917 | |||
| 918 | /** |
||
| 919 | * Gets the status and checks it against 'active' |
||
| 920 | * |
||
| 921 | * @return bool |
||
| 922 | */ |
||
| 923 | public function isActive() |
||
| 927 | |||
| 928 | /** |
||
| 929 | * @return Job |
||
| 930 | */ |
||
| 931 | public function makeSnapshot() |
||
| 936 | |||
| 937 | /** |
||
| 938 | * @return array|mixed |
||
| 939 | */ |
||
| 940 | public function getSnapshotGenerator() |
||
| 949 | } |
||
| 950 |