Total Complexity | 58 |
Total Lines | 881 |
Duplicated Lines | 0 % |
Changes | 0 |
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.
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 |
||
25 | class CWiki |
||
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 int |
||
45 | * |
||
46 | * @ORM\Column(name="id", type="integer", nullable=true) |
||
47 | */ |
||
48 | protected $id; |
||
49 | |||
50 | /** |
||
51 | * @var int |
||
52 | * |
||
53 | * @ORM\Column(name="page_id", type="integer", nullable=true) |
||
54 | */ |
||
55 | protected $pageId; |
||
56 | |||
57 | /** |
||
58 | * @var string |
||
59 | * |
||
60 | * @ORM\Column(name="reflink", type="string", length=255, nullable=false) |
||
61 | */ |
||
62 | protected $reflink; |
||
63 | |||
64 | /** |
||
65 | * @var string |
||
66 | * |
||
67 | * @ORM\Column(name="title", type="string", length=255, nullable=false) |
||
68 | */ |
||
69 | protected $title; |
||
70 | |||
71 | /** |
||
72 | * @var string |
||
73 | * |
||
74 | * @ORM\Column(name="content", type="text", nullable=false) |
||
75 | */ |
||
76 | protected $content; |
||
77 | |||
78 | /** |
||
79 | * @var int |
||
80 | * |
||
81 | * @ORM\Column(name="user_id", type="integer", nullable=false) |
||
82 | */ |
||
83 | protected $userId; |
||
84 | |||
85 | /** |
||
86 | * @var int |
||
87 | * |
||
88 | * @ORM\Column(name="group_id", type="integer", nullable=true) |
||
89 | */ |
||
90 | protected $groupId; |
||
91 | |||
92 | /** |
||
93 | * @var \DateTime |
||
94 | * |
||
95 | * @ORM\Column(name="dtime", type="datetime", nullable=true) |
||
96 | */ |
||
97 | protected $dtime; |
||
98 | |||
99 | /** |
||
100 | * @var int |
||
101 | * |
||
102 | * @ORM\Column(name="addlock", type="integer", nullable=false) |
||
103 | */ |
||
104 | protected $addlock; |
||
105 | |||
106 | /** |
||
107 | * @var int |
||
108 | * |
||
109 | * @ORM\Column(name="editlock", type="integer", nullable=false) |
||
110 | */ |
||
111 | protected $editlock; |
||
112 | |||
113 | /** |
||
114 | * @var int |
||
115 | * |
||
116 | * @ORM\Column(name="visibility", type="integer", nullable=false) |
||
117 | */ |
||
118 | protected $visibility; |
||
119 | |||
120 | /** |
||
121 | * @var int |
||
122 | * |
||
123 | * @ORM\Column(name="addlock_disc", type="integer", nullable=false) |
||
124 | */ |
||
125 | protected $addlockDisc; |
||
126 | |||
127 | /** |
||
128 | * @var int |
||
129 | * |
||
130 | * @ORM\Column(name="visibility_disc", type="integer", nullable=false) |
||
131 | */ |
||
132 | protected $visibilityDisc; |
||
133 | |||
134 | /** |
||
135 | * @var int |
||
136 | * |
||
137 | * @ORM\Column(name="ratinglock_disc", type="integer", nullable=false) |
||
138 | */ |
||
139 | protected $ratinglockDisc; |
||
140 | |||
141 | /** |
||
142 | * @var int |
||
143 | * |
||
144 | * @ORM\Column(name="assignment", type="integer", nullable=false) |
||
145 | */ |
||
146 | protected $assignment; |
||
147 | |||
148 | /** |
||
149 | * @var string |
||
150 | * |
||
151 | * @ORM\Column(name="comment", type="text", nullable=false) |
||
152 | */ |
||
153 | protected $comment; |
||
154 | |||
155 | /** |
||
156 | * @var string |
||
157 | * |
||
158 | * @ORM\Column(name="progress", type="text", nullable=false) |
||
159 | */ |
||
160 | protected $progress; |
||
161 | |||
162 | /** |
||
163 | * @var int |
||
164 | * |
||
165 | * @ORM\Column(name="score", type="integer", nullable=true) |
||
166 | */ |
||
167 | protected $score; |
||
168 | |||
169 | /** |
||
170 | * @var int |
||
171 | * |
||
172 | * @ORM\Column(name="version", type="integer", nullable=true) |
||
173 | */ |
||
174 | protected $version; |
||
175 | |||
176 | /** |
||
177 | * @var int |
||
178 | * |
||
179 | * @ORM\Column(name="is_editing", type="integer", nullable=false) |
||
180 | */ |
||
181 | protected $isEditing; |
||
182 | |||
183 | /** |
||
184 | * @var \DateTime |
||
185 | * |
||
186 | * @ORM\Column(name="time_edit", type="datetime", nullable=true) |
||
187 | */ |
||
188 | protected $timeEdit; |
||
189 | |||
190 | /** |
||
191 | * @var int |
||
192 | * |
||
193 | * @ORM\Column(name="hits", type="integer", nullable=true) |
||
194 | */ |
||
195 | protected $hits; |
||
196 | |||
197 | /** |
||
198 | * @var string |
||
199 | * |
||
200 | * @ORM\Column(name="linksto", type="text", nullable=false) |
||
201 | */ |
||
202 | protected $linksto; |
||
203 | |||
204 | /** |
||
205 | * @var string |
||
206 | * |
||
207 | * @ORM\Column(name="tag", type="text", nullable=false) |
||
208 | */ |
||
209 | protected $tag; |
||
210 | |||
211 | /** |
||
212 | * @var string |
||
213 | * |
||
214 | * @ORM\Column(name="user_ip", type="string", length=39, nullable=false) |
||
215 | */ |
||
216 | protected $userIp; |
||
217 | |||
218 | /** |
||
219 | * @var int |
||
220 | * |
||
221 | * @ORM\Column(name="session_id", type="integer", nullable=true) |
||
222 | */ |
||
223 | protected $sessionId; |
||
224 | /** |
||
225 | * @var Collection<int, CWikiCategory> |
||
226 | * |
||
227 | * Add @ to the next lines if api_get_configuration_value('wiki_categories_enabled') is true |
||
228 | * ORM\ManyToMany(targetEntity="Chamilo\CourseBundle\Entity\CWikiCategory", inversedBy="wikiPages") |
||
229 | * ORM\JoinTable( |
||
230 | * name="c_wiki_rel_category", |
||
231 | * joinColumns={@ORM\JoinColumn(name="wiki_id", referencedColumnName="iid", onDelete="CASCADE")}, |
||
232 | * inverseJoinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id", onDelete="CASCADE")} |
||
233 | * ) |
||
234 | */ |
||
235 | private $categories; |
||
236 | |||
237 | public function __construct() |
||
238 | { |
||
239 | $this->categories = new ArrayCollection(); |
||
240 | } |
||
241 | |||
242 | /** |
||
243 | * Set pageId. |
||
244 | * |
||
245 | * @param int $pageId |
||
246 | * |
||
247 | * @return CWiki |
||
248 | */ |
||
249 | public function setPageId($pageId) |
||
250 | { |
||
251 | $this->pageId = $pageId; |
||
252 | |||
253 | return $this; |
||
254 | } |
||
255 | |||
256 | /** |
||
257 | * Get pageId. |
||
258 | * |
||
259 | * @return int |
||
260 | */ |
||
261 | public function getPageId() |
||
262 | { |
||
263 | return $this->pageId; |
||
264 | } |
||
265 | |||
266 | /** |
||
267 | * Set reflink. |
||
268 | * |
||
269 | * @param string $reflink |
||
270 | * |
||
271 | * @return CWiki |
||
272 | */ |
||
273 | public function setReflink($reflink) |
||
274 | { |
||
275 | $this->reflink = $reflink; |
||
276 | |||
277 | return $this; |
||
278 | } |
||
279 | |||
280 | /** |
||
281 | * Get reflink. |
||
282 | * |
||
283 | * @return string |
||
284 | */ |
||
285 | public function getReflink() |
||
286 | { |
||
287 | return $this->reflink; |
||
288 | } |
||
289 | |||
290 | /** |
||
291 | * Set title. |
||
292 | * |
||
293 | * @param string $title |
||
294 | * |
||
295 | * @return CWiki |
||
296 | */ |
||
297 | public function setTitle($title) |
||
298 | { |
||
299 | $this->title = $title; |
||
300 | |||
301 | return $this; |
||
302 | } |
||
303 | |||
304 | /** |
||
305 | * Get title. |
||
306 | * |
||
307 | * @return string |
||
308 | */ |
||
309 | public function getTitle() |
||
310 | { |
||
311 | return $this->title; |
||
312 | } |
||
313 | |||
314 | /** |
||
315 | * Set content. |
||
316 | * |
||
317 | * @param string $content |
||
318 | * |
||
319 | * @return CWiki |
||
320 | */ |
||
321 | public function setContent($content) |
||
322 | { |
||
323 | $this->content = $content; |
||
324 | |||
325 | return $this; |
||
326 | } |
||
327 | |||
328 | /** |
||
329 | * Get content. |
||
330 | * |
||
331 | * @return string |
||
332 | */ |
||
333 | public function getContent() |
||
334 | { |
||
335 | return $this->content; |
||
336 | } |
||
337 | |||
338 | /** |
||
339 | * Set userId. |
||
340 | * |
||
341 | * @param int $userId |
||
342 | * |
||
343 | * @return CWiki |
||
344 | */ |
||
345 | public function setUserId($userId) |
||
346 | { |
||
347 | $this->userId = $userId; |
||
348 | |||
349 | return $this; |
||
350 | } |
||
351 | |||
352 | /** |
||
353 | * Get userId. |
||
354 | * |
||
355 | * @return int |
||
356 | */ |
||
357 | public function getUserId() |
||
358 | { |
||
359 | return $this->userId; |
||
360 | } |
||
361 | |||
362 | /** |
||
363 | * Set groupId. |
||
364 | * |
||
365 | * @param int $groupId |
||
366 | * |
||
367 | * @return CWiki |
||
368 | */ |
||
369 | public function setGroupId($groupId) |
||
370 | { |
||
371 | $this->groupId = $groupId; |
||
372 | |||
373 | return $this; |
||
374 | } |
||
375 | |||
376 | /** |
||
377 | * Get groupId. |
||
378 | * |
||
379 | * @return int |
||
380 | */ |
||
381 | public function getGroupId() |
||
382 | { |
||
383 | return $this->groupId; |
||
384 | } |
||
385 | |||
386 | /** |
||
387 | * Set dtime. |
||
388 | * |
||
389 | * @param \DateTime $dtime |
||
390 | * |
||
391 | * @return CWiki |
||
392 | */ |
||
393 | public function setDtime($dtime) |
||
394 | { |
||
395 | $this->dtime = $dtime; |
||
396 | |||
397 | return $this; |
||
398 | } |
||
399 | |||
400 | /** |
||
401 | * Get dtime. |
||
402 | * |
||
403 | * @return \DateTime |
||
404 | */ |
||
405 | public function getDtime() |
||
406 | { |
||
407 | return $this->dtime; |
||
408 | } |
||
409 | |||
410 | /** |
||
411 | * Set addlock. |
||
412 | * |
||
413 | * @param int $addlock |
||
414 | * |
||
415 | * @return CWiki |
||
416 | */ |
||
417 | public function setAddlock($addlock) |
||
418 | { |
||
419 | $this->addlock = $addlock; |
||
420 | |||
421 | return $this; |
||
422 | } |
||
423 | |||
424 | /** |
||
425 | * Get addlock. |
||
426 | * |
||
427 | * @return int |
||
428 | */ |
||
429 | public function getAddlock() |
||
430 | { |
||
431 | return $this->addlock; |
||
432 | } |
||
433 | |||
434 | /** |
||
435 | * Set editlock. |
||
436 | * |
||
437 | * @param int $editlock |
||
438 | * |
||
439 | * @return CWiki |
||
440 | */ |
||
441 | public function setEditlock($editlock) |
||
442 | { |
||
443 | $this->editlock = $editlock; |
||
444 | |||
445 | return $this; |
||
446 | } |
||
447 | |||
448 | /** |
||
449 | * Get editlock. |
||
450 | * |
||
451 | * @return int |
||
452 | */ |
||
453 | public function getEditlock() |
||
454 | { |
||
455 | return $this->editlock; |
||
456 | } |
||
457 | |||
458 | /** |
||
459 | * Set visibility. |
||
460 | * |
||
461 | * @param int $visibility |
||
462 | * |
||
463 | * @return CWiki |
||
464 | */ |
||
465 | public function setVisibility($visibility) |
||
466 | { |
||
467 | $this->visibility = $visibility; |
||
468 | |||
469 | return $this; |
||
470 | } |
||
471 | |||
472 | /** |
||
473 | * Get visibility. |
||
474 | * |
||
475 | * @return int |
||
476 | */ |
||
477 | public function getVisibility() |
||
478 | { |
||
479 | return $this->visibility; |
||
480 | } |
||
481 | |||
482 | /** |
||
483 | * Set addlockDisc. |
||
484 | * |
||
485 | * @param int $addlockDisc |
||
486 | * |
||
487 | * @return CWiki |
||
488 | */ |
||
489 | public function setAddlockDisc($addlockDisc) |
||
490 | { |
||
491 | $this->addlockDisc = $addlockDisc; |
||
492 | |||
493 | return $this; |
||
494 | } |
||
495 | |||
496 | /** |
||
497 | * Get addlockDisc. |
||
498 | * |
||
499 | * @return int |
||
500 | */ |
||
501 | public function getAddlockDisc() |
||
502 | { |
||
503 | return $this->addlockDisc; |
||
504 | } |
||
505 | |||
506 | /** |
||
507 | * Set visibilityDisc. |
||
508 | * |
||
509 | * @param int $visibilityDisc |
||
510 | * |
||
511 | * @return CWiki |
||
512 | */ |
||
513 | public function setVisibilityDisc($visibilityDisc) |
||
514 | { |
||
515 | $this->visibilityDisc = $visibilityDisc; |
||
516 | |||
517 | return $this; |
||
518 | } |
||
519 | |||
520 | /** |
||
521 | * Get visibilityDisc. |
||
522 | * |
||
523 | * @return int |
||
524 | */ |
||
525 | public function getVisibilityDisc() |
||
526 | { |
||
527 | return $this->visibilityDisc; |
||
528 | } |
||
529 | |||
530 | /** |
||
531 | * Set ratinglockDisc. |
||
532 | * |
||
533 | * @param int $ratinglockDisc |
||
534 | * |
||
535 | * @return CWiki |
||
536 | */ |
||
537 | public function setRatinglockDisc($ratinglockDisc) |
||
538 | { |
||
539 | $this->ratinglockDisc = $ratinglockDisc; |
||
540 | |||
541 | return $this; |
||
542 | } |
||
543 | |||
544 | /** |
||
545 | * Get ratinglockDisc. |
||
546 | * |
||
547 | * @return int |
||
548 | */ |
||
549 | public function getRatinglockDisc() |
||
550 | { |
||
551 | return $this->ratinglockDisc; |
||
552 | } |
||
553 | |||
554 | /** |
||
555 | * Set assignment. |
||
556 | * |
||
557 | * @param int $assignment |
||
558 | * |
||
559 | * @return CWiki |
||
560 | */ |
||
561 | public function setAssignment($assignment) |
||
562 | { |
||
563 | $this->assignment = $assignment; |
||
564 | |||
565 | return $this; |
||
566 | } |
||
567 | |||
568 | /** |
||
569 | * Get assignment. |
||
570 | * |
||
571 | * @return int |
||
572 | */ |
||
573 | public function getAssignment() |
||
576 | } |
||
577 | |||
578 | /** |
||
579 | * Set comment. |
||
580 | * |
||
581 | * @param string $comment |
||
582 | * |
||
583 | * @return CWiki |
||
584 | */ |
||
585 | public function setComment($comment) |
||
586 | { |
||
587 | $this->comment = $comment; |
||
588 | |||
589 | return $this; |
||
590 | } |
||
591 | |||
592 | /** |
||
593 | * Get comment. |
||
594 | * |
||
595 | * @return string |
||
596 | */ |
||
597 | public function getComment() |
||
598 | { |
||
599 | return $this->comment; |
||
600 | } |
||
601 | |||
602 | /** |
||
603 | * Set progress. |
||
604 | * |
||
605 | * @param string $progress |
||
606 | * |
||
607 | * @return CWiki |
||
608 | */ |
||
609 | public function setProgress($progress) |
||
610 | { |
||
611 | $this->progress = $progress; |
||
612 | |||
613 | return $this; |
||
614 | } |
||
615 | |||
616 | /** |
||
617 | * Get progress. |
||
618 | * |
||
619 | * @return string |
||
620 | */ |
||
621 | public function getProgress() |
||
622 | { |
||
623 | return $this->progress; |
||
624 | } |
||
625 | |||
626 | /** |
||
627 | * Set score. |
||
628 | * |
||
629 | * @param int $score |
||
630 | * |
||
631 | * @return CWiki |
||
632 | */ |
||
633 | public function setScore($score) |
||
634 | { |
||
635 | $this->score = $score; |
||
636 | |||
637 | return $this; |
||
638 | } |
||
639 | |||
640 | /** |
||
641 | * Get score. |
||
642 | * |
||
643 | * @return int |
||
644 | */ |
||
645 | public function getScore() |
||
646 | { |
||
647 | return $this->score; |
||
648 | } |
||
649 | |||
650 | /** |
||
651 | * Set version. |
||
652 | * |
||
653 | * @param int $version |
||
654 | * |
||
655 | * @return CWiki |
||
656 | */ |
||
657 | public function setVersion($version) |
||
658 | { |
||
659 | $this->version = $version; |
||
660 | |||
661 | return $this; |
||
662 | } |
||
663 | |||
664 | /** |
||
665 | * Get version. |
||
666 | * |
||
667 | * @return int |
||
668 | */ |
||
669 | public function getVersion() |
||
670 | { |
||
671 | return $this->version; |
||
672 | } |
||
673 | |||
674 | /** |
||
675 | * Set isEditing. |
||
676 | * |
||
677 | * @param int $isEditing |
||
678 | * |
||
679 | * @return CWiki |
||
680 | */ |
||
681 | public function setIsEditing($isEditing) |
||
682 | { |
||
683 | $this->isEditing = $isEditing; |
||
684 | |||
685 | return $this; |
||
686 | } |
||
687 | |||
688 | /** |
||
689 | * Get isEditing. |
||
690 | * |
||
691 | * @return int |
||
692 | */ |
||
693 | public function getIsEditing() |
||
694 | { |
||
695 | return $this->isEditing; |
||
696 | } |
||
697 | |||
698 | /** |
||
699 | * Set timeEdit. |
||
700 | * |
||
701 | * @param \DateTime $timeEdit |
||
702 | * |
||
703 | * @return CWiki |
||
704 | */ |
||
705 | public function setTimeEdit($timeEdit) |
||
710 | } |
||
711 | |||
712 | /** |
||
713 | * Get timeEdit. |
||
714 | * |
||
715 | * @return \DateTime |
||
716 | */ |
||
717 | public function getTimeEdit() |
||
718 | { |
||
719 | return $this->timeEdit; |
||
720 | } |
||
721 | |||
722 | /** |
||
723 | * Set hits. |
||
724 | * |
||
725 | * @param int $hits |
||
726 | * |
||
727 | * @return CWiki |
||
728 | */ |
||
729 | public function setHits($hits) |
||
730 | { |
||
731 | $this->hits = $hits; |
||
732 | |||
733 | return $this; |
||
734 | } |
||
735 | |||
736 | /** |
||
737 | * Get hits. |
||
738 | * |
||
739 | * @return int |
||
740 | */ |
||
741 | public function getHits() |
||
742 | { |
||
743 | return $this->hits; |
||
744 | } |
||
745 | |||
746 | /** |
||
747 | * Set linksto. |
||
748 | * |
||
749 | * @param string $linksto |
||
750 | * |
||
751 | * @return CWiki |
||
752 | */ |
||
753 | public function setLinksto($linksto) |
||
754 | { |
||
755 | $this->linksto = $linksto; |
||
756 | |||
757 | return $this; |
||
758 | } |
||
759 | |||
760 | /** |
||
761 | * Get linksto. |
||
762 | * |
||
763 | * @return string |
||
764 | */ |
||
765 | public function getLinksto() |
||
766 | { |
||
767 | return $this->linksto; |
||
768 | } |
||
769 | |||
770 | /** |
||
771 | * Set tag. |
||
772 | * |
||
773 | * @param string $tag |
||
774 | * |
||
775 | * @return CWiki |
||
776 | */ |
||
777 | public function setTag($tag) |
||
782 | } |
||
783 | |||
784 | /** |
||
785 | * Get tag. |
||
786 | * |
||
787 | * @return string |
||
788 | */ |
||
789 | public function getTag() |
||
790 | { |
||
791 | return $this->tag; |
||
792 | } |
||
793 | |||
794 | /** |
||
795 | * Set userIp. |
||
796 | * |
||
797 | * @param string $userIp |
||
798 | * |
||
799 | * @return CWiki |
||
800 | */ |
||
801 | public function setUserIp($userIp) |
||
802 | { |
||
803 | $this->userIp = $userIp; |
||
804 | |||
805 | return $this; |
||
806 | } |
||
807 | |||
808 | /** |
||
809 | * Get userIp. |
||
810 | * |
||
811 | * @return string |
||
812 | */ |
||
813 | public function getUserIp() |
||
814 | { |
||
815 | return $this->userIp; |
||
816 | } |
||
817 | |||
818 | /** |
||
819 | * Set sessionId. |
||
820 | * |
||
821 | * @param int $sessionId |
||
822 | * |
||
823 | * @return CWiki |
||
824 | */ |
||
825 | public function setSessionId($sessionId) |
||
826 | { |
||
827 | $this->sessionId = $sessionId; |
||
828 | |||
829 | return $this; |
||
830 | } |
||
831 | |||
832 | /** |
||
833 | * Get sessionId. |
||
834 | * |
||
835 | * @return int |
||
836 | */ |
||
837 | public function getSessionId() |
||
838 | { |
||
839 | return $this->sessionId; |
||
840 | } |
||
841 | |||
842 | /** |
||
843 | * Set id. |
||
844 | * |
||
845 | * @param int $id |
||
846 | * |
||
847 | * @return CWiki |
||
848 | */ |
||
849 | public function setId($id) |
||
850 | { |
||
851 | $this->id = $id; |
||
852 | |||
853 | return $this; |
||
854 | } |
||
855 | |||
856 | /** |
||
857 | * Get id. |
||
858 | * |
||
859 | * @return int |
||
860 | */ |
||
861 | public function getId() |
||
862 | { |
||
863 | return $this->id; |
||
864 | } |
||
865 | |||
866 | public function getIid(): int |
||
867 | { |
||
868 | return $this->iid; |
||
869 | } |
||
870 | |||
871 | /** |
||
872 | * Set cId. |
||
873 | * |
||
874 | * @param int $cId |
||
875 | * |
||
876 | * @return CWiki |
||
877 | */ |
||
878 | public function setCId($cId) |
||
879 | { |
||
880 | $this->cId = $cId; |
||
881 | |||
882 | return $this; |
||
883 | } |
||
884 | |||
885 | /** |
||
886 | * Get cId. |
||
887 | * |
||
888 | * @return int |
||
889 | */ |
||
890 | public function getCId() |
||
891 | { |
||
892 | return $this->cId; |
||
893 | } |
||
894 | |||
895 | public function getCategories() |
||
898 | } |
||
899 | |||
900 | public function addCategory(CWikiCategory $category): CWiki |
||
901 | { |
||
902 | $category->addWikiPage($this); |
||
903 | $this->categories->add($category); |
||
904 | |||
905 | return $this; |
||
906 | } |
||
907 | } |
||
908 |