Complex classes like CQuiz 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 CQuiz, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | class CQuiz |
||
| 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="id", type="integer", nullable=true) |
||
| 42 | */ |
||
| 43 | private $id; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var string |
||
| 47 | * |
||
| 48 | * @ORM\Column(name="title", type="string", length=255, nullable=false) |
||
| 49 | */ |
||
| 50 | private $title; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var string |
||
| 54 | * |
||
| 55 | * @ORM\Column(name="description", type="text", nullable=true) |
||
| 56 | */ |
||
| 57 | private $description; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var string |
||
| 61 | * |
||
| 62 | * @ORM\Column(name="sound", type="string", length=255, nullable=true) |
||
| 63 | */ |
||
| 64 | private $sound; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var boolean |
||
| 68 | * |
||
| 69 | * @ORM\Column(name="type", type="boolean", nullable=false) |
||
| 70 | */ |
||
| 71 | private $type; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @var integer |
||
| 75 | * |
||
| 76 | * @ORM\Column(name="random", type="integer", nullable=false) |
||
| 77 | */ |
||
| 78 | private $random; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @var boolean |
||
| 82 | * |
||
| 83 | * @ORM\Column(name="random_answers", type="boolean", nullable=false) |
||
| 84 | */ |
||
| 85 | private $randomAnswers; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @var boolean |
||
| 89 | * |
||
| 90 | * @ORM\Column(name="active", type="boolean", nullable=false) |
||
| 91 | */ |
||
| 92 | private $active; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var integer |
||
| 96 | * |
||
| 97 | * @ORM\Column(name="results_disabled", type="integer", nullable=false) |
||
| 98 | */ |
||
| 99 | private $resultsDisabled; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @var string |
||
| 103 | * |
||
| 104 | * @ORM\Column(name="access_condition", type="text", nullable=true) |
||
| 105 | */ |
||
| 106 | private $accessCondition; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @var integer |
||
| 110 | * |
||
| 111 | * @ORM\Column(name="max_attempt", type="integer", nullable=false) |
||
| 112 | */ |
||
| 113 | private $maxAttempt; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @var \DateTime |
||
| 117 | * |
||
| 118 | * @ORM\Column(name="start_time", type="datetime", nullable=true) |
||
| 119 | */ |
||
| 120 | private $startTime; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @var \DateTime |
||
| 124 | * |
||
| 125 | * @ORM\Column(name="end_time", type="datetime", nullable=true) |
||
| 126 | */ |
||
| 127 | private $endTime; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @var integer |
||
| 131 | * |
||
| 132 | * @ORM\Column(name="feedback_type", type="integer", nullable=false) |
||
| 133 | */ |
||
| 134 | private $feedbackType; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @var integer |
||
| 138 | * |
||
| 139 | * @ORM\Column(name="expired_time", type="integer", nullable=false) |
||
| 140 | */ |
||
| 141 | private $expiredTime; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @var integer |
||
| 145 | * |
||
| 146 | * @ORM\Column(name="session_id", type="integer", nullable=true) |
||
| 147 | */ |
||
| 148 | private $sessionId; |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @var integer |
||
| 152 | * |
||
| 153 | * @ORM\Column(name="propagate_neg", type="integer", nullable=false) |
||
| 154 | */ |
||
| 155 | private $propagateNeg; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @var boolean |
||
| 159 | * @ORm\Column(name="save_correct_answers", type="boolean", nullable=false) |
||
| 160 | */ |
||
| 161 | private $saveCorrectAnswers; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @var integer |
||
| 165 | * |
||
| 166 | * @ORM\Column(name="review_answers", type="integer", nullable=false) |
||
| 167 | */ |
||
| 168 | private $reviewAnswers; |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @var integer |
||
| 172 | * |
||
| 173 | * @ORM\Column(name="random_by_category", type="integer", nullable=false) |
||
| 174 | */ |
||
| 175 | private $randomByCategory; |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @var string |
||
| 179 | * |
||
| 180 | * @ORM\Column(name="text_when_finished", type="text", nullable=true) |
||
| 181 | */ |
||
| 182 | private $textWhenFinished; |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @var integer |
||
| 186 | * |
||
| 187 | * @ORM\Column(name="display_category_name", type="integer", nullable=false) |
||
| 188 | */ |
||
| 189 | private $displayCategoryName; |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @var integer |
||
| 193 | * |
||
| 194 | * @ORM\Column(name="pass_percentage", type="integer", nullable=true) |
||
| 195 | */ |
||
| 196 | private $passPercentage; |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @var integer |
||
| 200 | * |
||
| 201 | * @ORM\Column(name="question_selection_type", type="integer", nullable=true) |
||
| 202 | */ |
||
| 203 | private $questionSelectionType; |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @var boolean |
||
| 207 | * |
||
| 208 | * @ORM\Column(name="hide_question_title", type="boolean", nullable=true) |
||
| 209 | */ |
||
| 210 | private $hideQuestionTitle; |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @var boolean |
||
| 214 | * |
||
| 215 | * @ORM\Column(name="show_previous_button", type="boolean", nullable=true, options={"default":1}) |
||
| 216 | */ |
||
| 217 | private $showPreviousButton; |
||
| 218 | |||
| 219 | /** |
||
| 220 | * @var string |
||
| 221 | * |
||
| 222 | * @ORM\Column(name="notifications", type="string", length=255, nullable=true) |
||
| 223 | */ |
||
| 224 | private $notifications; |
||
| 225 | |||
| 226 | /** |
||
| 227 | * CQuiz constructor. |
||
| 228 | */ |
||
| 229 | public function __construct() |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Set title |
||
| 238 | * |
||
| 239 | * @param string $title |
||
| 240 | * @return CQuiz |
||
| 241 | */ |
||
| 242 | public function setTitle($title) |
||
| 248 | |||
| 249 | /** |
||
| 250 | * Get title |
||
| 251 | * |
||
| 252 | * @return string |
||
| 253 | */ |
||
| 254 | public function getTitle() |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Set description |
||
| 261 | * |
||
| 262 | * @param string $description |
||
| 263 | * @return CQuiz |
||
| 264 | */ |
||
| 265 | public function setDescription($description) |
||
| 271 | |||
| 272 | /** |
||
| 273 | * Get description |
||
| 274 | * |
||
| 275 | * @return string |
||
| 276 | */ |
||
| 277 | public function getDescription() |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Set sound |
||
| 284 | * |
||
| 285 | * @param string $sound |
||
| 286 | * @return CQuiz |
||
| 287 | */ |
||
| 288 | public function setSound($sound) |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Get sound |
||
| 297 | * |
||
| 298 | * @return string |
||
| 299 | */ |
||
| 300 | public function getSound() |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Set type |
||
| 307 | * |
||
| 308 | * @param boolean $type |
||
| 309 | * @return CQuiz |
||
| 310 | */ |
||
| 311 | public function setType($type) |
||
| 317 | |||
| 318 | /** |
||
| 319 | * Get type |
||
| 320 | * |
||
| 321 | * @return boolean |
||
| 322 | */ |
||
| 323 | public function getType() |
||
| 327 | |||
| 328 | /** |
||
| 329 | * Set random |
||
| 330 | * |
||
| 331 | * @param integer $random |
||
| 332 | * @return CQuiz |
||
| 333 | */ |
||
| 334 | public function setRandom($random) |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Get random |
||
| 343 | * |
||
| 344 | * @return integer |
||
| 345 | */ |
||
| 346 | public function getRandom() |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Set randomAnswers |
||
| 353 | * |
||
| 354 | * @param boolean $randomAnswers |
||
| 355 | * @return CQuiz |
||
| 356 | */ |
||
| 357 | public function setRandomAnswers($randomAnswers) |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Get randomAnswers |
||
| 366 | * |
||
| 367 | * @return boolean |
||
| 368 | */ |
||
| 369 | public function getRandomAnswers() |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Set active |
||
| 376 | * |
||
| 377 | * @param boolean $active |
||
| 378 | * @return CQuiz |
||
| 379 | */ |
||
| 380 | public function setActive($active) |
||
| 386 | |||
| 387 | /** |
||
| 388 | * Get active |
||
| 389 | * |
||
| 390 | * @return boolean |
||
| 391 | */ |
||
| 392 | public function getActive() |
||
| 396 | |||
| 397 | /** |
||
| 398 | * Set resultsDisabled |
||
| 399 | * |
||
| 400 | * @param integer $resultsDisabled |
||
| 401 | * @return CQuiz |
||
| 402 | */ |
||
| 403 | public function setResultsDisabled($resultsDisabled) |
||
| 409 | |||
| 410 | /** |
||
| 411 | * Get resultsDisabled |
||
| 412 | * |
||
| 413 | * @return integer |
||
| 414 | */ |
||
| 415 | public function getResultsDisabled() |
||
| 419 | |||
| 420 | /** |
||
| 421 | * Set accessCondition |
||
| 422 | * |
||
| 423 | * @param string $accessCondition |
||
| 424 | * @return CQuiz |
||
| 425 | */ |
||
| 426 | public function setAccessCondition($accessCondition) |
||
| 432 | |||
| 433 | /** |
||
| 434 | * Get accessCondition |
||
| 435 | * |
||
| 436 | * @return string |
||
| 437 | */ |
||
| 438 | public function getAccessCondition() |
||
| 442 | |||
| 443 | /** |
||
| 444 | * Set maxAttempt |
||
| 445 | * |
||
| 446 | * @param integer $maxAttempt |
||
| 447 | * @return CQuiz |
||
| 448 | */ |
||
| 449 | public function setMaxAttempt($maxAttempt) |
||
| 455 | |||
| 456 | /** |
||
| 457 | * Get maxAttempt |
||
| 458 | * |
||
| 459 | * @return integer |
||
| 460 | */ |
||
| 461 | public function getMaxAttempt() |
||
| 465 | |||
| 466 | /** |
||
| 467 | * Set startTime |
||
| 468 | * |
||
| 469 | * @param \DateTime $startTime |
||
| 470 | * @return CQuiz |
||
| 471 | */ |
||
| 472 | public function setStartTime($startTime) |
||
| 478 | |||
| 479 | /** |
||
| 480 | * Get startTime |
||
| 481 | * |
||
| 482 | * @return \DateTime |
||
| 483 | */ |
||
| 484 | public function getStartTime() |
||
| 488 | |||
| 489 | /** |
||
| 490 | * Set endTime |
||
| 491 | * |
||
| 492 | * @param \DateTime $endTime |
||
| 493 | * @return CQuiz |
||
| 494 | */ |
||
| 495 | public function setEndTime($endTime) |
||
| 501 | |||
| 502 | /** |
||
| 503 | * Get endTime |
||
| 504 | * |
||
| 505 | * @return \DateTime |
||
| 506 | */ |
||
| 507 | public function getEndTime() |
||
| 511 | |||
| 512 | /** |
||
| 513 | * Set feedbackType |
||
| 514 | * |
||
| 515 | * @param integer $feedbackType |
||
| 516 | * @return CQuiz |
||
| 517 | */ |
||
| 518 | public function setFeedbackType($feedbackType) |
||
| 524 | |||
| 525 | /** |
||
| 526 | * Get feedbackType |
||
| 527 | * |
||
| 528 | * @return integer |
||
| 529 | */ |
||
| 530 | public function getFeedbackType() |
||
| 534 | |||
| 535 | /** |
||
| 536 | * Set expiredTime |
||
| 537 | * |
||
| 538 | * @param integer $expiredTime |
||
| 539 | * @return CQuiz |
||
| 540 | */ |
||
| 541 | public function setExpiredTime($expiredTime) |
||
| 547 | |||
| 548 | /** |
||
| 549 | * Get expiredTime |
||
| 550 | * |
||
| 551 | * @return integer |
||
| 552 | */ |
||
| 553 | public function getExpiredTime() |
||
| 557 | |||
| 558 | /** |
||
| 559 | * Set sessionId |
||
| 560 | * |
||
| 561 | * @param integer $sessionId |
||
| 562 | * @return CQuiz |
||
| 563 | */ |
||
| 564 | public function setSessionId($sessionId) |
||
| 570 | |||
| 571 | /** |
||
| 572 | * Get sessionId |
||
| 573 | * |
||
| 574 | * @return integer |
||
| 575 | */ |
||
| 576 | public function getSessionId() |
||
| 580 | |||
| 581 | /** |
||
| 582 | * Set propagateNeg |
||
| 583 | * |
||
| 584 | * @param integer $propagateNeg |
||
| 585 | * @return CQuiz |
||
| 586 | */ |
||
| 587 | public function setPropagateNeg($propagateNeg) |
||
| 593 | |||
| 594 | /** |
||
| 595 | * Get propagateNeg |
||
| 596 | * |
||
| 597 | * @return integer |
||
| 598 | */ |
||
| 599 | public function getPropagateNeg() |
||
| 603 | |||
| 604 | /** |
||
| 605 | * @param $saveCorrectAnswers boolean |
||
| 606 | * @return CQuiz |
||
| 607 | */ |
||
| 608 | public function setSaveCorrectAnswers($saveCorrectAnswers) |
||
| 614 | |||
| 615 | /** |
||
| 616 | * @return boolean |
||
| 617 | */ |
||
| 618 | public function getSaveCorrectAnswers() |
||
| 622 | |||
| 623 | /** |
||
| 624 | * Set reviewAnswers |
||
| 625 | * |
||
| 626 | * @param integer $reviewAnswers |
||
| 627 | * @return CQuiz |
||
| 628 | */ |
||
| 629 | public function setReviewAnswers($reviewAnswers) |
||
| 635 | |||
| 636 | /** |
||
| 637 | * Get reviewAnswers |
||
| 638 | * |
||
| 639 | * @return integer |
||
| 640 | */ |
||
| 641 | public function getReviewAnswers() |
||
| 645 | |||
| 646 | /** |
||
| 647 | * Set randomByCategory |
||
| 648 | * |
||
| 649 | * @param integer $randomByCategory |
||
| 650 | * @return CQuiz |
||
| 651 | */ |
||
| 652 | public function setRandomByCategory($randomByCategory) |
||
| 658 | |||
| 659 | /** |
||
| 660 | * Get randomByCategory |
||
| 661 | * |
||
| 662 | * @return integer |
||
| 663 | */ |
||
| 664 | public function getRandomByCategory() |
||
| 668 | |||
| 669 | /** |
||
| 670 | * Set textWhenFinished |
||
| 671 | * |
||
| 672 | * @param string $textWhenFinished |
||
| 673 | * @return CQuiz |
||
| 674 | */ |
||
| 675 | public function setTextWhenFinished($textWhenFinished) |
||
| 681 | |||
| 682 | /** |
||
| 683 | * Get textWhenFinished |
||
| 684 | * |
||
| 685 | * @return string |
||
| 686 | */ |
||
| 687 | public function getTextWhenFinished() |
||
| 691 | |||
| 692 | /** |
||
| 693 | * Set displayCategoryName |
||
| 694 | * |
||
| 695 | * @param integer $displayCategoryName |
||
| 696 | * @return CQuiz |
||
| 697 | */ |
||
| 698 | public function setDisplayCategoryName($displayCategoryName) |
||
| 704 | |||
| 705 | /** |
||
| 706 | * Get displayCategoryName |
||
| 707 | * |
||
| 708 | * @return integer |
||
| 709 | */ |
||
| 710 | public function getDisplayCategoryName() |
||
| 714 | |||
| 715 | /** |
||
| 716 | * Set passPercentage |
||
| 717 | * |
||
| 718 | * @param integer $passPercentage |
||
| 719 | * @return CQuiz |
||
| 720 | */ |
||
| 721 | public function setPassPercentage($passPercentage) |
||
| 727 | |||
| 728 | /** |
||
| 729 | * Get passPercentage |
||
| 730 | * |
||
| 731 | * @return integer |
||
| 732 | */ |
||
| 733 | public function getPassPercentage() |
||
| 737 | |||
| 738 | /** |
||
| 739 | * Set id |
||
| 740 | * |
||
| 741 | * @param integer $id |
||
| 742 | * @return CQuiz |
||
| 743 | */ |
||
| 744 | public function setId($id) |
||
| 750 | |||
| 751 | /** |
||
| 752 | * Get id |
||
| 753 | * |
||
| 754 | * @return integer |
||
| 755 | */ |
||
| 756 | public function getId() |
||
| 760 | |||
| 761 | /** |
||
| 762 | * Set cId |
||
| 763 | * |
||
| 764 | * @param integer $cId |
||
| 765 | * @return CQuiz |
||
| 766 | */ |
||
| 767 | public function setCId($cId) |
||
| 773 | |||
| 774 | /** |
||
| 775 | * Get cId |
||
| 776 | * |
||
| 777 | * @return integer |
||
| 778 | */ |
||
| 779 | public function getCId() |
||
| 783 | |||
| 784 | /** |
||
| 785 | * @return int |
||
| 786 | */ |
||
| 787 | public function getQuestionSelectionType() |
||
| 791 | |||
| 792 | /** |
||
| 793 | * @param int $questionSelectionType |
||
| 794 | * @return CQuiz |
||
| 795 | */ |
||
| 796 | public function setQuestionSelectionType($questionSelectionType) |
||
| 802 | |||
| 803 | /** |
||
| 804 | * @return boolean |
||
| 805 | */ |
||
| 806 | public function isHideQuestionTitle() |
||
| 810 | |||
| 811 | /** |
||
| 812 | * @param boolean $hideQuestionTitle |
||
| 813 | * @return CQuiz |
||
| 814 | */ |
||
| 815 | public function setHideQuestionTitle($hideQuestionTitle) |
||
| 821 | |||
| 822 | /** |
||
| 823 | * @return bool |
||
| 824 | */ |
||
| 825 | public function isShowPreviousButton(): bool |
||
| 829 | |||
| 830 | /** |
||
| 831 | * @param bool $showPreviousButton |
||
| 832 | * @return CQuiz |
||
| 833 | */ |
||
| 834 | public function setShowPreviousButton(bool $showPreviousButton): CQuiz |
||
| 840 | |||
| 841 | /** |
||
| 842 | * @return string |
||
| 843 | */ |
||
| 844 | public function getNotifications(): string |
||
| 848 | |||
| 849 | /** |
||
| 850 | * @param string $notifications |
||
| 851 | * @return CQuiz |
||
| 852 | */ |
||
| 853 | public function setNotifications(string $notifications): CQuiz |
||
| 859 | } |
||
| 860 |