Total Complexity | 54 |
Total Lines | 785 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Complex classes like CForumForum 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 CForumForum, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | class CForumForum 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 | * |
||
46 | * @Assert\NotBlank |
||
47 | * |
||
48 | * @ORM\Column(name="forum_title", type="string", length=255, nullable=false) |
||
49 | */ |
||
50 | protected $forumTitle; |
||
51 | |||
52 | /** |
||
53 | * @var string |
||
54 | * |
||
55 | * @ORM\Column(name="forum_comment", type="text", nullable=true) |
||
56 | */ |
||
57 | protected $forumComment; |
||
58 | |||
59 | /** |
||
60 | * @var int |
||
61 | * |
||
62 | * @ORM\Column(name="forum_threads", type="integer", nullable=true) |
||
63 | */ |
||
64 | protected $forumThreads; |
||
65 | |||
66 | /** |
||
67 | * @var int |
||
68 | * |
||
69 | * @ORM\Column(name="forum_posts", type="integer", nullable=true) |
||
70 | */ |
||
71 | protected $forumPosts; |
||
72 | |||
73 | /** |
||
74 | * @var int |
||
75 | * |
||
76 | * @ORM\Column(name="forum_last_post", type="integer", nullable=true) |
||
77 | */ |
||
78 | protected $forumLastPost; |
||
79 | |||
80 | /** |
||
81 | * @Gedmo\SortableGroup |
||
82 | * |
||
83 | * @var CForumCategory|null |
||
84 | * |
||
85 | * @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CForumCategory", inversedBy="forums") |
||
86 | * @ORM\JoinColumn(name="forum_category", referencedColumnName="iid", nullable=true, onDelete="SET NULL") |
||
87 | */ |
||
88 | protected $forumCategory; |
||
89 | |||
90 | /** |
||
91 | * @var int |
||
92 | * |
||
93 | * @ORM\Column(name="allow_anonymous", type="integer", nullable=true) |
||
94 | */ |
||
95 | protected $allowAnonymous; |
||
96 | |||
97 | /** |
||
98 | * @var int |
||
99 | * |
||
100 | * @ORM\Column(name="allow_edit", type="integer", nullable=true) |
||
101 | */ |
||
102 | protected $allowEdit; |
||
103 | |||
104 | /** |
||
105 | * @var string |
||
106 | * |
||
107 | * @ORM\Column(name="approval_direct_post", type="string", length=20, nullable=true) |
||
108 | */ |
||
109 | protected $approvalDirectPost; |
||
110 | |||
111 | /** |
||
112 | * @var int |
||
113 | * |
||
114 | * @ORM\Column(name="allow_attachments", type="integer", nullable=true) |
||
115 | */ |
||
116 | protected $allowAttachments; |
||
117 | |||
118 | /** |
||
119 | * @var int |
||
120 | * |
||
121 | * @ORM\Column(name="allow_new_threads", type="integer", nullable=true) |
||
122 | */ |
||
123 | protected $allowNewThreads; |
||
124 | |||
125 | /** |
||
126 | * @var string |
||
127 | * |
||
128 | * @ORM\Column(name="default_view", type="string", length=20, nullable=true) |
||
129 | */ |
||
130 | protected $defaultView; |
||
131 | |||
132 | /** |
||
133 | * @var string |
||
134 | * |
||
135 | * @ORM\Column(name="forum_of_group", type="string", length=20, nullable=true) |
||
136 | */ |
||
137 | protected $forumOfGroup; |
||
138 | |||
139 | /** |
||
140 | * @var string |
||
141 | * |
||
142 | * @ORM\Column(name="forum_group_public_private", type="string", length=20, nullable=true) |
||
143 | */ |
||
144 | protected $forumGroupPublicPrivate; |
||
145 | |||
146 | /** |
||
147 | * @var int |
||
148 | * @Gedmo\SortablePosition |
||
149 | * |
||
150 | * @ORM\Column(name="forum_order", type="integer", nullable=true) |
||
151 | */ |
||
152 | protected $forumOrder; |
||
153 | |||
154 | /** |
||
155 | * @var int |
||
156 | * |
||
157 | * @ORM\Column(name="locked", type="integer", nullable=false) |
||
158 | */ |
||
159 | protected $locked; |
||
160 | |||
161 | /** |
||
162 | * @var int |
||
163 | * |
||
164 | * @ORM\Column(name="session_id", type="integer", nullable=false) |
||
165 | */ |
||
166 | protected $sessionId; |
||
167 | |||
168 | /** |
||
169 | * @var string |
||
170 | * |
||
171 | * @ORM\Column(name="forum_image", type="string", length=255, nullable=false) |
||
172 | */ |
||
173 | protected $forumImage; |
||
174 | |||
175 | /** |
||
176 | * @var \DateTime |
||
177 | * |
||
178 | * @ORM\Column(name="start_time", type="datetime", nullable=true) |
||
179 | */ |
||
180 | protected $startTime; |
||
181 | |||
182 | /** |
||
183 | * @var \DateTime |
||
184 | * |
||
185 | * @ORM\Column(name="end_time", type="datetime", nullable=true) |
||
186 | */ |
||
187 | protected $endTime; |
||
188 | |||
189 | /** |
||
190 | * @var int |
||
191 | * |
||
192 | * @ORM\Column(name="lp_id", type="integer", options={"unsigned":true}) |
||
193 | */ |
||
194 | protected $lpId; |
||
195 | |||
196 | /** |
||
197 | * @var bool |
||
198 | * |
||
199 | * @ORM\Column(name="moderated", type="boolean", nullable=true) |
||
200 | */ |
||
201 | protected $moderated; |
||
202 | |||
203 | /** |
||
204 | * @var ArrayCollection|CForumThread[] |
||
205 | * |
||
206 | * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CForumThread", mappedBy="forum") |
||
207 | */ |
||
208 | protected $threads; |
||
209 | |||
210 | /** |
||
211 | * @var ArrayCollection|CForumPost[] |
||
212 | * |
||
213 | * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CForumPost", mappedBy="forum") |
||
214 | */ |
||
215 | protected $posts; |
||
216 | |||
217 | /** |
||
218 | * CForumForum constructor. |
||
219 | */ |
||
220 | public function __construct() |
||
221 | { |
||
222 | $this->threads = new ArrayCollection(); |
||
223 | $this->posts = new ArrayCollection(); |
||
224 | $this->locked = 0; |
||
225 | $this->forumImage = ''; |
||
226 | $this->forumOfGroup = 0; |
||
227 | $this->forumPosts = 0; |
||
228 | $this->forumGroupPublicPrivate = ''; |
||
229 | } |
||
230 | |||
231 | public function __toString(): string |
||
232 | { |
||
233 | return $this->getForumTitle(); |
||
234 | } |
||
235 | |||
236 | /** |
||
237 | * Set forumTitle. |
||
238 | * |
||
239 | * @param string $forumTitle |
||
240 | * |
||
241 | * @return CForumForum |
||
242 | */ |
||
243 | public function setForumTitle($forumTitle) |
||
244 | { |
||
245 | $this->forumTitle = $forumTitle; |
||
246 | |||
247 | return $this; |
||
248 | } |
||
249 | |||
250 | /** |
||
251 | * Get forumTitle. |
||
252 | * |
||
253 | * @return string |
||
254 | */ |
||
255 | public function getForumTitle() |
||
256 | { |
||
257 | return $this->forumTitle; |
||
258 | } |
||
259 | |||
260 | /** |
||
261 | * Set forumComment. |
||
262 | * |
||
263 | * @param string $forumComment |
||
264 | */ |
||
265 | public function setForumComment($forumComment): self |
||
266 | { |
||
267 | $this->forumComment = $forumComment; |
||
268 | |||
269 | return $this; |
||
270 | } |
||
271 | |||
272 | /** |
||
273 | * Get forumComment. |
||
274 | * |
||
275 | * @return string |
||
276 | */ |
||
277 | public function getForumComment() |
||
278 | { |
||
279 | return $this->forumComment; |
||
280 | } |
||
281 | |||
282 | /** |
||
283 | * Set forumThreads. |
||
284 | * |
||
285 | * @param int $forumThreads |
||
286 | */ |
||
287 | public function setForumThreads($forumThreads): self |
||
288 | { |
||
289 | $this->forumThreads = $forumThreads; |
||
290 | |||
291 | return $this; |
||
292 | } |
||
293 | |||
294 | /** |
||
295 | * Get forumThreads. |
||
296 | * |
||
297 | * @return int |
||
298 | */ |
||
299 | public function getForumThreads() |
||
300 | { |
||
301 | return $this->forumThreads; |
||
302 | } |
||
303 | |||
304 | public function hasThread($thread) |
||
305 | { |
||
306 | return $this->threads->contains($thread); |
||
307 | } |
||
308 | |||
309 | /** |
||
310 | * Set forumPosts. |
||
311 | * |
||
312 | * @param int $forumPosts |
||
313 | * |
||
314 | * @return CForumForum |
||
315 | */ |
||
316 | public function setForumPosts($forumPosts) |
||
317 | { |
||
318 | $this->forumPosts = $forumPosts; |
||
319 | |||
320 | return $this; |
||
321 | } |
||
322 | |||
323 | /** |
||
324 | * Get forumPosts. |
||
325 | * |
||
326 | * @return int |
||
327 | */ |
||
328 | public function getForumPosts() |
||
329 | { |
||
330 | return $this->forumPosts; |
||
331 | } |
||
332 | |||
333 | /** |
||
334 | * Set forumLastPost. |
||
335 | * |
||
336 | * @param int $forumLastPost |
||
337 | * |
||
338 | * @return CForumForum |
||
339 | */ |
||
340 | public function setForumLastPost($forumLastPost) |
||
341 | { |
||
342 | $this->forumLastPost = $forumLastPost; |
||
343 | |||
344 | return $this; |
||
345 | } |
||
346 | |||
347 | /** |
||
348 | * Get forumLastPost. |
||
349 | * |
||
350 | * @return int |
||
351 | */ |
||
352 | public function getForumLastPost() |
||
353 | { |
||
354 | return $this->forumLastPost; |
||
355 | } |
||
356 | |||
357 | /** |
||
358 | * Set forumCategory. |
||
359 | * |
||
360 | * @return CForumForum |
||
361 | */ |
||
362 | public function setForumCategory(CForumCategory $forumCategory = null) |
||
363 | { |
||
364 | $this->forumCategory = $forumCategory; |
||
365 | |||
366 | return $this; |
||
367 | } |
||
368 | |||
369 | /** |
||
370 | * Get forumCategory. |
||
371 | * |
||
372 | * @return CForumCategory|null |
||
373 | */ |
||
374 | public function getForumCategory() |
||
375 | { |
||
376 | return $this->forumCategory; |
||
377 | } |
||
378 | |||
379 | /** |
||
380 | * Set allowAnonymous. |
||
381 | * |
||
382 | * @param int $allowAnonymous |
||
383 | * |
||
384 | * @return CForumForum |
||
385 | */ |
||
386 | public function setAllowAnonymous($allowAnonymous) |
||
387 | { |
||
388 | $this->allowAnonymous = $allowAnonymous; |
||
389 | |||
390 | return $this; |
||
391 | } |
||
392 | |||
393 | /** |
||
394 | * Get allowAnonymous. |
||
395 | * |
||
396 | * @return int |
||
397 | */ |
||
398 | public function getAllowAnonymous() |
||
399 | { |
||
400 | return $this->allowAnonymous; |
||
401 | } |
||
402 | |||
403 | /** |
||
404 | * Set allowEdit. |
||
405 | * |
||
406 | * @param int $allowEdit |
||
407 | * |
||
408 | * @return CForumForum |
||
409 | */ |
||
410 | public function setAllowEdit($allowEdit) |
||
411 | { |
||
412 | $this->allowEdit = $allowEdit; |
||
413 | |||
414 | return $this; |
||
415 | } |
||
416 | |||
417 | /** |
||
418 | * Get allowEdit. |
||
419 | * |
||
420 | * @return int |
||
421 | */ |
||
422 | public function getAllowEdit() |
||
423 | { |
||
424 | return $this->allowEdit; |
||
425 | } |
||
426 | |||
427 | /** |
||
428 | * Set approvalDirectPost. |
||
429 | * |
||
430 | * @param string $approvalDirectPost |
||
431 | * |
||
432 | * @return CForumForum |
||
433 | */ |
||
434 | public function setApprovalDirectPost($approvalDirectPost) |
||
435 | { |
||
436 | $this->approvalDirectPost = $approvalDirectPost; |
||
437 | |||
438 | return $this; |
||
439 | } |
||
440 | |||
441 | /** |
||
442 | * Get approvalDirectPost. |
||
443 | * |
||
444 | * @return string |
||
445 | */ |
||
446 | public function getApprovalDirectPost() |
||
447 | { |
||
448 | return $this->approvalDirectPost; |
||
449 | } |
||
450 | |||
451 | /** |
||
452 | * Set allowAttachments. |
||
453 | * |
||
454 | * @param int $allowAttachments |
||
455 | * |
||
456 | * @return CForumForum |
||
457 | */ |
||
458 | public function setAllowAttachments($allowAttachments) |
||
459 | { |
||
460 | $this->allowAttachments = $allowAttachments; |
||
461 | |||
462 | return $this; |
||
463 | } |
||
464 | |||
465 | /** |
||
466 | * Get allowAttachments. |
||
467 | * |
||
468 | * @return int |
||
469 | */ |
||
470 | public function getAllowAttachments() |
||
471 | { |
||
472 | return $this->allowAttachments; |
||
473 | } |
||
474 | |||
475 | /** |
||
476 | * Set allowNewThreads. |
||
477 | * |
||
478 | * @param int $allowNewThreads |
||
479 | * |
||
480 | * @return CForumForum |
||
481 | */ |
||
482 | public function setAllowNewThreads($allowNewThreads) |
||
483 | { |
||
484 | $this->allowNewThreads = $allowNewThreads; |
||
485 | |||
486 | return $this; |
||
487 | } |
||
488 | |||
489 | /** |
||
490 | * Get allowNewThreads. |
||
491 | * |
||
492 | * @return int |
||
493 | */ |
||
494 | public function getAllowNewThreads() |
||
495 | { |
||
496 | return $this->allowNewThreads; |
||
497 | } |
||
498 | |||
499 | /** |
||
500 | * Set defaultView. |
||
501 | * |
||
502 | * @param string $defaultView |
||
503 | * |
||
504 | * @return CForumForum |
||
505 | */ |
||
506 | public function setDefaultView($defaultView) |
||
507 | { |
||
508 | $this->defaultView = $defaultView; |
||
509 | |||
510 | return $this; |
||
511 | } |
||
512 | |||
513 | /** |
||
514 | * Get defaultView. |
||
515 | * |
||
516 | * @return string |
||
517 | */ |
||
518 | public function getDefaultView() |
||
519 | { |
||
520 | return $this->defaultView; |
||
521 | } |
||
522 | |||
523 | /** |
||
524 | * Set forumOfGroup. |
||
525 | * |
||
526 | * @param string $forumOfGroup |
||
527 | * |
||
528 | * @return CForumForum |
||
529 | */ |
||
530 | public function setForumOfGroup($forumOfGroup) |
||
531 | { |
||
532 | $this->forumOfGroup = $forumOfGroup; |
||
533 | |||
534 | return $this; |
||
535 | } |
||
536 | |||
537 | /** |
||
538 | * Get forumOfGroup. |
||
539 | * |
||
540 | * @return string |
||
541 | */ |
||
542 | public function getForumOfGroup() |
||
543 | { |
||
544 | return $this->forumOfGroup; |
||
545 | } |
||
546 | |||
547 | public function getForumGroupPublicPrivate(): string |
||
548 | { |
||
549 | return $this->forumGroupPublicPrivate; |
||
550 | } |
||
551 | |||
552 | /** |
||
553 | * @return $this |
||
554 | */ |
||
555 | public function setForumGroupPublicPrivate(string $forumGroupPublicPrivate) |
||
556 | { |
||
557 | $this->forumGroupPublicPrivate = $forumGroupPublicPrivate; |
||
558 | |||
559 | return $this; |
||
560 | } |
||
561 | |||
562 | /** |
||
563 | * Set forumOrder. |
||
564 | * |
||
565 | * @param int $forumOrder |
||
566 | * |
||
567 | * @return CForumForum |
||
568 | */ |
||
569 | public function setForumOrder($forumOrder) |
||
570 | { |
||
571 | $this->forumOrder = $forumOrder; |
||
572 | |||
573 | return $this; |
||
574 | } |
||
575 | |||
576 | /** |
||
577 | * Get forumOrder. |
||
578 | * |
||
579 | * @return int |
||
580 | */ |
||
581 | public function getForumOrder() |
||
582 | { |
||
583 | return $this->forumOrder; |
||
584 | } |
||
585 | |||
586 | /** |
||
587 | * Set locked. |
||
588 | * |
||
589 | * @param int $locked |
||
590 | * |
||
591 | * @return CForumForum |
||
592 | */ |
||
593 | public function setLocked($locked) |
||
594 | { |
||
595 | $this->locked = $locked; |
||
596 | |||
597 | return $this; |
||
598 | } |
||
599 | |||
600 | /** |
||
601 | * Get locked. |
||
602 | * |
||
603 | * @return int |
||
604 | */ |
||
605 | public function getLocked() |
||
606 | { |
||
607 | return $this->locked; |
||
608 | } |
||
609 | |||
610 | /** |
||
611 | * Set sessionId. |
||
612 | * |
||
613 | * @param int $sessionId |
||
614 | * |
||
615 | * @return CForumForum |
||
616 | */ |
||
617 | public function setSessionId($sessionId) |
||
618 | { |
||
619 | $this->sessionId = $sessionId; |
||
620 | |||
621 | return $this; |
||
622 | } |
||
623 | |||
624 | /** |
||
625 | * Get sessionId. |
||
626 | * |
||
627 | * @return int |
||
628 | */ |
||
629 | public function getSessionId() |
||
630 | { |
||
631 | return $this->sessionId; |
||
632 | } |
||
633 | |||
634 | /** |
||
635 | * Set forumImage. |
||
636 | * |
||
637 | * @param string $forumImage |
||
638 | * |
||
639 | * @return CForumForum |
||
640 | */ |
||
641 | public function setForumImage($forumImage) |
||
642 | { |
||
643 | $this->forumImage = $forumImage; |
||
644 | |||
645 | return $this; |
||
646 | } |
||
647 | |||
648 | /** |
||
649 | * Get forumImage. |
||
650 | * |
||
651 | * @return string |
||
652 | */ |
||
653 | public function getForumImage() |
||
654 | { |
||
655 | return $this->forumImage; |
||
656 | } |
||
657 | |||
658 | /** |
||
659 | * Set startTime. |
||
660 | * |
||
661 | * @param \DateTime $startTime |
||
662 | * |
||
663 | * @return CForumForum |
||
664 | */ |
||
665 | public function setStartTime($startTime) |
||
666 | { |
||
667 | $this->startTime = $startTime; |
||
668 | |||
669 | return $this; |
||
670 | } |
||
671 | |||
672 | /** |
||
673 | * Get startTime. |
||
674 | * |
||
675 | * @return \DateTime |
||
676 | */ |
||
677 | public function getStartTime() |
||
678 | { |
||
679 | return $this->startTime; |
||
680 | } |
||
681 | |||
682 | /** |
||
683 | * Set endTime. |
||
684 | * |
||
685 | * @param \DateTime $endTime |
||
686 | * |
||
687 | * @return CForumForum |
||
688 | */ |
||
689 | public function setEndTime($endTime) |
||
690 | { |
||
691 | $this->endTime = $endTime; |
||
692 | |||
693 | return $this; |
||
694 | } |
||
695 | |||
696 | /** |
||
697 | * Get endTime. |
||
698 | * |
||
699 | * @return \DateTime |
||
700 | */ |
||
701 | public function getEndTime() |
||
702 | { |
||
703 | return $this->endTime; |
||
704 | } |
||
705 | |||
706 | /** |
||
707 | * Set cId. |
||
708 | * |
||
709 | * @param int $cId |
||
710 | * |
||
711 | * @return CForumForum |
||
712 | */ |
||
713 | public function setCId($cId) |
||
714 | { |
||
715 | $this->cId = $cId; |
||
716 | |||
717 | return $this; |
||
718 | } |
||
719 | |||
720 | /** |
||
721 | * Get cId. |
||
722 | * |
||
723 | * @return int |
||
724 | */ |
||
725 | public function getCId() |
||
726 | { |
||
727 | return $this->cId; |
||
728 | } |
||
729 | |||
730 | /** |
||
731 | * Set lpId. |
||
732 | * |
||
733 | * @param int $lpId |
||
734 | * |
||
735 | * @return CForumForum |
||
736 | */ |
||
737 | public function setLpId($lpId) |
||
742 | } |
||
743 | |||
744 | /** |
||
745 | * Get lpId. |
||
746 | * |
||
747 | * @return int |
||
748 | */ |
||
749 | public function getLpId() |
||
750 | { |
||
751 | return $this->lpId; |
||
752 | } |
||
753 | |||
754 | /** |
||
755 | * @return bool |
||
756 | */ |
||
757 | public function isModerated() |
||
758 | { |
||
759 | return $this->moderated; |
||
760 | } |
||
761 | |||
762 | /** |
||
763 | * @param $moderated |
||
764 | * |
||
765 | * @return $this |
||
766 | */ |
||
767 | public function setModerated($moderated) |
||
768 | { |
||
769 | $this->moderated = $moderated; |
||
770 | |||
771 | return $this; |
||
772 | } |
||
773 | |||
774 | /** |
||
775 | * Get iid. |
||
776 | * |
||
777 | * @return int |
||
778 | */ |
||
779 | public function getIid() |
||
782 | } |
||
783 | |||
784 | /** |
||
785 | * Get threads. |
||
786 | * |
||
787 | * @return ArrayCollection|CForumThread[] |
||
788 | */ |
||
789 | public function getThreads() |
||
792 | } |
||
793 | |||
794 | /** |
||
795 | * Resource identifier. |
||
796 | */ |
||
797 | public function getResourceIdentifier(): int |
||
798 | { |
||
799 | return $this->getIid(); |
||
800 | } |
||
801 | |||
802 | public function getResourceName(): string |
||
805 | } |
||
806 | |||
807 | public function setResourceName(string $name): self |
||
808 | { |
||
809 | return $this->setForumTitle($name); |
||
810 | } |
||
811 | } |
||
812 |