| Total Complexity | 43 |
| Total Lines | 623 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Complex classes like CForumThread 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.
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 CForumThread, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | class CForumThread extends AbstractResource implements ResourceInterface |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * @var int |
||
| 29 | * |
||
| 30 | * @ORM\Column(name="iid", type="integer") |
||
| 31 | * @ORM\Id |
||
| 32 | * @ORM\GeneratedValue |
||
| 33 | */ |
||
| 34 | protected $iid; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var int |
||
| 38 | * |
||
| 39 | * @ORM\Column(name="c_id", type="integer") |
||
| 40 | */ |
||
| 41 | protected $cId; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var string |
||
| 45 | * @Assert\NotBlank() |
||
| 46 | * @ORM\Column(name="thread_title", type="string", length=255, nullable=true) |
||
| 47 | */ |
||
| 48 | protected $threadTitle; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var CForumForum|null |
||
| 52 | * |
||
| 53 | * @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CForumForum", inversedBy="threads") |
||
| 54 | * @ORM\JoinColumn(name="forum_id", referencedColumnName="iid", nullable=true, onDelete="SET NULL") |
||
| 55 | */ |
||
| 56 | protected $forum; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var int |
||
| 60 | * |
||
| 61 | * @ORM\Column(name="thread_replies", type="integer", nullable=false, options={"unsigned":true, "default" = 0}) |
||
| 62 | */ |
||
| 63 | protected $threadReplies; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var int |
||
| 67 | * |
||
| 68 | * @ORM\Column(name="thread_poster_id", type="integer", nullable=true) |
||
| 69 | */ |
||
| 70 | protected $threadPosterId; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @var string |
||
| 74 | * |
||
| 75 | * @ORM\Column(name="thread_poster_name", type="string", length=100, nullable=true) |
||
| 76 | */ |
||
| 77 | protected $threadPosterName; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var int |
||
| 81 | * |
||
| 82 | * @ORM\Column(name="thread_views", type="integer", nullable=false, options={"unsigned":true, "default" = 0}) |
||
| 83 | */ |
||
| 84 | protected $threadViews; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var int |
||
| 88 | * |
||
| 89 | * @ORM\Column(name="thread_last_post", type="integer", nullable=true) |
||
| 90 | */ |
||
| 91 | protected $threadLastPost; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @var \DateTime |
||
| 95 | * |
||
| 96 | * @ORM\Column(name="thread_date", type="datetime", nullable=true) |
||
| 97 | */ |
||
| 98 | protected $threadDate; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @var bool |
||
| 102 | * |
||
| 103 | * @ORM\Column(name="thread_sticky", type="boolean", nullable=true) |
||
| 104 | */ |
||
| 105 | protected $threadSticky; |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @var int |
||
| 109 | * |
||
| 110 | * @ORM\Column(name="locked", type="integer", nullable=false) |
||
| 111 | */ |
||
| 112 | protected $locked; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @var int |
||
| 116 | * |
||
| 117 | * @ORM\Column(name="session_id", type="integer", nullable=true) |
||
| 118 | */ |
||
| 119 | protected $sessionId; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @var string |
||
| 123 | * |
||
| 124 | * @ORM\Column(name="thread_title_qualify", type="string", length=255, nullable=true) |
||
| 125 | */ |
||
| 126 | protected $threadTitleQualify; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @var float |
||
| 130 | * |
||
| 131 | * @ORM\Column(name="thread_qualify_max", type="float", precision=6, scale=2, nullable=false) |
||
| 132 | */ |
||
| 133 | protected $threadQualifyMax; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @var \DateTime |
||
| 137 | * |
||
| 138 | * @ORM\Column(name="thread_close_date", type="datetime", nullable=true) |
||
| 139 | */ |
||
| 140 | protected $threadCloseDate; |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @var float |
||
| 144 | * |
||
| 145 | * @ORM\Column(name="thread_weight", type="float", precision=6, scale=2, nullable=false) |
||
| 146 | */ |
||
| 147 | protected $threadWeight; |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @var bool |
||
| 151 | * |
||
| 152 | * @ORM\Column(name="thread_peer_qualify", type="boolean") |
||
| 153 | */ |
||
| 154 | protected $threadPeerQualify; |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @var int |
||
| 158 | * |
||
| 159 | * @ORM\Column(name="lp_item_id", type="integer", options={"unsigned":true}) |
||
| 160 | */ |
||
| 161 | protected $lpItemId; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @var CForumPost[] |
||
| 165 | * |
||
| 166 | * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CForumPost", mappedBy="thread", cascade={"persist", "remove"}, orphanRemoval=true) |
||
| 167 | */ |
||
| 168 | protected $posts; |
||
| 169 | |||
| 170 | public function __construct() |
||
| 171 | { |
||
| 172 | $this->threadPeerQualify = false; |
||
| 173 | $this->threadReplies = 0; |
||
| 174 | $this->threadViews = 0; |
||
| 175 | $this->locked = 0; |
||
| 176 | $this->threadQualifyMax = 0; |
||
| 177 | $this->threadWeight = 0; |
||
| 178 | $this->lpItemId = 0; |
||
| 179 | } |
||
| 180 | |||
| 181 | public function __toString(): string |
||
| 182 | { |
||
| 183 | return (string) $this->getThreadTitle(); |
||
| 184 | } |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @return bool |
||
| 188 | */ |
||
| 189 | public function isThreadPeerQualify() |
||
| 190 | { |
||
| 191 | return $this->threadPeerQualify; |
||
| 192 | } |
||
| 193 | |||
| 194 | /** |
||
| 195 | * set threadPeerQualify. |
||
| 196 | * |
||
| 197 | * @param bool $threadPeerQualify |
||
| 198 | * |
||
| 199 | * @return $this |
||
| 200 | */ |
||
| 201 | public function setThreadPeerQualify($threadPeerQualify) |
||
| 202 | { |
||
| 203 | $this->threadPeerQualify = $threadPeerQualify; |
||
| 204 | |||
| 205 | return $this; |
||
| 206 | } |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Set threadTitle. |
||
| 210 | * |
||
| 211 | * @param string $threadTitle |
||
| 212 | * |
||
| 213 | * @return CForumThread |
||
| 214 | */ |
||
| 215 | public function setThreadTitle($threadTitle) |
||
| 216 | { |
||
| 217 | $this->threadTitle = $threadTitle; |
||
| 218 | |||
| 219 | return $this; |
||
| 220 | } |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Get threadTitle. |
||
| 224 | * |
||
| 225 | * @return string |
||
| 226 | */ |
||
| 227 | public function getThreadTitle() |
||
| 228 | { |
||
| 229 | return $this->threadTitle; |
||
| 230 | } |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Set forum. |
||
| 234 | * |
||
| 235 | * @return CForumThread |
||
| 236 | */ |
||
| 237 | public function setForum(CForumForum $forum = null) |
||
| 238 | { |
||
| 239 | $this->forum = $forum; |
||
| 240 | |||
| 241 | return $this; |
||
| 242 | } |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Get forumId. |
||
| 246 | * |
||
| 247 | * @return CForumForum|null |
||
| 248 | */ |
||
| 249 | public function getForum() |
||
| 250 | { |
||
| 251 | return $this->forum; |
||
| 252 | } |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Set threadReplies. |
||
| 256 | * |
||
| 257 | * @param int $threadReplies |
||
| 258 | * |
||
| 259 | * @return CForumThread |
||
| 260 | */ |
||
| 261 | public function setThreadReplies($threadReplies) |
||
| 262 | { |
||
| 263 | $this->threadReplies = $threadReplies; |
||
| 264 | |||
| 265 | return $this; |
||
| 266 | } |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Get threadReplies. |
||
| 270 | * |
||
| 271 | * @return int |
||
| 272 | */ |
||
| 273 | public function getThreadReplies() |
||
| 274 | { |
||
| 275 | return $this->threadReplies; |
||
| 276 | } |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Set threadPosterId. |
||
| 280 | * |
||
| 281 | * @param int $threadPosterId |
||
| 282 | * |
||
| 283 | * @return CForumThread |
||
| 284 | */ |
||
| 285 | public function setThreadPosterId($threadPosterId) |
||
| 286 | { |
||
| 287 | $this->threadPosterId = $threadPosterId; |
||
| 288 | |||
| 289 | return $this; |
||
| 290 | } |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Get threadPosterId. |
||
| 294 | * |
||
| 295 | * @return int |
||
| 296 | */ |
||
| 297 | public function getThreadPosterId() |
||
| 298 | { |
||
| 299 | return $this->threadPosterId; |
||
| 300 | } |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Set threadPosterName. |
||
| 304 | * |
||
| 305 | * @param string $threadPosterName |
||
| 306 | * |
||
| 307 | * @return CForumThread |
||
| 308 | */ |
||
| 309 | public function setThreadPosterName($threadPosterName) |
||
| 310 | { |
||
| 311 | $this->threadPosterName = $threadPosterName; |
||
| 312 | |||
| 313 | return $this; |
||
| 314 | } |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Get threadPosterName. |
||
| 318 | * |
||
| 319 | * @return string |
||
| 320 | */ |
||
| 321 | public function getThreadPosterName() |
||
| 322 | { |
||
| 323 | return $this->threadPosterName; |
||
| 324 | } |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Set threadViews. |
||
| 328 | * |
||
| 329 | * @param int $threadViews |
||
| 330 | * |
||
| 331 | * @return CForumThread |
||
| 332 | */ |
||
| 333 | public function setThreadViews($threadViews) |
||
| 334 | { |
||
| 335 | $this->threadViews = $threadViews; |
||
| 336 | |||
| 337 | return $this; |
||
| 338 | } |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Get threadViews. |
||
| 342 | * |
||
| 343 | * @return int |
||
| 344 | */ |
||
| 345 | public function getThreadViews() |
||
| 346 | { |
||
| 347 | return $this->threadViews; |
||
| 348 | } |
||
| 349 | |||
| 350 | /** |
||
| 351 | * Set threadLastPost. |
||
| 352 | * |
||
| 353 | * @param int $threadLastPost |
||
| 354 | * |
||
| 355 | * @return CForumThread |
||
| 356 | */ |
||
| 357 | public function setThreadLastPost($threadLastPost) |
||
| 358 | { |
||
| 359 | $this->threadLastPost = $threadLastPost; |
||
| 360 | |||
| 361 | return $this; |
||
| 362 | } |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Get threadLastPost. |
||
| 366 | * |
||
| 367 | * @return int |
||
| 368 | */ |
||
| 369 | public function getThreadLastPost() |
||
| 370 | { |
||
| 371 | return $this->threadLastPost; |
||
| 372 | } |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Set threadDate. |
||
| 376 | * |
||
| 377 | * @param \DateTime $threadDate |
||
| 378 | * |
||
| 379 | * @return CForumThread |
||
| 380 | */ |
||
| 381 | public function setThreadDate($threadDate) |
||
| 382 | { |
||
| 383 | $this->threadDate = $threadDate; |
||
| 384 | |||
| 385 | return $this; |
||
| 386 | } |
||
| 387 | |||
| 388 | /** |
||
| 389 | * Get threadDate. |
||
| 390 | * |
||
| 391 | * @return \DateTime |
||
| 392 | */ |
||
| 393 | public function getThreadDate() |
||
| 394 | { |
||
| 395 | return $this->threadDate; |
||
| 396 | } |
||
| 397 | |||
| 398 | /** |
||
| 399 | * Set threadSticky. |
||
| 400 | * |
||
| 401 | * @param bool $threadSticky |
||
| 402 | * |
||
| 403 | * @return CForumThread |
||
| 404 | */ |
||
| 405 | public function setThreadSticky($threadSticky) |
||
| 406 | { |
||
| 407 | $this->threadSticky = $threadSticky; |
||
| 408 | |||
| 409 | return $this; |
||
| 410 | } |
||
| 411 | |||
| 412 | /** |
||
| 413 | * Get threadSticky. |
||
| 414 | * |
||
| 415 | * @return bool |
||
| 416 | */ |
||
| 417 | public function getThreadSticky() |
||
| 418 | { |
||
| 419 | return $this->threadSticky; |
||
| 420 | } |
||
| 421 | |||
| 422 | /** |
||
| 423 | * Set locked. |
||
| 424 | * |
||
| 425 | * @param int $locked |
||
| 426 | * |
||
| 427 | * @return CForumThread |
||
| 428 | */ |
||
| 429 | public function setLocked($locked) |
||
| 430 | { |
||
| 431 | $this->locked = $locked; |
||
| 432 | |||
| 433 | return $this; |
||
| 434 | } |
||
| 435 | |||
| 436 | /** |
||
| 437 | * Get locked. |
||
| 438 | * |
||
| 439 | * @return int |
||
| 440 | */ |
||
| 441 | public function getLocked() |
||
| 442 | { |
||
| 443 | return $this->locked; |
||
| 444 | } |
||
| 445 | |||
| 446 | /** |
||
| 447 | * Set sessionId. |
||
| 448 | * |
||
| 449 | * @param int $sessionId |
||
| 450 | * |
||
| 451 | * @return CForumThread |
||
| 452 | */ |
||
| 453 | public function setSessionId($sessionId) |
||
| 454 | { |
||
| 455 | $this->sessionId = $sessionId; |
||
| 456 | |||
| 457 | return $this; |
||
| 458 | } |
||
| 459 | |||
| 460 | /** |
||
| 461 | * Get sessionId. |
||
| 462 | * |
||
| 463 | * @return int |
||
| 464 | */ |
||
| 465 | public function getSessionId() |
||
| 466 | { |
||
| 467 | return $this->sessionId; |
||
| 468 | } |
||
| 469 | |||
| 470 | /** |
||
| 471 | * Set threadTitleQualify. |
||
| 472 | * |
||
| 473 | * @param string $threadTitleQualify |
||
| 474 | * |
||
| 475 | * @return CForumThread |
||
| 476 | */ |
||
| 477 | public function setThreadTitleQualify($threadTitleQualify) |
||
| 478 | { |
||
| 479 | $this->threadTitleQualify = $threadTitleQualify; |
||
| 480 | |||
| 481 | return $this; |
||
| 482 | } |
||
| 483 | |||
| 484 | /** |
||
| 485 | * Get threadTitleQualify. |
||
| 486 | * |
||
| 487 | * @return string |
||
| 488 | */ |
||
| 489 | public function getThreadTitleQualify() |
||
| 490 | { |
||
| 491 | return $this->threadTitleQualify; |
||
| 492 | } |
||
| 493 | |||
| 494 | /** |
||
| 495 | * Set threadQualifyMax. |
||
| 496 | * |
||
| 497 | * @param float $threadQualifyMax |
||
| 498 | * |
||
| 499 | * @return CForumThread |
||
| 500 | */ |
||
| 501 | public function setThreadQualifyMax($threadQualifyMax) |
||
| 502 | { |
||
| 503 | $this->threadQualifyMax = $threadQualifyMax; |
||
| 504 | |||
| 505 | return $this; |
||
| 506 | } |
||
| 507 | |||
| 508 | /** |
||
| 509 | * Get threadQualifyMax. |
||
| 510 | * |
||
| 511 | * @return float |
||
| 512 | */ |
||
| 513 | public function getThreadQualifyMax() |
||
| 514 | { |
||
| 515 | return $this->threadQualifyMax; |
||
| 516 | } |
||
| 517 | |||
| 518 | /** |
||
| 519 | * Set threadCloseDate. |
||
| 520 | * |
||
| 521 | * @param \DateTime $threadCloseDate |
||
| 522 | * |
||
| 523 | * @return CForumThread |
||
| 524 | */ |
||
| 525 | public function setThreadCloseDate($threadCloseDate) |
||
| 526 | { |
||
| 527 | $this->threadCloseDate = $threadCloseDate; |
||
| 528 | |||
| 529 | return $this; |
||
| 530 | } |
||
| 531 | |||
| 532 | /** |
||
| 533 | * Get threadCloseDate. |
||
| 534 | * |
||
| 535 | * @return \DateTime |
||
| 536 | */ |
||
| 537 | public function getThreadCloseDate() |
||
| 538 | { |
||
| 539 | return $this->threadCloseDate; |
||
| 540 | } |
||
| 541 | |||
| 542 | /** |
||
| 543 | * Set threadWeight. |
||
| 544 | * |
||
| 545 | * @param float $threadWeight |
||
| 546 | * |
||
| 547 | * @return CForumThread |
||
| 548 | */ |
||
| 549 | public function setThreadWeight($threadWeight) |
||
| 550 | { |
||
| 551 | $this->threadWeight = $threadWeight; |
||
| 552 | |||
| 553 | return $this; |
||
| 554 | } |
||
| 555 | |||
| 556 | /** |
||
| 557 | * Get threadWeight. |
||
| 558 | * |
||
| 559 | * @return float |
||
| 560 | */ |
||
| 561 | public function getThreadWeight() |
||
| 562 | { |
||
| 563 | return $this->threadWeight; |
||
| 564 | } |
||
| 565 | |||
| 566 | /** |
||
| 567 | * Set cId. |
||
| 568 | * |
||
| 569 | * @param int $cId |
||
| 570 | * |
||
| 571 | * @return CForumThread |
||
| 572 | */ |
||
| 573 | public function setCId($cId) |
||
| 578 | } |
||
| 579 | |||
| 580 | /** |
||
| 581 | * Get cId. |
||
| 582 | * |
||
| 583 | * @return int |
||
| 584 | */ |
||
| 585 | public function getCId() |
||
| 586 | { |
||
| 587 | return $this->cId; |
||
| 588 | } |
||
| 589 | |||
| 590 | /** |
||
| 591 | * Set lpItemId. |
||
| 592 | * |
||
| 593 | * @param int $lpItemId |
||
| 594 | * |
||
| 595 | * @return $this |
||
| 596 | */ |
||
| 597 | public function setLpItemId($lpItemId) |
||
| 598 | { |
||
| 599 | $this->lpItemId = $lpItemId; |
||
| 600 | |||
| 601 | return $this; |
||
| 602 | } |
||
| 603 | |||
| 604 | /** |
||
| 605 | * Get lpId. |
||
| 606 | * |
||
| 607 | * @return int |
||
| 608 | */ |
||
| 609 | public function getLpItemId() |
||
| 610 | { |
||
| 611 | return $this->lpItemId; |
||
| 612 | } |
||
| 613 | |||
| 614 | /** |
||
| 615 | * Get iid. |
||
| 616 | * |
||
| 617 | * @return int |
||
| 618 | */ |
||
| 619 | public function getIid() |
||
| 620 | { |
||
| 621 | return $this->iid; |
||
| 622 | } |
||
| 623 | |||
| 624 | /** |
||
| 625 | * @return ArrayCollection|CForumPost[] |
||
| 626 | */ |
||
| 627 | public function getPosts() |
||
| 628 | { |
||
| 629 | return $this->posts; |
||
| 630 | } |
||
| 631 | |||
| 632 | /** |
||
| 633 | * Resource identifier. |
||
| 634 | */ |
||
| 635 | public function getResourceIdentifier(): int |
||
| 636 | { |
||
| 637 | return $this->getIid(); |
||
| 638 | } |
||
| 639 | |||
| 640 | public function getResourceName(): string |
||
| 643 | } |
||
| 644 | |||
| 645 | public function setResourceName(string $name): self |
||
| 646 | { |
||
| 647 | return $this->setThreadTitle($name); |
||
| 648 | } |
||
| 649 | } |
||
| 650 |