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=false) |
||
| 119 | */ |
||
| 120 | private $startTime; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @var \DateTime |
||
| 124 | * |
||
| 125 | * @ORM\Column(name="end_time", type="datetime", nullable=false) |
||
| 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 | * Set title |
||
| 207 | * |
||
| 208 | * @param string $title |
||
| 209 | * @return CQuiz |
||
| 210 | */ |
||
| 211 | public function setTitle($title) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Get title |
||
| 220 | * |
||
| 221 | * @return string |
||
| 222 | */ |
||
| 223 | public function getTitle() |
||
| 227 | |||
| 228 | /** |
||
| 229 | * Set description |
||
| 230 | * |
||
| 231 | * @param string $description |
||
| 232 | * @return CQuiz |
||
| 233 | */ |
||
| 234 | public function setDescription($description) |
||
| 240 | |||
| 241 | /** |
||
| 242 | * Get description |
||
| 243 | * |
||
| 244 | * @return string |
||
| 245 | */ |
||
| 246 | public function getDescription() |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Set sound |
||
| 253 | * |
||
| 254 | * @param string $sound |
||
| 255 | * @return CQuiz |
||
| 256 | */ |
||
| 257 | public function setSound($sound) |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Get sound |
||
| 266 | * |
||
| 267 | * @return string |
||
| 268 | */ |
||
| 269 | public function getSound() |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Set type |
||
| 276 | * |
||
| 277 | * @param boolean $type |
||
| 278 | * @return CQuiz |
||
| 279 | */ |
||
| 280 | public function setType($type) |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Get type |
||
| 289 | * |
||
| 290 | * @return boolean |
||
| 291 | */ |
||
| 292 | public function getType() |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Set random |
||
| 299 | * |
||
| 300 | * @param integer $random |
||
| 301 | * @return CQuiz |
||
| 302 | */ |
||
| 303 | public function setRandom($random) |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Get random |
||
| 312 | * |
||
| 313 | * @return integer |
||
| 314 | */ |
||
| 315 | public function getRandom() |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Set randomAnswers |
||
| 322 | * |
||
| 323 | * @param boolean $randomAnswers |
||
| 324 | * @return CQuiz |
||
| 325 | */ |
||
| 326 | public function setRandomAnswers($randomAnswers) |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Get randomAnswers |
||
| 335 | * |
||
| 336 | * @return boolean |
||
| 337 | */ |
||
| 338 | public function getRandomAnswers() |
||
| 342 | |||
| 343 | /** |
||
| 344 | * Set active |
||
| 345 | * |
||
| 346 | * @param boolean $active |
||
| 347 | * @return CQuiz |
||
| 348 | */ |
||
| 349 | public function setActive($active) |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Get active |
||
| 358 | * |
||
| 359 | * @return boolean |
||
| 360 | */ |
||
| 361 | public function getActive() |
||
| 365 | |||
| 366 | /** |
||
| 367 | * Set resultsDisabled |
||
| 368 | * |
||
| 369 | * @param integer $resultsDisabled |
||
| 370 | * @return CQuiz |
||
| 371 | */ |
||
| 372 | public function setResultsDisabled($resultsDisabled) |
||
| 378 | |||
| 379 | /** |
||
| 380 | * Get resultsDisabled |
||
| 381 | * |
||
| 382 | * @return integer |
||
| 383 | */ |
||
| 384 | public function getResultsDisabled() |
||
| 388 | |||
| 389 | /** |
||
| 390 | * Set accessCondition |
||
| 391 | * |
||
| 392 | * @param string $accessCondition |
||
| 393 | * @return CQuiz |
||
| 394 | */ |
||
| 395 | public function setAccessCondition($accessCondition) |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Get accessCondition |
||
| 404 | * |
||
| 405 | * @return string |
||
| 406 | */ |
||
| 407 | public function getAccessCondition() |
||
| 411 | |||
| 412 | /** |
||
| 413 | * Set maxAttempt |
||
| 414 | * |
||
| 415 | * @param integer $maxAttempt |
||
| 416 | * @return CQuiz |
||
| 417 | */ |
||
| 418 | public function setMaxAttempt($maxAttempt) |
||
| 424 | |||
| 425 | /** |
||
| 426 | * Get maxAttempt |
||
| 427 | * |
||
| 428 | * @return integer |
||
| 429 | */ |
||
| 430 | public function getMaxAttempt() |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Set startTime |
||
| 437 | * |
||
| 438 | * @param \DateTime $startTime |
||
| 439 | * @return CQuiz |
||
| 440 | */ |
||
| 441 | public function setStartTime($startTime) |
||
| 447 | |||
| 448 | /** |
||
| 449 | * Get startTime |
||
| 450 | * |
||
| 451 | * @return \DateTime |
||
| 452 | */ |
||
| 453 | public function getStartTime() |
||
| 457 | |||
| 458 | /** |
||
| 459 | * Set endTime |
||
| 460 | * |
||
| 461 | * @param \DateTime $endTime |
||
| 462 | * @return CQuiz |
||
| 463 | */ |
||
| 464 | public function setEndTime($endTime) |
||
| 470 | |||
| 471 | /** |
||
| 472 | * Get endTime |
||
| 473 | * |
||
| 474 | * @return \DateTime |
||
| 475 | */ |
||
| 476 | public function getEndTime() |
||
| 480 | |||
| 481 | /** |
||
| 482 | * Set feedbackType |
||
| 483 | * |
||
| 484 | * @param integer $feedbackType |
||
| 485 | * @return CQuiz |
||
| 486 | */ |
||
| 487 | public function setFeedbackType($feedbackType) |
||
| 493 | |||
| 494 | /** |
||
| 495 | * Get feedbackType |
||
| 496 | * |
||
| 497 | * @return integer |
||
| 498 | */ |
||
| 499 | public function getFeedbackType() |
||
| 503 | |||
| 504 | /** |
||
| 505 | * Set expiredTime |
||
| 506 | * |
||
| 507 | * @param integer $expiredTime |
||
| 508 | * @return CQuiz |
||
| 509 | */ |
||
| 510 | public function setExpiredTime($expiredTime) |
||
| 516 | |||
| 517 | /** |
||
| 518 | * Get expiredTime |
||
| 519 | * |
||
| 520 | * @return integer |
||
| 521 | */ |
||
| 522 | public function getExpiredTime() |
||
| 526 | |||
| 527 | /** |
||
| 528 | * Set sessionId |
||
| 529 | * |
||
| 530 | * @param integer $sessionId |
||
| 531 | * @return CQuiz |
||
| 532 | */ |
||
| 533 | public function setSessionId($sessionId) |
||
| 539 | |||
| 540 | /** |
||
| 541 | * Get sessionId |
||
| 542 | * |
||
| 543 | * @return integer |
||
| 544 | */ |
||
| 545 | public function getSessionId() |
||
| 549 | |||
| 550 | /** |
||
| 551 | * Set propagateNeg |
||
| 552 | * |
||
| 553 | * @param integer $propagateNeg |
||
| 554 | * @return CQuiz |
||
| 555 | */ |
||
| 556 | public function setPropagateNeg($propagateNeg) |
||
| 562 | |||
| 563 | /** |
||
| 564 | * Get propagateNeg |
||
| 565 | * |
||
| 566 | * @return integer |
||
| 567 | */ |
||
| 568 | public function getPropagateNeg() |
||
| 572 | |||
| 573 | /** |
||
| 574 | * @param $saveCorrectAnswers boolean |
||
| 575 | * @return CQuiz |
||
| 576 | */ |
||
| 577 | public function setSaveCorrectAnswers($saveCorrectAnswers) |
||
| 583 | |||
| 584 | /** |
||
| 585 | * @return boolean |
||
| 586 | */ |
||
| 587 | public function getSaveCorrectAnswers() |
||
| 591 | |||
| 592 | /** |
||
| 593 | * Set reviewAnswers |
||
| 594 | * |
||
| 595 | * @param integer $reviewAnswers |
||
| 596 | * @return CQuiz |
||
| 597 | */ |
||
| 598 | public function setReviewAnswers($reviewAnswers) |
||
| 604 | |||
| 605 | /** |
||
| 606 | * Get reviewAnswers |
||
| 607 | * |
||
| 608 | * @return integer |
||
| 609 | */ |
||
| 610 | public function getReviewAnswers() |
||
| 614 | |||
| 615 | /** |
||
| 616 | * Set randomByCategory |
||
| 617 | * |
||
| 618 | * @param integer $randomByCategory |
||
| 619 | * @return CQuiz |
||
| 620 | */ |
||
| 621 | public function setRandomByCategory($randomByCategory) |
||
| 627 | |||
| 628 | /** |
||
| 629 | * Get randomByCategory |
||
| 630 | * |
||
| 631 | * @return integer |
||
| 632 | */ |
||
| 633 | public function getRandomByCategory() |
||
| 637 | |||
| 638 | /** |
||
| 639 | * Set textWhenFinished |
||
| 640 | * |
||
| 641 | * @param string $textWhenFinished |
||
| 642 | * @return CQuiz |
||
| 643 | */ |
||
| 644 | public function setTextWhenFinished($textWhenFinished) |
||
| 650 | |||
| 651 | /** |
||
| 652 | * Get textWhenFinished |
||
| 653 | * |
||
| 654 | * @return string |
||
| 655 | */ |
||
| 656 | public function getTextWhenFinished() |
||
| 660 | |||
| 661 | /** |
||
| 662 | * Set displayCategoryName |
||
| 663 | * |
||
| 664 | * @param integer $displayCategoryName |
||
| 665 | * @return CQuiz |
||
| 666 | */ |
||
| 667 | public function setDisplayCategoryName($displayCategoryName) |
||
| 673 | |||
| 674 | /** |
||
| 675 | * Get displayCategoryName |
||
| 676 | * |
||
| 677 | * @return integer |
||
| 678 | */ |
||
| 679 | public function getDisplayCategoryName() |
||
| 683 | |||
| 684 | /** |
||
| 685 | * Set passPercentage |
||
| 686 | * |
||
| 687 | * @param integer $passPercentage |
||
| 688 | * @return CQuiz |
||
| 689 | */ |
||
| 690 | public function setPassPercentage($passPercentage) |
||
| 696 | |||
| 697 | /** |
||
| 698 | * Get passPercentage |
||
| 699 | * |
||
| 700 | * @return integer |
||
| 701 | */ |
||
| 702 | public function getPassPercentage() |
||
| 706 | |||
| 707 | /** |
||
| 708 | * Set id |
||
| 709 | * |
||
| 710 | * @param integer $id |
||
| 711 | * @return CQuiz |
||
| 712 | */ |
||
| 713 | public function setId($id) |
||
| 719 | |||
| 720 | /** |
||
| 721 | * Get id |
||
| 722 | * |
||
| 723 | * @return integer |
||
| 724 | */ |
||
| 725 | public function getId() |
||
| 729 | |||
| 730 | /** |
||
| 731 | * Set cId |
||
| 732 | * |
||
| 733 | * @param integer $cId |
||
| 734 | * @return CQuiz |
||
| 735 | */ |
||
| 736 | public function setCId($cId) |
||
| 742 | |||
| 743 | /** |
||
| 744 | * Get cId |
||
| 745 | * |
||
| 746 | * @return integer |
||
| 747 | */ |
||
| 748 | public function getCId() |
||
| 752 | } |
||
| 753 |
This check marks private properties in classes that are never used. Those properties can be removed.