Complex classes like CWiki 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 CWiki, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 23 | class CWiki |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @var integer |
||
| 27 | * |
||
| 28 | * @ORM\Column(name="iid", type="integer") |
||
| 29 | * @ORM\Id |
||
| 30 | * @ORM\GeneratedValue |
||
| 31 | */ |
||
| 32 | private $iid; |
||
|
|
|||
| 33 | |||
| 34 | /** |
||
| 35 | * @var integer |
||
| 36 | * |
||
| 37 | * @ORM\Column(name="c_id", type="integer") |
||
| 38 | */ |
||
| 39 | private $cId; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var integer |
||
| 43 | * |
||
| 44 | * @ORM\Column(name="id", type="integer", nullable=true) |
||
| 45 | */ |
||
| 46 | private $id; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var integer |
||
| 50 | * |
||
| 51 | * @ORM\Column(name="page_id", type="integer", nullable=true) |
||
| 52 | */ |
||
| 53 | private $pageId; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var string |
||
| 57 | * |
||
| 58 | * @ORM\Column(name="reflink", type="string", length=255, nullable=false) |
||
| 59 | */ |
||
| 60 | private $reflink; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @var string |
||
| 64 | * |
||
| 65 | * @ORM\Column(name="title", type="string", length=255, nullable=false) |
||
| 66 | */ |
||
| 67 | private $title; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var string |
||
| 71 | * |
||
| 72 | * @ORM\Column(name="content", type="text", nullable=false) |
||
| 73 | */ |
||
| 74 | private $content; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var integer |
||
| 78 | * |
||
| 79 | * @ORM\Column(name="user_id", type="integer", nullable=false) |
||
| 80 | */ |
||
| 81 | private $userId; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @var integer |
||
| 85 | * |
||
| 86 | * @ORM\Column(name="group_id", type="integer", nullable=true) |
||
| 87 | */ |
||
| 88 | private $groupId; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @var \DateTime |
||
| 92 | * |
||
| 93 | * @ORM\Column(name="dtime", type="datetime", nullable=true) |
||
| 94 | */ |
||
| 95 | private $dtime; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @var integer |
||
| 99 | * |
||
| 100 | * @ORM\Column(name="addlock", type="integer", nullable=false) |
||
| 101 | */ |
||
| 102 | private $addlock; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var integer |
||
| 106 | * |
||
| 107 | * @ORM\Column(name="editlock", type="integer", nullable=false) |
||
| 108 | */ |
||
| 109 | private $editlock; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @var integer |
||
| 113 | * |
||
| 114 | * @ORM\Column(name="visibility", type="integer", nullable=false) |
||
| 115 | */ |
||
| 116 | private $visibility; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @var integer |
||
| 120 | * |
||
| 121 | * @ORM\Column(name="addlock_disc", type="integer", nullable=false) |
||
| 122 | */ |
||
| 123 | private $addlockDisc; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @var integer |
||
| 127 | * |
||
| 128 | * @ORM\Column(name="visibility_disc", type="integer", nullable=false) |
||
| 129 | */ |
||
| 130 | private $visibilityDisc; |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @var integer |
||
| 134 | * |
||
| 135 | * @ORM\Column(name="ratinglock_disc", type="integer", nullable=false) |
||
| 136 | */ |
||
| 137 | private $ratinglockDisc; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @var integer |
||
| 141 | * |
||
| 142 | * @ORM\Column(name="assignment", type="integer", nullable=false) |
||
| 143 | */ |
||
| 144 | private $assignment; |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @var string |
||
| 148 | * |
||
| 149 | * @ORM\Column(name="comment", type="text", nullable=false) |
||
| 150 | */ |
||
| 151 | private $comment; |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @var string |
||
| 155 | * |
||
| 156 | * @ORM\Column(name="progress", type="text", nullable=false) |
||
| 157 | */ |
||
| 158 | private $progress; |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @var integer |
||
| 162 | * |
||
| 163 | * @ORM\Column(name="score", type="integer", nullable=true) |
||
| 164 | */ |
||
| 165 | private $score; |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @var integer |
||
| 169 | * |
||
| 170 | * @ORM\Column(name="version", type="integer", nullable=true) |
||
| 171 | */ |
||
| 172 | private $version; |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @var integer |
||
| 176 | * |
||
| 177 | * @ORM\Column(name="is_editing", type="integer", nullable=false) |
||
| 178 | */ |
||
| 179 | private $isEditing; |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @var \DateTime |
||
| 183 | * |
||
| 184 | * @ORM\Column(name="time_edit", type="datetime", nullable=true) |
||
| 185 | */ |
||
| 186 | private $timeEdit; |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @var integer |
||
| 190 | * |
||
| 191 | * @ORM\Column(name="hits", type="integer", nullable=true) |
||
| 192 | */ |
||
| 193 | private $hits; |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @var string |
||
| 197 | * |
||
| 198 | * @ORM\Column(name="linksto", type="text", nullable=false) |
||
| 199 | */ |
||
| 200 | private $linksto; |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @var string |
||
| 204 | * |
||
| 205 | * @ORM\Column(name="tag", type="text", nullable=false) |
||
| 206 | */ |
||
| 207 | private $tag; |
||
| 208 | |||
| 209 | /** |
||
| 210 | * @var string |
||
| 211 | * |
||
| 212 | * @ORM\Column(name="user_ip", type="string", length=39, nullable=false) |
||
| 213 | */ |
||
| 214 | private $userIp; |
||
| 215 | |||
| 216 | /** |
||
| 217 | * @var integer |
||
| 218 | * |
||
| 219 | * @ORM\Column(name="session_id", type="integer", nullable=true) |
||
| 220 | */ |
||
| 221 | private $sessionId; |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Set pageId |
||
| 225 | * |
||
| 226 | * @param integer $pageId |
||
| 227 | * @return CWiki |
||
| 228 | */ |
||
| 229 | public function setPageId($pageId) |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Get pageId |
||
| 238 | * |
||
| 239 | * @return integer |
||
| 240 | */ |
||
| 241 | public function getPageId() |
||
| 245 | |||
| 246 | /** |
||
| 247 | * Set reflink |
||
| 248 | * |
||
| 249 | * @param string $reflink |
||
| 250 | * @return CWiki |
||
| 251 | */ |
||
| 252 | public function setReflink($reflink) |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Get reflink |
||
| 261 | * |
||
| 262 | * @return string |
||
| 263 | */ |
||
| 264 | public function getReflink() |
||
| 268 | |||
| 269 | /** |
||
| 270 | * Set title |
||
| 271 | * |
||
| 272 | * @param string $title |
||
| 273 | * @return CWiki |
||
| 274 | */ |
||
| 275 | public function setTitle($title) |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Get title |
||
| 284 | * |
||
| 285 | * @return string |
||
| 286 | */ |
||
| 287 | public function getTitle() |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Set content |
||
| 294 | * |
||
| 295 | * @param string $content |
||
| 296 | * @return CWiki |
||
| 297 | */ |
||
| 298 | public function setContent($content) |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Get content |
||
| 307 | * |
||
| 308 | * @return string |
||
| 309 | */ |
||
| 310 | public function getContent() |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Set userId |
||
| 317 | * |
||
| 318 | * @param integer $userId |
||
| 319 | * @return CWiki |
||
| 320 | */ |
||
| 321 | public function setUserId($userId) |
||
| 327 | |||
| 328 | /** |
||
| 329 | * Get userId |
||
| 330 | * |
||
| 331 | * @return integer |
||
| 332 | */ |
||
| 333 | public function getUserId() |
||
| 337 | |||
| 338 | /** |
||
| 339 | * Set groupId |
||
| 340 | * |
||
| 341 | * @param integer $groupId |
||
| 342 | * @return CWiki |
||
| 343 | */ |
||
| 344 | public function setGroupId($groupId) |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Get groupId |
||
| 353 | * |
||
| 354 | * @return integer |
||
| 355 | */ |
||
| 356 | public function getGroupId() |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Set dtime |
||
| 363 | * |
||
| 364 | * @param \DateTime $dtime |
||
| 365 | * @return CWiki |
||
| 366 | */ |
||
| 367 | public function setDtime($dtime) |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Get dtime |
||
| 376 | * |
||
| 377 | * @return \DateTime |
||
| 378 | */ |
||
| 379 | public function getDtime() |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Set addlock |
||
| 386 | * |
||
| 387 | * @param integer $addlock |
||
| 388 | * @return CWiki |
||
| 389 | */ |
||
| 390 | public function setAddlock($addlock) |
||
| 396 | |||
| 397 | /** |
||
| 398 | * Get addlock |
||
| 399 | * |
||
| 400 | * @return integer |
||
| 401 | */ |
||
| 402 | public function getAddlock() |
||
| 406 | |||
| 407 | /** |
||
| 408 | * Set editlock |
||
| 409 | * |
||
| 410 | * @param integer $editlock |
||
| 411 | * @return CWiki |
||
| 412 | */ |
||
| 413 | public function setEditlock($editlock) |
||
| 419 | |||
| 420 | /** |
||
| 421 | * Get editlock |
||
| 422 | * |
||
| 423 | * @return integer |
||
| 424 | */ |
||
| 425 | public function getEditlock() |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Set visibility |
||
| 432 | * |
||
| 433 | * @param integer $visibility |
||
| 434 | * @return CWiki |
||
| 435 | */ |
||
| 436 | public function setVisibility($visibility) |
||
| 442 | |||
| 443 | /** |
||
| 444 | * Get visibility |
||
| 445 | * |
||
| 446 | * @return integer |
||
| 447 | */ |
||
| 448 | public function getVisibility() |
||
| 452 | |||
| 453 | /** |
||
| 454 | * Set addlockDisc |
||
| 455 | * |
||
| 456 | * @param integer $addlockDisc |
||
| 457 | * @return CWiki |
||
| 458 | */ |
||
| 459 | public function setAddlockDisc($addlockDisc) |
||
| 465 | |||
| 466 | /** |
||
| 467 | * Get addlockDisc |
||
| 468 | * |
||
| 469 | * @return integer |
||
| 470 | */ |
||
| 471 | public function getAddlockDisc() |
||
| 475 | |||
| 476 | /** |
||
| 477 | * Set visibilityDisc |
||
| 478 | * |
||
| 479 | * @param integer $visibilityDisc |
||
| 480 | * @return CWiki |
||
| 481 | */ |
||
| 482 | public function setVisibilityDisc($visibilityDisc) |
||
| 488 | |||
| 489 | /** |
||
| 490 | * Get visibilityDisc |
||
| 491 | * |
||
| 492 | * @return integer |
||
| 493 | */ |
||
| 494 | public function getVisibilityDisc() |
||
| 498 | |||
| 499 | /** |
||
| 500 | * Set ratinglockDisc |
||
| 501 | * |
||
| 502 | * @param integer $ratinglockDisc |
||
| 503 | * @return CWiki |
||
| 504 | */ |
||
| 505 | public function setRatinglockDisc($ratinglockDisc) |
||
| 511 | |||
| 512 | /** |
||
| 513 | * Get ratinglockDisc |
||
| 514 | * |
||
| 515 | * @return integer |
||
| 516 | */ |
||
| 517 | public function getRatinglockDisc() |
||
| 521 | |||
| 522 | /** |
||
| 523 | * Set assignment |
||
| 524 | * |
||
| 525 | * @param integer $assignment |
||
| 526 | * @return CWiki |
||
| 527 | */ |
||
| 528 | public function setAssignment($assignment) |
||
| 534 | |||
| 535 | /** |
||
| 536 | * Get assignment |
||
| 537 | * |
||
| 538 | * @return integer |
||
| 539 | */ |
||
| 540 | public function getAssignment() |
||
| 544 | |||
| 545 | /** |
||
| 546 | * Set comment |
||
| 547 | * |
||
| 548 | * @param string $comment |
||
| 549 | * @return CWiki |
||
| 550 | */ |
||
| 551 | public function setComment($comment) |
||
| 557 | |||
| 558 | /** |
||
| 559 | * Get comment |
||
| 560 | * |
||
| 561 | * @return string |
||
| 562 | */ |
||
| 563 | public function getComment() |
||
| 567 | |||
| 568 | /** |
||
| 569 | * Set progress |
||
| 570 | * |
||
| 571 | * @param string $progress |
||
| 572 | * @return CWiki |
||
| 573 | */ |
||
| 574 | public function setProgress($progress) |
||
| 580 | |||
| 581 | /** |
||
| 582 | * Get progress |
||
| 583 | * |
||
| 584 | * @return string |
||
| 585 | */ |
||
| 586 | public function getProgress() |
||
| 590 | |||
| 591 | /** |
||
| 592 | * Set score |
||
| 593 | * |
||
| 594 | * @param integer $score |
||
| 595 | * @return CWiki |
||
| 596 | */ |
||
| 597 | public function setScore($score) |
||
| 603 | |||
| 604 | /** |
||
| 605 | * Get score |
||
| 606 | * |
||
| 607 | * @return integer |
||
| 608 | */ |
||
| 609 | public function getScore() |
||
| 613 | |||
| 614 | /** |
||
| 615 | * Set version |
||
| 616 | * |
||
| 617 | * @param integer $version |
||
| 618 | * @return CWiki |
||
| 619 | */ |
||
| 620 | public function setVersion($version) |
||
| 626 | |||
| 627 | /** |
||
| 628 | * Get version |
||
| 629 | * |
||
| 630 | * @return integer |
||
| 631 | */ |
||
| 632 | public function getVersion() |
||
| 636 | |||
| 637 | /** |
||
| 638 | * Set isEditing |
||
| 639 | * |
||
| 640 | * @param integer $isEditing |
||
| 641 | * @return CWiki |
||
| 642 | */ |
||
| 643 | public function setIsEditing($isEditing) |
||
| 649 | |||
| 650 | /** |
||
| 651 | * Get isEditing |
||
| 652 | * |
||
| 653 | * @return integer |
||
| 654 | */ |
||
| 655 | public function getIsEditing() |
||
| 659 | |||
| 660 | /** |
||
| 661 | * Set timeEdit |
||
| 662 | * |
||
| 663 | * @param \DateTime $timeEdit |
||
| 664 | * @return CWiki |
||
| 665 | */ |
||
| 666 | public function setTimeEdit($timeEdit) |
||
| 672 | |||
| 673 | /** |
||
| 674 | * Get timeEdit |
||
| 675 | * |
||
| 676 | * @return \DateTime |
||
| 677 | */ |
||
| 678 | public function getTimeEdit() |
||
| 682 | |||
| 683 | /** |
||
| 684 | * Set hits |
||
| 685 | * |
||
| 686 | * @param integer $hits |
||
| 687 | * @return CWiki |
||
| 688 | */ |
||
| 689 | public function setHits($hits) |
||
| 695 | |||
| 696 | /** |
||
| 697 | * Get hits |
||
| 698 | * |
||
| 699 | * @return integer |
||
| 700 | */ |
||
| 701 | public function getHits() |
||
| 705 | |||
| 706 | /** |
||
| 707 | * Set linksto |
||
| 708 | * |
||
| 709 | * @param string $linksto |
||
| 710 | * @return CWiki |
||
| 711 | */ |
||
| 712 | public function setLinksto($linksto) |
||
| 718 | |||
| 719 | /** |
||
| 720 | * Get linksto |
||
| 721 | * |
||
| 722 | * @return string |
||
| 723 | */ |
||
| 724 | public function getLinksto() |
||
| 728 | |||
| 729 | /** |
||
| 730 | * Set tag |
||
| 731 | * |
||
| 732 | * @param string $tag |
||
| 733 | * @return CWiki |
||
| 734 | */ |
||
| 735 | public function setTag($tag) |
||
| 741 | |||
| 742 | /** |
||
| 743 | * Get tag |
||
| 744 | * |
||
| 745 | * @return string |
||
| 746 | */ |
||
| 747 | public function getTag() |
||
| 751 | |||
| 752 | /** |
||
| 753 | * Set userIp |
||
| 754 | * |
||
| 755 | * @param string $userIp |
||
| 756 | * @return CWiki |
||
| 757 | */ |
||
| 758 | public function setUserIp($userIp) |
||
| 764 | |||
| 765 | /** |
||
| 766 | * Get userIp |
||
| 767 | * |
||
| 768 | * @return string |
||
| 769 | */ |
||
| 770 | public function getUserIp() |
||
| 774 | |||
| 775 | /** |
||
| 776 | * Set sessionId |
||
| 777 | * |
||
| 778 | * @param integer $sessionId |
||
| 779 | * @return CWiki |
||
| 780 | */ |
||
| 781 | public function setSessionId($sessionId) |
||
| 787 | |||
| 788 | /** |
||
| 789 | * Get sessionId |
||
| 790 | * |
||
| 791 | * @return integer |
||
| 792 | */ |
||
| 793 | public function getSessionId() |
||
| 797 | |||
| 798 | /** |
||
| 799 | * Set id |
||
| 800 | * |
||
| 801 | * @param integer $id |
||
| 802 | * @return CWiki |
||
| 803 | */ |
||
| 804 | public function setId($id) |
||
| 810 | |||
| 811 | /** |
||
| 812 | * Get id |
||
| 813 | * |
||
| 814 | * @return integer |
||
| 815 | */ |
||
| 816 | public function getId() |
||
| 820 | |||
| 821 | /** |
||
| 822 | * Set cId |
||
| 823 | * |
||
| 824 | * @param integer $cId |
||
| 825 | * @return CWiki |
||
| 826 | */ |
||
| 827 | public function setCId($cId) |
||
| 833 | |||
| 834 | /** |
||
| 835 | * Get cId |
||
| 836 | * |
||
| 837 | * @return integer |
||
| 838 | */ |
||
| 839 | public function getCId() |
||
| 843 | } |
||
| 844 |
This check marks private properties in classes that are never used. Those properties can be removed.