Complex classes like CSurvey 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 CSurvey, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | class CSurvey |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var integer |
||
| 24 | * |
||
| 25 | * @ORM\Column(name="iid", type="integer") |
||
| 26 | * @ORM\Id |
||
| 27 | * @ORM\GeneratedValue |
||
| 28 | */ |
||
| 29 | private $iid; |
||
|
|
|||
| 30 | |||
| 31 | /** |
||
| 32 | * @var integer |
||
| 33 | * |
||
| 34 | * @ORM\Column(name="c_id", type="integer") |
||
| 35 | */ |
||
| 36 | private $cId; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var integer |
||
| 40 | * |
||
| 41 | * @ORM\Column(name="survey_id", type="integer") |
||
| 42 | */ |
||
| 43 | private $surveyId; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var string |
||
| 47 | * |
||
| 48 | * @ORM\Column(name="code", type="string", length=20, nullable=true) |
||
| 49 | */ |
||
| 50 | private $code; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var string |
||
| 54 | * |
||
| 55 | * @ORM\Column(name="title", type="text", nullable=true) |
||
| 56 | */ |
||
| 57 | private $title; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var string |
||
| 61 | * |
||
| 62 | * @ORM\Column(name="subtitle", type="text", nullable=true) |
||
| 63 | */ |
||
| 64 | private $subtitle; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var string |
||
| 68 | * |
||
| 69 | * @ORM\Column(name="author", type="string", length=20, nullable=true) |
||
| 70 | */ |
||
| 71 | private $author; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @var string |
||
| 75 | * |
||
| 76 | * @ORM\Column(name="lang", type="string", length=20, nullable=true) |
||
| 77 | */ |
||
| 78 | private $lang; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @var \DateTime |
||
| 82 | * |
||
| 83 | * @ORM\Column(name="avail_from", type="date", nullable=true) |
||
| 84 | */ |
||
| 85 | private $availFrom; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @var \DateTime |
||
| 89 | * |
||
| 90 | * @ORM\Column(name="avail_till", type="date", nullable=true) |
||
| 91 | */ |
||
| 92 | private $availTill; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var string |
||
| 96 | * |
||
| 97 | * @ORM\Column(name="is_shared", type="string", length=1, nullable=true) |
||
| 98 | */ |
||
| 99 | private $isShared; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @var string |
||
| 103 | * |
||
| 104 | * @ORM\Column(name="template", type="string", length=20, nullable=true) |
||
| 105 | */ |
||
| 106 | private $template; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @var string |
||
| 110 | * |
||
| 111 | * @ORM\Column(name="intro", type="text", nullable=true) |
||
| 112 | */ |
||
| 113 | private $intro; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @var string |
||
| 117 | * |
||
| 118 | * @ORM\Column(name="surveythanks", type="text", nullable=true) |
||
| 119 | */ |
||
| 120 | private $surveythanks; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @var \DateTime |
||
| 124 | * |
||
| 125 | * @ORM\Column(name="creation_date", type="datetime", nullable=false) |
||
| 126 | */ |
||
| 127 | private $creationDate; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @var integer |
||
| 131 | * |
||
| 132 | * @ORM\Column(name="invited", type="integer", nullable=false) |
||
| 133 | */ |
||
| 134 | private $invited; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @var integer |
||
| 138 | * |
||
| 139 | * @ORM\Column(name="answered", type="integer", nullable=false) |
||
| 140 | */ |
||
| 141 | private $answered; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @var string |
||
| 145 | * |
||
| 146 | * @ORM\Column(name="invite_mail", type="text", nullable=false) |
||
| 147 | */ |
||
| 148 | private $inviteMail; |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @var string |
||
| 152 | * |
||
| 153 | * @ORM\Column(name="reminder_mail", type="text", nullable=false) |
||
| 154 | */ |
||
| 155 | private $reminderMail; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @var string |
||
| 159 | * |
||
| 160 | * @ORM\Column(name="mail_subject", type="string", length=255, nullable=false) |
||
| 161 | */ |
||
| 162 | private $mailSubject; |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @var string |
||
| 166 | * |
||
| 167 | * @ORM\Column(name="anonymous", type="string", length=10, nullable=false) |
||
| 168 | */ |
||
| 169 | private $anonymous; |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @var string |
||
| 173 | * |
||
| 174 | * @ORM\Column(name="access_condition", type="text", nullable=true) |
||
| 175 | */ |
||
| 176 | private $accessCondition; |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @var boolean |
||
| 180 | * |
||
| 181 | * @ORM\Column(name="shuffle", type="boolean", nullable=false) |
||
| 182 | */ |
||
| 183 | private $shuffle; |
||
| 184 | |||
| 185 | /** |
||
| 186 | * @var boolean |
||
| 187 | * |
||
| 188 | * @ORM\Column(name="one_question_per_page", type="boolean", nullable=false) |
||
| 189 | */ |
||
| 190 | private $oneQuestionPerPage; |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @var string |
||
| 194 | * |
||
| 195 | * @ORM\Column(name="survey_version", type="string", length=255, nullable=false) |
||
| 196 | */ |
||
| 197 | private $surveyVersion; |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @var integer |
||
| 201 | * |
||
| 202 | * @ORM\Column(name="parent_id", type="integer", nullable=false) |
||
| 203 | */ |
||
| 204 | private $parentId; |
||
| 205 | |||
| 206 | /** |
||
| 207 | * @var integer |
||
| 208 | * |
||
| 209 | * @ORM\Column(name="survey_type", type="integer", nullable=false) |
||
| 210 | */ |
||
| 211 | private $surveyType; |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @var integer |
||
| 215 | * |
||
| 216 | * @ORM\Column(name="show_form_profile", type="integer", nullable=false) |
||
| 217 | */ |
||
| 218 | private $showFormProfile; |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @var string |
||
| 222 | * |
||
| 223 | * @ORM\Column(name="form_fields", type="text", nullable=false) |
||
| 224 | */ |
||
| 225 | private $formFields; |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @var integer |
||
| 229 | * |
||
| 230 | * @ORM\Column(name="session_id", type="integer", nullable=false) |
||
| 231 | */ |
||
| 232 | private $sessionId; |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @var integer |
||
| 236 | * |
||
| 237 | * @ORM\Column(name="visible_results", type="integer", nullable=true) |
||
| 238 | */ |
||
| 239 | private $visibleResults; |
||
| 240 | |||
| 241 | /** |
||
| 242 | * Set code |
||
| 243 | * |
||
| 244 | * @param string $code |
||
| 245 | * @return CSurvey |
||
| 246 | */ |
||
| 247 | public function setCode($code) |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Get code |
||
| 256 | * |
||
| 257 | * @return string |
||
| 258 | */ |
||
| 259 | public function getCode() |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Set title |
||
| 266 | * |
||
| 267 | * @param string $title |
||
| 268 | * @return CSurvey |
||
| 269 | */ |
||
| 270 | public function setTitle($title) |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Get title |
||
| 279 | * |
||
| 280 | * @return string |
||
| 281 | */ |
||
| 282 | public function getTitle() |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Set subtitle |
||
| 289 | * |
||
| 290 | * @param string $subtitle |
||
| 291 | * @return CSurvey |
||
| 292 | */ |
||
| 293 | public function setSubtitle($subtitle) |
||
| 299 | |||
| 300 | /** |
||
| 301 | * Get subtitle |
||
| 302 | * |
||
| 303 | * @return string |
||
| 304 | */ |
||
| 305 | public function getSubtitle() |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Set author |
||
| 312 | * |
||
| 313 | * @param string $author |
||
| 314 | * @return CSurvey |
||
| 315 | */ |
||
| 316 | public function setAuthor($author) |
||
| 322 | |||
| 323 | /** |
||
| 324 | * Get author |
||
| 325 | * |
||
| 326 | * @return string |
||
| 327 | */ |
||
| 328 | public function getAuthor() |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Set lang |
||
| 335 | * |
||
| 336 | * @param string $lang |
||
| 337 | * @return CSurvey |
||
| 338 | */ |
||
| 339 | public function setLang($lang) |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Get lang |
||
| 348 | * |
||
| 349 | * @return string |
||
| 350 | */ |
||
| 351 | public function getLang() |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Set availFrom |
||
| 358 | * |
||
| 359 | * @param \DateTime $availFrom |
||
| 360 | * @return CSurvey |
||
| 361 | */ |
||
| 362 | public function setAvailFrom($availFrom) |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Get availFrom |
||
| 371 | * |
||
| 372 | * @return \DateTime |
||
| 373 | */ |
||
| 374 | public function getAvailFrom() |
||
| 378 | |||
| 379 | /** |
||
| 380 | * Set availTill |
||
| 381 | * |
||
| 382 | * @param \DateTime $availTill |
||
| 383 | * @return CSurvey |
||
| 384 | */ |
||
| 385 | public function setAvailTill($availTill) |
||
| 391 | |||
| 392 | /** |
||
| 393 | * Get availTill |
||
| 394 | * |
||
| 395 | * @return \DateTime |
||
| 396 | */ |
||
| 397 | public function getAvailTill() |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Set isShared |
||
| 404 | * |
||
| 405 | * @param string $isShared |
||
| 406 | * @return CSurvey |
||
| 407 | */ |
||
| 408 | public function setIsShared($isShared) |
||
| 414 | |||
| 415 | /** |
||
| 416 | * Get isShared |
||
| 417 | * |
||
| 418 | * @return string |
||
| 419 | */ |
||
| 420 | public function getIsShared() |
||
| 424 | |||
| 425 | /** |
||
| 426 | * Set template |
||
| 427 | * |
||
| 428 | * @param string $template |
||
| 429 | * @return CSurvey |
||
| 430 | */ |
||
| 431 | public function setTemplate($template) |
||
| 437 | |||
| 438 | /** |
||
| 439 | * Get template |
||
| 440 | * |
||
| 441 | * @return string |
||
| 442 | */ |
||
| 443 | public function getTemplate() |
||
| 447 | |||
| 448 | /** |
||
| 449 | * Set intro |
||
| 450 | * |
||
| 451 | * @param string $intro |
||
| 452 | * @return CSurvey |
||
| 453 | */ |
||
| 454 | public function setIntro($intro) |
||
| 460 | |||
| 461 | /** |
||
| 462 | * Get intro |
||
| 463 | * |
||
| 464 | * @return string |
||
| 465 | */ |
||
| 466 | public function getIntro() |
||
| 470 | |||
| 471 | /** |
||
| 472 | * Set surveythanks |
||
| 473 | * |
||
| 474 | * @param string $surveythanks |
||
| 475 | * @return CSurvey |
||
| 476 | */ |
||
| 477 | public function setSurveythanks($surveythanks) |
||
| 483 | |||
| 484 | /** |
||
| 485 | * Get surveythanks |
||
| 486 | * |
||
| 487 | * @return string |
||
| 488 | */ |
||
| 489 | public function getSurveythanks() |
||
| 493 | |||
| 494 | /** |
||
| 495 | * Set creationDate |
||
| 496 | * |
||
| 497 | * @param \DateTime $creationDate |
||
| 498 | * @return CSurvey |
||
| 499 | */ |
||
| 500 | public function setCreationDate($creationDate) |
||
| 506 | |||
| 507 | /** |
||
| 508 | * Get creationDate |
||
| 509 | * |
||
| 510 | * @return \DateTime |
||
| 511 | */ |
||
| 512 | public function getCreationDate() |
||
| 516 | |||
| 517 | /** |
||
| 518 | * Set invited |
||
| 519 | * |
||
| 520 | * @param integer $invited |
||
| 521 | * @return CSurvey |
||
| 522 | */ |
||
| 523 | public function setInvited($invited) |
||
| 529 | |||
| 530 | /** |
||
| 531 | * Get invited |
||
| 532 | * |
||
| 533 | * @return integer |
||
| 534 | */ |
||
| 535 | public function getInvited() |
||
| 539 | |||
| 540 | /** |
||
| 541 | * Set answered |
||
| 542 | * |
||
| 543 | * @param integer $answered |
||
| 544 | * @return CSurvey |
||
| 545 | */ |
||
| 546 | public function setAnswered($answered) |
||
| 552 | |||
| 553 | /** |
||
| 554 | * Get answered |
||
| 555 | * |
||
| 556 | * @return integer |
||
| 557 | */ |
||
| 558 | public function getAnswered() |
||
| 562 | |||
| 563 | /** |
||
| 564 | * Set inviteMail |
||
| 565 | * |
||
| 566 | * @param string $inviteMail |
||
| 567 | * @return CSurvey |
||
| 568 | */ |
||
| 569 | public function setInviteMail($inviteMail) |
||
| 575 | |||
| 576 | /** |
||
| 577 | * Get inviteMail |
||
| 578 | * |
||
| 579 | * @return string |
||
| 580 | */ |
||
| 581 | public function getInviteMail() |
||
| 585 | |||
| 586 | /** |
||
| 587 | * Set reminderMail |
||
| 588 | * |
||
| 589 | * @param string $reminderMail |
||
| 590 | * @return CSurvey |
||
| 591 | */ |
||
| 592 | public function setReminderMail($reminderMail) |
||
| 598 | |||
| 599 | /** |
||
| 600 | * Get reminderMail |
||
| 601 | * |
||
| 602 | * @return string |
||
| 603 | */ |
||
| 604 | public function getReminderMail() |
||
| 608 | |||
| 609 | /** |
||
| 610 | * Set mailSubject |
||
| 611 | * |
||
| 612 | * @param string $mailSubject |
||
| 613 | * @return CSurvey |
||
| 614 | */ |
||
| 615 | public function setMailSubject($mailSubject) |
||
| 621 | |||
| 622 | /** |
||
| 623 | * Get mailSubject |
||
| 624 | * |
||
| 625 | * @return string |
||
| 626 | */ |
||
| 627 | public function getMailSubject() |
||
| 631 | |||
| 632 | /** |
||
| 633 | * Set anonymous |
||
| 634 | * |
||
| 635 | * @param string $anonymous |
||
| 636 | * @return CSurvey |
||
| 637 | */ |
||
| 638 | public function setAnonymous($anonymous) |
||
| 644 | |||
| 645 | /** |
||
| 646 | * Get anonymous |
||
| 647 | * |
||
| 648 | * @return string |
||
| 649 | */ |
||
| 650 | public function getAnonymous() |
||
| 654 | |||
| 655 | /** |
||
| 656 | * Set accessCondition |
||
| 657 | * |
||
| 658 | * @param string $accessCondition |
||
| 659 | * @return CSurvey |
||
| 660 | */ |
||
| 661 | public function setAccessCondition($accessCondition) |
||
| 667 | |||
| 668 | /** |
||
| 669 | * Get accessCondition |
||
| 670 | * |
||
| 671 | * @return string |
||
| 672 | */ |
||
| 673 | public function getAccessCondition() |
||
| 677 | |||
| 678 | /** |
||
| 679 | * Set shuffle |
||
| 680 | * |
||
| 681 | * @param boolean $shuffle |
||
| 682 | * @return CSurvey |
||
| 683 | */ |
||
| 684 | public function setShuffle($shuffle) |
||
| 690 | |||
| 691 | /** |
||
| 692 | * Get shuffle |
||
| 693 | * |
||
| 694 | * @return boolean |
||
| 695 | */ |
||
| 696 | public function getShuffle() |
||
| 700 | |||
| 701 | /** |
||
| 702 | * Set oneQuestionPerPage |
||
| 703 | * |
||
| 704 | * @param boolean $oneQuestionPerPage |
||
| 705 | * @return CSurvey |
||
| 706 | */ |
||
| 707 | public function setOneQuestionPerPage($oneQuestionPerPage) |
||
| 713 | |||
| 714 | /** |
||
| 715 | * Get oneQuestionPerPage |
||
| 716 | * |
||
| 717 | * @return boolean |
||
| 718 | */ |
||
| 719 | public function getOneQuestionPerPage() |
||
| 723 | |||
| 724 | /** |
||
| 725 | * Set surveyVersion |
||
| 726 | * |
||
| 727 | * @param string $surveyVersion |
||
| 728 | * @return CSurvey |
||
| 729 | */ |
||
| 730 | public function setSurveyVersion($surveyVersion) |
||
| 736 | |||
| 737 | /** |
||
| 738 | * Get surveyVersion |
||
| 739 | * |
||
| 740 | * @return string |
||
| 741 | */ |
||
| 742 | public function getSurveyVersion() |
||
| 746 | |||
| 747 | /** |
||
| 748 | * Set parentId |
||
| 749 | * |
||
| 750 | * @param integer $parentId |
||
| 751 | * @return CSurvey |
||
| 752 | */ |
||
| 753 | public function setParentId($parentId) |
||
| 759 | |||
| 760 | /** |
||
| 761 | * Get parentId |
||
| 762 | * |
||
| 763 | * @return integer |
||
| 764 | */ |
||
| 765 | public function getParentId() |
||
| 769 | |||
| 770 | /** |
||
| 771 | * Set surveyType |
||
| 772 | * |
||
| 773 | * @param integer $surveyType |
||
| 774 | * @return CSurvey |
||
| 775 | */ |
||
| 776 | public function setSurveyType($surveyType) |
||
| 782 | |||
| 783 | /** |
||
| 784 | * Get surveyType |
||
| 785 | * |
||
| 786 | * @return integer |
||
| 787 | */ |
||
| 788 | public function getSurveyType() |
||
| 792 | |||
| 793 | /** |
||
| 794 | * Set showFormProfile |
||
| 795 | * |
||
| 796 | * @param integer $showFormProfile |
||
| 797 | * @return CSurvey |
||
| 798 | */ |
||
| 799 | public function setShowFormProfile($showFormProfile) |
||
| 805 | |||
| 806 | /** |
||
| 807 | * Get showFormProfile |
||
| 808 | * |
||
| 809 | * @return integer |
||
| 810 | */ |
||
| 811 | public function getShowFormProfile() |
||
| 815 | |||
| 816 | /** |
||
| 817 | * Set formFields |
||
| 818 | * |
||
| 819 | * @param string $formFields |
||
| 820 | * @return CSurvey |
||
| 821 | */ |
||
| 822 | public function setFormFields($formFields) |
||
| 828 | |||
| 829 | /** |
||
| 830 | * Get formFields |
||
| 831 | * |
||
| 832 | * @return string |
||
| 833 | */ |
||
| 834 | public function getFormFields() |
||
| 838 | |||
| 839 | /** |
||
| 840 | * Set sessionId |
||
| 841 | * |
||
| 842 | * @param integer $sessionId |
||
| 843 | * @return CSurvey |
||
| 844 | */ |
||
| 845 | public function setSessionId($sessionId) |
||
| 851 | |||
| 852 | /** |
||
| 853 | * Get sessionId |
||
| 854 | * |
||
| 855 | * @return integer |
||
| 856 | */ |
||
| 857 | public function getSessionId() |
||
| 861 | |||
| 862 | /** |
||
| 863 | * Set visibleResults |
||
| 864 | * |
||
| 865 | * @param integer $visibleResults |
||
| 866 | * @return CSurvey |
||
| 867 | */ |
||
| 868 | public function setVisibleResults($visibleResults) |
||
| 874 | |||
| 875 | /** |
||
| 876 | * Get visibleResults |
||
| 877 | * |
||
| 878 | * @return integer |
||
| 879 | */ |
||
| 880 | public function getVisibleResults() |
||
| 884 | |||
| 885 | /** |
||
| 886 | * Set surveyId |
||
| 887 | * |
||
| 888 | * @param integer $surveyId |
||
| 889 | * @return CSurvey |
||
| 890 | */ |
||
| 891 | public function setSurveyId($surveyId) |
||
| 897 | |||
| 898 | /** |
||
| 899 | * Get surveyId |
||
| 900 | * |
||
| 901 | * @return integer |
||
| 902 | */ |
||
| 903 | public function getSurveyId() |
||
| 907 | |||
| 908 | /** |
||
| 909 | * Set cId |
||
| 910 | * |
||
| 911 | * @param integer $cId |
||
| 912 | * @return CSurvey |
||
| 913 | */ |
||
| 914 | public function setCId($cId) |
||
| 920 | |||
| 921 | /** |
||
| 922 | * Get cId |
||
| 923 | * |
||
| 924 | * @return integer |
||
| 925 | */ |
||
| 926 | public function getCId() |
||
| 930 | } |
||
| 931 |
This check marks private properties in classes that are never used. Those properties can be removed.