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