| Total Complexity | 48 |
| Total Lines | 624 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like CGroup 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 CGroup, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 30 | class CGroup extends AbstractResource implements ResourceInterface |
||
| 31 | { |
||
| 32 | use CourseTrait; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var int |
||
| 36 | * |
||
| 37 | * @ORM\Column(name="iid", type="integer") |
||
| 38 | * @ORM\Id |
||
| 39 | * @ORM\GeneratedValue |
||
| 40 | */ |
||
| 41 | protected $iid; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var int |
||
| 45 | * |
||
| 46 | * @ORM\Column(name="id", type="integer", nullable=true) |
||
| 47 | */ |
||
| 48 | protected $id; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var string |
||
| 52 | * @Assert\NotBlank() |
||
| 53 | * @ORM\Column(name="name", type="string", length=100, nullable=true) |
||
| 54 | */ |
||
| 55 | protected $name; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var bool |
||
| 59 | * |
||
| 60 | * @ORM\Column(name="status", type="boolean", nullable=true) |
||
| 61 | */ |
||
| 62 | protected $status; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var int |
||
| 66 | * |
||
| 67 | * @ORM\Column(name="category_id", type="integer", nullable=true) |
||
| 68 | */ |
||
| 69 | protected $categoryId; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var string |
||
| 73 | * |
||
| 74 | * @ORM\Column(name="description", type="text", nullable=true) |
||
| 75 | */ |
||
| 76 | protected $description; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @var int |
||
| 80 | * |
||
| 81 | * @ORM\Column(name="max_student", type="integer", nullable=false) |
||
| 82 | */ |
||
| 83 | protected $maxStudent; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @var bool |
||
| 87 | * |
||
| 88 | * @ORM\Column(name="doc_state", type="boolean", nullable=false) |
||
| 89 | */ |
||
| 90 | protected $docState; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @var bool |
||
| 94 | * |
||
| 95 | * @ORM\Column(name="calendar_state", type="boolean", nullable=false) |
||
| 96 | */ |
||
| 97 | protected $calendarState; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var bool |
||
| 101 | * |
||
| 102 | * @ORM\Column(name="work_state", type="boolean", nullable=false) |
||
| 103 | */ |
||
| 104 | protected $workState; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @var bool |
||
| 108 | * |
||
| 109 | * @ORM\Column(name="announcements_state", type="boolean", nullable=false) |
||
| 110 | */ |
||
| 111 | protected $announcementsState; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @var bool |
||
| 115 | * |
||
| 116 | * @ORM\Column(name="forum_state", type="boolean", nullable=false) |
||
| 117 | */ |
||
| 118 | protected $forumState; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @var bool |
||
| 122 | * |
||
| 123 | * @ORM\Column(name="wiki_state", type="boolean", nullable=false) |
||
| 124 | */ |
||
| 125 | protected $wikiState; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @var bool |
||
| 129 | * |
||
| 130 | * @ORM\Column(name="chat_state", type="boolean", nullable=false) |
||
| 131 | */ |
||
| 132 | protected $chatState; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @var string |
||
| 136 | * |
||
| 137 | * @ORM\Column(name="secret_directory", type="string", length=255, nullable=true) |
||
| 138 | */ |
||
| 139 | protected $secretDirectory; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @var bool |
||
| 143 | * |
||
| 144 | * @ORM\Column(name="self_registration_allowed", type="boolean", nullable=false) |
||
| 145 | */ |
||
| 146 | protected $selfRegistrationAllowed; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @var bool |
||
| 150 | * |
||
| 151 | * @ORM\Column(name="self_unregistration_allowed", type="boolean", nullable=false) |
||
| 152 | */ |
||
| 153 | protected $selfUnregistrationAllowed; |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @var int |
||
| 157 | * |
||
| 158 | * @ORM\Column(name="session_id", type="integer", nullable=false) |
||
| 159 | */ |
||
| 160 | protected $sessionId; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @var int |
||
| 164 | * |
||
| 165 | * @ORM\Column(name="document_access", type="integer", nullable=false, options={"default":0}) |
||
| 166 | */ |
||
| 167 | protected $documentAccess; |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @var Course |
||
| 171 | * |
||
| 172 | * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", inversedBy="groups", cascade={"persist"}) |
||
| 173 | * @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=false) |
||
| 174 | */ |
||
| 175 | protected $course; |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @var ArrayCollection|CGroupRelUser[] |
||
| 179 | * |
||
| 180 | * @ORM\OneToMany(targetEntity="CGroupRelUser", mappedBy="group") |
||
| 181 | */ |
||
| 182 | protected $members; |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @var ArrayCollection|CGroupRelTutor[] |
||
| 186 | * |
||
| 187 | * @ORM\OneToMany(targetEntity="CGroupRelTutor", mappedBy="group") |
||
| 188 | */ |
||
| 189 | protected $tutors; |
||
| 190 | |||
| 191 | public function __construct() |
||
| 192 | { |
||
| 193 | $this->status = 1; |
||
|
|
|||
| 194 | } |
||
| 195 | |||
| 196 | public function __toString(): string |
||
| 197 | { |
||
| 198 | return $this->getName(); |
||
| 199 | } |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Get iid. |
||
| 203 | * |
||
| 204 | * @return int |
||
| 205 | */ |
||
| 206 | public function getIid() |
||
| 207 | { |
||
| 208 | return $this->iid; |
||
| 209 | } |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Set name. |
||
| 213 | * |
||
| 214 | * @param string $name |
||
| 215 | * |
||
| 216 | * @return CGroup |
||
| 217 | */ |
||
| 218 | public function setName($name) |
||
| 219 | { |
||
| 220 | $this->name = $name; |
||
| 221 | |||
| 222 | return $this; |
||
| 223 | } |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Get name. |
||
| 227 | * |
||
| 228 | * @return string |
||
| 229 | */ |
||
| 230 | public function getName() |
||
| 231 | { |
||
| 232 | return (string) $this->name; |
||
| 233 | } |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Set status. |
||
| 237 | * |
||
| 238 | * @param bool $status |
||
| 239 | * |
||
| 240 | * @return CGroup |
||
| 241 | */ |
||
| 242 | public function setStatus($status) |
||
| 243 | { |
||
| 244 | $this->status = $status; |
||
| 245 | |||
| 246 | return $this; |
||
| 247 | } |
||
| 248 | |||
| 249 | /** |
||
| 250 | * Get status. |
||
| 251 | * |
||
| 252 | * @return bool |
||
| 253 | */ |
||
| 254 | public function getStatus() |
||
| 255 | { |
||
| 256 | return $this->status; |
||
| 257 | } |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Set categoryId. |
||
| 261 | * |
||
| 262 | * @param int $categoryId |
||
| 263 | * |
||
| 264 | * @return CGroup |
||
| 265 | */ |
||
| 266 | public function setCategoryId($categoryId) |
||
| 267 | { |
||
| 268 | $this->categoryId = $categoryId; |
||
| 269 | |||
| 270 | return $this; |
||
| 271 | } |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Get categoryId. |
||
| 275 | * |
||
| 276 | * @return int |
||
| 277 | */ |
||
| 278 | public function getCategoryId() |
||
| 279 | { |
||
| 280 | return $this->categoryId; |
||
| 281 | } |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Set description. |
||
| 285 | * |
||
| 286 | * @param string $description |
||
| 287 | */ |
||
| 288 | public function setDescription($description): self |
||
| 289 | { |
||
| 290 | $this->description = $description; |
||
| 291 | |||
| 292 | return $this; |
||
| 293 | } |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Get description. |
||
| 297 | * |
||
| 298 | * @return string |
||
| 299 | */ |
||
| 300 | public function getDescription() |
||
| 301 | { |
||
| 302 | return $this->description; |
||
| 303 | } |
||
| 304 | |||
| 305 | public function setMaxStudent(int $maxStudent): self |
||
| 306 | { |
||
| 307 | $this->maxStudent = $maxStudent; |
||
| 308 | |||
| 309 | return $this; |
||
| 310 | } |
||
| 311 | |||
| 312 | public function getMaxStudent(): int |
||
| 313 | { |
||
| 314 | return (int) $this->maxStudent; |
||
| 315 | } |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Set docState. |
||
| 319 | * |
||
| 320 | * @param bool $docState |
||
| 321 | */ |
||
| 322 | public function setDocState($docState): self |
||
| 323 | { |
||
| 324 | $this->docState = $docState; |
||
| 325 | |||
| 326 | return $this; |
||
| 327 | } |
||
| 328 | |||
| 329 | /** |
||
| 330 | * Get docState. |
||
| 331 | * |
||
| 332 | * @return bool |
||
| 333 | */ |
||
| 334 | public function getDocState() |
||
| 335 | { |
||
| 336 | return $this->docState; |
||
| 337 | } |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Set calendarState. |
||
| 341 | * |
||
| 342 | * @param bool $calendarState |
||
| 343 | */ |
||
| 344 | public function setCalendarState($calendarState): self |
||
| 345 | { |
||
| 346 | $this->calendarState = $calendarState; |
||
| 347 | |||
| 348 | return $this; |
||
| 349 | } |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Get calendarState. |
||
| 353 | * |
||
| 354 | * @return bool |
||
| 355 | */ |
||
| 356 | public function getCalendarState() |
||
| 357 | { |
||
| 358 | return $this->calendarState; |
||
| 359 | } |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Set workState. |
||
| 363 | * |
||
| 364 | * @param bool $workState |
||
| 365 | */ |
||
| 366 | public function setWorkState($workState): self |
||
| 367 | { |
||
| 368 | $this->workState = $workState; |
||
| 369 | |||
| 370 | return $this; |
||
| 371 | } |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Get workState. |
||
| 375 | * |
||
| 376 | * @return bool |
||
| 377 | */ |
||
| 378 | public function getWorkState() |
||
| 379 | { |
||
| 380 | return $this->workState; |
||
| 381 | } |
||
| 382 | |||
| 383 | /** |
||
| 384 | * Set announcementsState. |
||
| 385 | * |
||
| 386 | * @param bool $announcementsState |
||
| 387 | */ |
||
| 388 | public function setAnnouncementsState($announcementsState): self |
||
| 389 | { |
||
| 390 | $this->announcementsState = $announcementsState; |
||
| 391 | |||
| 392 | return $this; |
||
| 393 | } |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Get announcementsState. |
||
| 397 | * |
||
| 398 | * @return bool |
||
| 399 | */ |
||
| 400 | public function getAnnouncementsState() |
||
| 401 | { |
||
| 402 | return $this->announcementsState; |
||
| 403 | } |
||
| 404 | |||
| 405 | /** |
||
| 406 | * Set forumState. |
||
| 407 | * |
||
| 408 | * @param bool $forumState |
||
| 409 | */ |
||
| 410 | public function setForumState($forumState): self |
||
| 411 | { |
||
| 412 | $this->forumState = $forumState; |
||
| 413 | |||
| 414 | return $this; |
||
| 415 | } |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Get forumState. |
||
| 419 | * |
||
| 420 | * @return bool |
||
| 421 | */ |
||
| 422 | public function getForumState() |
||
| 423 | { |
||
| 424 | return $this->forumState; |
||
| 425 | } |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Set wikiState. |
||
| 429 | * |
||
| 430 | * @param bool $wikiState |
||
| 431 | * |
||
| 432 | * @return CGroup |
||
| 433 | */ |
||
| 434 | public function setWikiState($wikiState) |
||
| 435 | { |
||
| 436 | $this->wikiState = $wikiState; |
||
| 437 | |||
| 438 | return $this; |
||
| 439 | } |
||
| 440 | |||
| 441 | /** |
||
| 442 | * Get wikiState. |
||
| 443 | * |
||
| 444 | * @return bool |
||
| 445 | */ |
||
| 446 | public function getWikiState() |
||
| 447 | { |
||
| 448 | return $this->wikiState; |
||
| 449 | } |
||
| 450 | |||
| 451 | /** |
||
| 452 | * Set chatState. |
||
| 453 | * |
||
| 454 | * @param bool $chatState |
||
| 455 | * |
||
| 456 | * @return CGroup |
||
| 457 | */ |
||
| 458 | public function setChatState($chatState) |
||
| 459 | { |
||
| 460 | $this->chatState = $chatState; |
||
| 461 | |||
| 462 | return $this; |
||
| 463 | } |
||
| 464 | |||
| 465 | /** |
||
| 466 | * Get chatState. |
||
| 467 | * |
||
| 468 | * @return bool |
||
| 469 | */ |
||
| 470 | public function getChatState() |
||
| 471 | { |
||
| 472 | return $this->chatState; |
||
| 473 | } |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Set secretDirectory. |
||
| 477 | * |
||
| 478 | * @param string $secretDirectory |
||
| 479 | * |
||
| 480 | * @return CGroup |
||
| 481 | */ |
||
| 482 | public function setSecretDirectory($secretDirectory) |
||
| 483 | { |
||
| 484 | $this->secretDirectory = $secretDirectory; |
||
| 485 | |||
| 486 | return $this; |
||
| 487 | } |
||
| 488 | |||
| 489 | public function getSecretDirectory(): string |
||
| 490 | { |
||
| 491 | return $this->secretDirectory; |
||
| 492 | } |
||
| 493 | |||
| 494 | /** |
||
| 495 | * Set selfRegistrationAllowed. |
||
| 496 | * |
||
| 497 | * @param bool $selfRegistrationAllowed |
||
| 498 | */ |
||
| 499 | public function setSelfRegistrationAllowed($selfRegistrationAllowed): self |
||
| 500 | { |
||
| 501 | $this->selfRegistrationAllowed = $selfRegistrationAllowed; |
||
| 502 | |||
| 503 | return $this; |
||
| 504 | } |
||
| 505 | |||
| 506 | /** |
||
| 507 | * Get selfRegistrationAllowed. |
||
| 508 | * |
||
| 509 | * @return bool |
||
| 510 | */ |
||
| 511 | public function getSelfRegistrationAllowed() |
||
| 512 | { |
||
| 513 | return $this->selfRegistrationAllowed; |
||
| 514 | } |
||
| 515 | |||
| 516 | /** |
||
| 517 | * Set selfUnregistrationAllowed. |
||
| 518 | * |
||
| 519 | * @param bool $selfUnregistrationAllowed |
||
| 520 | */ |
||
| 521 | public function setSelfUnregistrationAllowed($selfUnregistrationAllowed): self |
||
| 522 | { |
||
| 523 | $this->selfUnregistrationAllowed = $selfUnregistrationAllowed; |
||
| 524 | |||
| 525 | return $this; |
||
| 526 | } |
||
| 527 | |||
| 528 | /** |
||
| 529 | * Get selfUnregistrationAllowed. |
||
| 530 | * |
||
| 531 | * @return bool |
||
| 532 | */ |
||
| 533 | public function getSelfUnregistrationAllowed() |
||
| 534 | { |
||
| 535 | return $this->selfUnregistrationAllowed; |
||
| 536 | } |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Set sessionId. |
||
| 540 | * |
||
| 541 | * @param int $sessionId |
||
| 542 | */ |
||
| 543 | public function setSessionId($sessionId): self |
||
| 544 | { |
||
| 545 | $this->sessionId = $sessionId; |
||
| 546 | |||
| 547 | return $this; |
||
| 548 | } |
||
| 549 | |||
| 550 | /** |
||
| 551 | * Get sessionId. |
||
| 552 | * |
||
| 553 | * @return int |
||
| 554 | */ |
||
| 555 | public function getSessionId() |
||
| 558 | } |
||
| 559 | |||
| 560 | /** |
||
| 561 | * Set id. |
||
| 562 | * |
||
| 563 | * @param int $id |
||
| 564 | * |
||
| 565 | * @return CGroup |
||
| 566 | */ |
||
| 567 | public function setId($id) |
||
| 568 | { |
||
| 569 | $this->id = $id; |
||
| 570 | |||
| 571 | return $this; |
||
| 572 | } |
||
| 573 | |||
| 574 | /** |
||
| 575 | * Get id. |
||
| 576 | * |
||
| 577 | * @return int |
||
| 578 | */ |
||
| 579 | public function getId() |
||
| 580 | { |
||
| 581 | return $this->id; |
||
| 582 | } |
||
| 583 | |||
| 584 | public function getDocumentAccess(): int |
||
| 585 | { |
||
| 586 | return $this->documentAccess; |
||
| 587 | } |
||
| 588 | |||
| 589 | public function setDocumentAccess(int $documentAccess): self |
||
| 590 | { |
||
| 591 | $this->documentAccess = $documentAccess; |
||
| 592 | |||
| 593 | return $this; |
||
| 594 | } |
||
| 595 | |||
| 596 | public function getMembers(): ArrayCollection |
||
| 597 | { |
||
| 598 | return $this->members; |
||
| 599 | } |
||
| 600 | |||
| 601 | public function setMembers(ArrayCollection $members): self |
||
| 602 | { |
||
| 603 | $this->members = $members; |
||
| 604 | |||
| 605 | return $this; |
||
| 606 | } |
||
| 607 | |||
| 608 | public function getTutors(): ArrayCollection |
||
| 609 | { |
||
| 610 | return $this->tutors; |
||
| 611 | } |
||
| 612 | |||
| 613 | public function setTutors(ArrayCollection $tutors): self |
||
| 614 | { |
||
| 615 | $this->tutors = $tutors; |
||
| 616 | |||
| 617 | return $this; |
||
| 618 | } |
||
| 619 | |||
| 620 | public function userIsTutor(User $user = null): bool |
||
| 621 | { |
||
| 622 | if (empty($user)) { |
||
| 623 | return false; |
||
| 624 | } |
||
| 625 | |||
| 626 | if (0 === $this->tutors->count()) { |
||
| 627 | return false; |
||
| 628 | } |
||
| 629 | |||
| 630 | $criteria = Criteria::create() |
||
| 631 | ->where( |
||
| 632 | Criteria::expr()->eq('cId', $this->course) |
||
| 633 | ) |
||
| 634 | ->andWhere( |
||
| 635 | Criteria::expr()->eq('user', $user) |
||
| 636 | ); |
||
| 637 | |||
| 638 | $relation = $this->tutors->matching($criteria); |
||
| 639 | |||
| 640 | return $relation->count() > 0; |
||
| 641 | } |
||
| 642 | |||
| 643 | /** |
||
| 644 | * Resource identifier. |
||
| 645 | */ |
||
| 646 | public function getResourceIdentifier(): int |
||
| 647 | { |
||
| 648 | return $this->iid; |
||
| 649 | } |
||
| 650 | |||
| 651 | public function getResourceName(): string |
||
| 654 | } |
||
| 655 | } |
||
| 656 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.