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