Complex classes like JobSnapshot 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 JobSnapshot, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 33 | class JobSnapshot extends BaseEntity implements JobInterface, SnapshotInterface |
||
| 34 | { |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var String |
||
| 38 | */ |
||
| 39 | protected $jobId; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * unique ID of a job posting used by applications to reference |
||
| 43 | * a job |
||
| 44 | * |
||
| 45 | * @var String |
||
| 46 | * @ODM\String @ODM\Index |
||
| 47 | **/ |
||
| 48 | protected $applyId; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * title of a job posting |
||
| 52 | * |
||
| 53 | * @var String |
||
| 54 | * @ODM\String |
||
| 55 | */ |
||
| 56 | protected $title; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * name of the publishing company |
||
| 60 | * |
||
| 61 | * @var String |
||
| 62 | * @ODM\String |
||
| 63 | */ |
||
| 64 | protected $company; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * publishing company |
||
| 68 | * |
||
| 69 | * @var OrganizationInterface |
||
| 70 | * @ODM\ReferenceOne (targetDocument="\Organizations\Entity\Organization", simple=true, inversedBy="jobs") |
||
| 71 | * @ODM\Index |
||
| 72 | */ |
||
| 73 | protected $organization; |
||
| 74 | |||
| 75 | |||
| 76 | /** |
||
| 77 | * Email Address, which is used to send notifications about e.g. new applications. |
||
| 78 | * |
||
| 79 | * @var String |
||
| 80 | * @ODM\String |
||
| 81 | **/ |
||
| 82 | protected $contactEmail; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * the owner of a Job Posting |
||
| 86 | * |
||
| 87 | * @var UserInterface $user |
||
| 88 | * @ODM\ReferenceOne(targetDocument="\Auth\Entity\User", simple=true) |
||
| 89 | * @ODM\Index |
||
| 90 | */ |
||
| 91 | protected $user; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * all applications of a certain jobad |
||
| 95 | * |
||
| 96 | * @var Collection |
||
| 97 | * @ODM\ReferenceMany(targetDocument="Applications\Entity\Application", simple=true, mappedBy="job", |
||
| 98 | * repositoryMethod="loadApplicationsForJob") |
||
| 99 | */ |
||
| 100 | protected $applications; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * new applications |
||
| 104 | * |
||
| 105 | * @ODM\ReferenceMany(targetDocument="Applications\Entity\Application", |
||
| 106 | * repositoryMethod="loadUnreadApplicationsForJob", mappedBy="job") |
||
| 107 | * @var Int |
||
| 108 | */ |
||
| 109 | protected $unreadApplications; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * language of the job posting. Languages are ISO 639-1 coded |
||
| 113 | * |
||
| 114 | * @var String |
||
| 115 | * @ODM\String |
||
| 116 | */ |
||
| 117 | protected $language; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * location of the job posting. This is a plain text, which describes the location in |
||
| 121 | * search e.g. results. |
||
| 122 | * |
||
| 123 | * @var String |
||
| 124 | * @ODM\String |
||
| 125 | */ |
||
| 126 | protected $location; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * locations of the job posting. This collection contains structured coordinates, |
||
| 130 | * postal codes, city, region, and country names |
||
| 131 | * |
||
| 132 | * @var Collection |
||
| 133 | * @ODM\EmbedMany(targetDocument="Location") |
||
| 134 | */ |
||
| 135 | protected $locations; |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Link which points to the job posting |
||
| 139 | * |
||
| 140 | * @var String |
||
| 141 | * @ODM\String |
||
| 142 | **/ |
||
| 143 | protected $link; |
||
| 144 | |||
| 145 | /** |
||
| 146 | * publishing date of a job posting |
||
| 147 | * |
||
| 148 | * @var String |
||
| 149 | * @ODM\Field(type="tz_date") |
||
| 150 | */ |
||
| 151 | protected $datePublishStart; |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Status of the job posting |
||
| 155 | * |
||
| 156 | * @var Status |
||
| 157 | * @ODM\EmbedOne(targetDocument="Status") |
||
| 158 | * @ODM\Index |
||
| 159 | */ |
||
| 160 | protected $status; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * History on an job posting |
||
| 164 | * |
||
| 165 | * @var Collection |
||
| 166 | * @ODM\EmbedMany(targetDocument="History") |
||
| 167 | */ |
||
| 168 | protected $history; |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Flag, privacy policy is accepted or not. |
||
| 172 | * |
||
| 173 | * @var bool |
||
| 174 | * @ODM\Boolean |
||
| 175 | */ |
||
| 176 | protected $termsAccepted; |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Reference of a job opening, on which an applicant can refer to. |
||
| 180 | * |
||
| 181 | * @var String |
||
| 182 | * @ODM\String |
||
| 183 | */ |
||
| 184 | protected $reference; |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Unified Resource Locator to the company-Logo |
||
| 188 | * |
||
| 189 | * @deprecated (use $organization->image->uri instead) |
||
| 190 | * @var String |
||
| 191 | * @ODM\String |
||
| 192 | */ |
||
| 193 | protected $logoRef; |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Template-Name |
||
| 197 | * |
||
| 198 | * @var String |
||
| 199 | * @ODM\String |
||
| 200 | */ |
||
| 201 | protected $template; |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Application link. |
||
| 205 | * |
||
| 206 | * @var String |
||
| 207 | * @ODM\String |
||
| 208 | */ |
||
| 209 | protected $uriApply; |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Unified Resource Locator the Yawik, which handled this job first - so |
||
| 213 | * does know who is the one who has commited this job. |
||
| 214 | * |
||
| 215 | * @var String |
||
| 216 | * @ODM\String |
||
| 217 | */ |
||
| 218 | protected $uriPublisher; |
||
| 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 | * |
||
| 248 | * @var TemplateValues |
||
| 249 | * @ODM\EmbedOne(targetDocument="\Jobs\Entity\TemplateValues") |
||
| 250 | */ |
||
| 251 | protected $templateValues; |
||
| 252 | |||
| 253 | |||
| 254 | /** |
||
| 255 | * Can contain various Portals |
||
| 256 | * |
||
| 257 | * @var array |
||
| 258 | * @ODM\Collection*/ |
||
| 259 | protected $portals = array(); |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Flag indicating draft state of this job. |
||
| 263 | * |
||
| 264 | * @var bool |
||
| 265 | * @ODM\Boolean |
||
| 266 | */ |
||
| 267 | protected $isDraft = false; |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @param $jobEntity |
||
| 271 | */ |
||
| 272 | public function __construct() |
||
| 275 | |||
| 276 | /** |
||
| 277 | * transfer all attributes from the job-entity to the snapshot-entity |
||
| 278 | * |
||
| 279 | * @TODO this could go into an abstract class since it is nearly allways the same |
||
| 280 | * |
||
| 281 | * @param $source |
||
| 282 | * @param $target |
||
| 283 | * @return $this |
||
| 284 | */ |
||
| 285 | protected function copyAttributes($source, $target) |
||
| 312 | |||
| 313 | |||
| 314 | |||
| 315 | /** |
||
| 316 | * Gets the unique key used by applications to reference a job posting |
||
| 317 | * |
||
| 318 | * @param string $applyId |
||
| 319 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 320 | */ |
||
| 321 | public function setApplyId($applyId) |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Sets a unique key used by applications to reference a job posting |
||
| 328 | * |
||
| 329 | * @return string |
||
| 330 | */ |
||
| 331 | public function getApplyId() |
||
| 335 | |||
| 336 | /** |
||
| 337 | * checks, weather a job is enabled for getting applications |
||
| 338 | * @deprecated since 0.19 - Use atsMode sub document via getAtsMode() |
||
| 339 | * @return boolean |
||
| 340 | */ |
||
| 341 | public function getAtsEnabled() |
||
| 345 | |||
| 346 | /** |
||
| 347 | * enables a job add to receive applications |
||
| 348 | * |
||
| 349 | * @param boolean $atsEnabled |
||
| 350 | * @deprecated since 0.19 - Use atsMode entity via setAtsMode() |
||
| 351 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 352 | * @return \Jobs\Entity\Job |
||
| 353 | */ |
||
| 354 | public function setAtsEnabled($atsEnabled) |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Sets the ATS mode. |
||
| 361 | * |
||
| 362 | * @param AtsMode $mode |
||
| 363 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 364 | * |
||
| 365 | * @return self |
||
| 366 | * @since 0.19 |
||
| 367 | */ |
||
| 368 | public function setAtsMode(AtsMode $mode) |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Gets the ATS mode. |
||
| 375 | * |
||
| 376 | * @return AtsMode |
||
| 377 | * @since 0.19 |
||
| 378 | */ |
||
| 379 | public function getAtsMode() |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Gets an URI for a job posting |
||
| 386 | * |
||
| 387 | * @return string |
||
| 388 | */ |
||
| 389 | public function getLink() |
||
| 393 | |||
| 394 | /** |
||
| 395 | * Sets an URI for a job posting |
||
| 396 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 397 | * |
||
| 398 | * @param string $link |
||
| 399 | */ |
||
| 400 | public function setLink($link) |
||
| 404 | |||
| 405 | /** |
||
| 406 | * Gets the publishing date of a job posting |
||
| 407 | * |
||
| 408 | * @return string |
||
| 409 | */ |
||
| 410 | public function getDatePublishStart() |
||
| 414 | |||
| 415 | /** |
||
| 416 | * Sets the publishing date of a job posting |
||
| 417 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 418 | * |
||
| 419 | * @param $datePublishStart |
||
| 420 | * @return string |
||
| 421 | */ |
||
| 422 | public function setDatePublishStart($datePublishStart) |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Gets the title of a job posting |
||
| 429 | * |
||
| 430 | * @return string $title |
||
| 431 | */ |
||
| 432 | public function getTitle() |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Sets the title of a job posting |
||
| 439 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 440 | * |
||
| 441 | * @param string $title |
||
| 442 | */ |
||
| 443 | public function setTitle($title) |
||
| 447 | |||
| 448 | /** |
||
| 449 | * Gets the organisation name, which offers the job posting |
||
| 450 | * |
||
| 451 | * @deprecated |
||
| 452 | * @return string |
||
| 453 | */ |
||
| 454 | public function getCompany() |
||
| 458 | |||
| 459 | /** |
||
| 460 | * Sets the organisation name, which offers a job posting |
||
| 461 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 462 | * |
||
| 463 | * @deprecated |
||
| 464 | * @param string $company |
||
| 465 | * @return JobInterface $job |
||
| 466 | */ |
||
| 467 | public function setCompany($company) |
||
| 471 | |||
| 472 | /** |
||
| 473 | * Gets the organisation, which offers the job posting |
||
| 474 | * |
||
| 475 | * @return OrganizationInterface |
||
| 476 | */ |
||
| 477 | public function getOrganization() |
||
| 481 | |||
| 482 | /** |
||
| 483 | * Sets the organization, which offers the job |
||
| 484 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 485 | * |
||
| 486 | * @param OrganizationInterface $organization |
||
|
|
|||
| 487 | * @return JobInterface |
||
| 488 | */ |
||
| 489 | public function setOrganization(OrganizationInterface $organization = null) |
||
| 493 | |||
| 494 | /** |
||
| 495 | * Sets the contact email of a job posting |
||
| 496 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 497 | * |
||
| 498 | * @param string $email |
||
| 499 | * @return JobInterface $job |
||
| 500 | */ |
||
| 501 | public function setContactEmail($email) |
||
| 505 | |||
| 506 | /** |
||
| 507 | * Gets the contact email a job posting |
||
| 508 | * |
||
| 509 | * @return string |
||
| 510 | */ |
||
| 511 | public function getContactEmail() |
||
| 515 | |||
| 516 | /** |
||
| 517 | * Sets the user, who owns a job posting |
||
| 518 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 519 | * |
||
| 520 | * @param UserInterface $user |
||
| 521 | * @return JobInterface $job |
||
| 522 | */ |
||
| 523 | public function setUser(UserInterface $user) |
||
| 527 | |||
| 528 | /** |
||
| 529 | * Gets the user, who owns a job posting |
||
| 530 | * |
||
| 531 | * @return UserInterface $user |
||
| 532 | */ |
||
| 533 | public function getUser() |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Gets the link to the application form |
||
| 540 | * |
||
| 541 | * @return String |
||
| 542 | */ |
||
| 543 | public function getUriApply() |
||
| 547 | |||
| 548 | /** |
||
| 549 | * Sets the Link to the application form |
||
| 550 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 551 | * |
||
| 552 | * @param String $uriApply |
||
| 553 | * @return \Jobs\Entity\Job |
||
| 554 | */ |
||
| 555 | public function setUriApply($uriApply) |
||
| 559 | |||
| 560 | /** |
||
| 561 | * Gets the URI of the publisher |
||
| 562 | * |
||
| 563 | * @return String |
||
| 564 | */ |
||
| 565 | public function getUriPublisher() |
||
| 569 | |||
| 570 | /** |
||
| 571 | * Sets the URI of the publisher |
||
| 572 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 573 | * |
||
| 574 | * @param String $uriPublisher |
||
| 575 | * @return \Jobs\Entity\Job |
||
| 576 | */ |
||
| 577 | public function setUriPublisher($uriPublisher) |
||
| 581 | |||
| 582 | /** |
||
| 583 | * Sets the language of a job posting |
||
| 584 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 585 | * |
||
| 586 | * @param string $language |
||
| 587 | */ |
||
| 588 | public function setLanguage($language) |
||
| 592 | |||
| 593 | /** |
||
| 594 | * Gets the language of a job posting |
||
| 595 | * |
||
| 596 | * @return string |
||
| 597 | */ |
||
| 598 | public function getLanguage() |
||
| 602 | |||
| 603 | /** |
||
| 604 | * Sets the location of a job posting |
||
| 605 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 606 | * |
||
| 607 | * @param string $location |
||
| 608 | */ |
||
| 609 | public function setLocation($location) |
||
| 613 | |||
| 614 | /** |
||
| 615 | * Gets the location of a job posting |
||
| 616 | * |
||
| 617 | * @return string |
||
| 618 | */ |
||
| 619 | public function getLocation() |
||
| 623 | |||
| 624 | /** |
||
| 625 | * Sets locations of a job posting |
||
| 626 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 627 | * |
||
| 628 | * @param string $locations |
||
| 629 | */ |
||
| 630 | public function setLocations($locations) |
||
| 634 | |||
| 635 | /** |
||
| 636 | * Gets locations of a job posting |
||
| 637 | * |
||
| 638 | * @return string |
||
| 639 | */ |
||
| 640 | public function getLocations() |
||
| 644 | |||
| 645 | /** |
||
| 646 | * Sets applications for a job posting |
||
| 647 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 648 | * |
||
| 649 | * @param Collection $applications |
||
| 650 | */ |
||
| 651 | public function setApplications(Collection $applications) |
||
| 655 | |||
| 656 | /** |
||
| 657 | * Gets applications for a job posting |
||
| 658 | * |
||
| 659 | * @return Collection $applications |
||
| 660 | */ |
||
| 661 | public function getApplications() |
||
| 665 | |||
| 666 | /** |
||
| 667 | * Sets Status of a job posting |
||
| 668 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 669 | * |
||
| 670 | * @param string $status |
||
| 671 | */ |
||
| 672 | public function setStatus($status) |
||
| 676 | |||
| 677 | /** |
||
| 678 | * Gets applications for a job posting |
||
| 679 | * |
||
| 680 | * @return string |
||
| 681 | */ |
||
| 682 | public function getStatus() |
||
| 686 | |||
| 687 | /** |
||
| 688 | * Sets the collection of history entities. |
||
| 689 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 690 | * |
||
| 691 | * @param Collection $history |
||
| 692 | * @return JobInterface |
||
| 693 | */ |
||
| 694 | public function setHistory(Collection $history) |
||
| 698 | |||
| 699 | /** |
||
| 700 | * Gets the collection of history entities. |
||
| 701 | * |
||
| 702 | * @return Collection |
||
| 703 | */ |
||
| 704 | public function getHistory() |
||
| 708 | |||
| 709 | /** |
||
| 710 | * Sets the terms and conditions accepted flag. |
||
| 711 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 712 | * |
||
| 713 | * @param bool $flag |
||
| 714 | * @return self |
||
| 715 | */ |
||
| 716 | public function setTermsAccepted($flag) |
||
| 720 | |||
| 721 | /** |
||
| 722 | * Gets the terms and conditions accepted flag. |
||
| 723 | * |
||
| 724 | * @return bool |
||
| 725 | */ |
||
| 726 | public function getTermsAccepted() |
||
| 730 | |||
| 731 | /** |
||
| 732 | * Sets a reference for a job posting, used by the |
||
| 733 | * organisation offering the job. |
||
| 734 | * |
||
| 735 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 736 | * @param string $reference |
||
| 737 | */ |
||
| 738 | public function setReference($reference) |
||
| 742 | |||
| 743 | /** |
||
| 744 | * Gets a reference for a job posting, used by the |
||
| 745 | * organisation offering the job. |
||
| 746 | * |
||
| 747 | * @return string $reference |
||
| 748 | */ |
||
| 749 | public function getReference() |
||
| 753 | |||
| 754 | /** |
||
| 755 | * Sets the list of channels where a job opening should be published |
||
| 756 | * |
||
| 757 | * @throws \Core\Exception\ImmutablePropertyException |
||
| 758 | * @param Array $portals |
||
| 759 | */ |
||
| 760 | public function setPortals(array $portals) |
||
| 764 | |||
| 765 | /** |
||
| 766 | * Gets the list of channels where the job opening should be published |
||
| 767 | * |
||
| 768 | * @return Array |
||
| 769 | */ |
||
| 770 | public function getPortals() |
||
| 774 | |||
| 775 | /** |
||
| 776 | * Gets the permissions entity. |
||
| 777 | * |
||
| 778 | * @return PermissionsInterface |
||
| 779 | */ |
||
| 780 | public function getPermissions() |
||
| 784 | |||
| 785 | /** |
||
| 786 | * the permissions must be mutable because of a flaw in the design of an upper class |
||
| 787 | * |
||
| 788 | * @param PermissionsInterface $permissions |
||
| 789 | * @return $this |
||
| 790 | */ |
||
| 791 | public function setPermissions(PermissionsInterface $permissions) |
||
| 796 | |||
| 797 | /** |
||
| 798 | * Gets the Values of a job template |
||
| 799 | * |
||
| 800 | * @return TemplateValues |
||
| 801 | */ |
||
| 802 | public function getTemplateValues() |
||
| 806 | |||
| 807 | /** |
||
| 808 | * @param EntityInterface $templateValues |
||
| 809 | * @return $this |
||
| 810 | */ |
||
| 811 | public function setTemplateValues(EntityInterface $templateValues = null) |
||
| 816 | |||
| 817 | /** |
||
| 818 | * Returns the string identifier of the Resource |
||
| 819 | * |
||
| 820 | * @return null|string |
||
| 821 | */ |
||
| 822 | public function getResourceId() |
||
| 826 | } |
||
| 827 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.