| Total Complexity | 56 |
| Total Lines | 628 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like CStudentPublication 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 CStudentPublication, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 29 | class CStudentPublication extends AbstractResource implements ResourceInterface |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * @ORM\Column(name="iid", type="integer") |
||
| 33 | * @ORM\Id |
||
| 34 | * @ORM\GeneratedValue |
||
| 35 | */ |
||
| 36 | protected int $iid; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @Assert\NotBlank() |
||
| 40 | * @ORM\Column(name="title", type="string", length=255, nullable=false) |
||
| 41 | */ |
||
| 42 | protected string $title; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @ORM\Column(name="description", type="text", nullable=true) |
||
| 46 | */ |
||
| 47 | protected ?string $description; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @ORM\Column(name="author", type="string", length=255, nullable=true) |
||
| 51 | */ |
||
| 52 | protected ?string $author; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @ORM\Column(name="active", type="integer", nullable=true) |
||
| 56 | */ |
||
| 57 | protected ?int $active; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @ORM\Column(name="accepted", type="boolean", nullable=true) |
||
| 61 | */ |
||
| 62 | protected ?bool $accepted; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @ORM\Column(name="post_group_id", type="integer", nullable=false) |
||
| 66 | */ |
||
| 67 | protected int $postGroupId; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @ORM\Column(name="sent_date", type="datetime", nullable=true) |
||
| 71 | */ |
||
| 72 | protected ?DateTime $sentDate; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @ORM\Column(name="filetype", type="string", length=10, nullable=false) |
||
| 76 | */ |
||
| 77 | protected string $filetype; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @ORM\Column(name="has_properties", type="integer", nullable=false) |
||
| 81 | */ |
||
| 82 | protected int $hasProperties; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @ORM\Column(name="view_properties", type="boolean", nullable=true) |
||
| 86 | */ |
||
| 87 | protected ?bool $viewProperties; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @ORM\Column(name="qualification", type="float", precision=6, scale=2, nullable=false) |
||
| 91 | */ |
||
| 92 | protected float $qualification; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @ORM\Column(name="date_of_qualification", type="datetime", nullable=true) |
||
| 96 | */ |
||
| 97 | protected ?DateTime $dateOfQualification; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var Collection|CStudentPublication[] |
||
| 101 | * @ORM\OneToMany(targetEntity="CStudentPublication", mappedBy="publicationParent") |
||
| 102 | */ |
||
| 103 | protected Collection $children; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @var Collection|CStudentPublicationComment[] |
||
| 107 | * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CStudentPublicationComment", mappedBy="publication") |
||
| 108 | */ |
||
| 109 | protected Collection $comments; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CStudentPublication", inversedBy="children") |
||
| 113 | * @ORM\JoinColumn(name="parent_id", referencedColumnName="iid") |
||
| 114 | */ |
||
| 115 | protected ?CStudentPublication $publicationParent; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @ORM\OneToOne(targetEntity="Chamilo\CourseBundle\Entity\CStudentPublicationAssignment", mappedBy="publication") |
||
| 119 | */ |
||
| 120 | protected ?CStudentPublicationAssignment $assignment = null; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @ORM\Column(name="qualificator_id", type="integer", nullable=false) |
||
| 124 | */ |
||
| 125 | protected int $qualificatorId; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @ORM\Column(name="weight", type="float", precision=6, scale=2, nullable=false) |
||
| 129 | */ |
||
| 130 | protected float $weight; |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User") |
||
| 134 | * @ORM\JoinColumn(name="user_id", referencedColumnName="id") |
||
| 135 | */ |
||
| 136 | protected User $user; |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @ORM\Column(name="allow_text_assignment", type="integer", nullable=false) |
||
| 140 | */ |
||
| 141 | protected int $allowTextAssignment; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @ORM\Column(name="contains_file", type="integer", nullable=false) |
||
| 145 | */ |
||
| 146 | protected int $containsFile; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @ORM\Column(name="document_id", type="integer", nullable=false) |
||
| 150 | */ |
||
| 151 | protected int $documentId; |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @ORM\Column(name="filesize", type="integer", nullable=true) |
||
| 155 | */ |
||
| 156 | protected ?int $fileSize; |
||
| 157 | |||
| 158 | public function __construct() |
||
| 159 | { |
||
| 160 | $this->description = ''; |
||
| 161 | $this->documentId = 0; |
||
| 162 | $this->hasProperties = 0; |
||
| 163 | $this->containsFile = 0; |
||
| 164 | $this->publicationParent = null; |
||
| 165 | $this->qualificatorId = 0; |
||
| 166 | $this->qualification = 0; |
||
| 167 | $this->assignment = null; |
||
| 168 | $this->sentDate = new DateTime(); |
||
| 169 | $this->children = new ArrayCollection(); |
||
| 170 | $this->comments = new ArrayCollection(); |
||
| 171 | } |
||
| 172 | |||
| 173 | public function __toString(): string |
||
| 174 | { |
||
| 175 | return (string) $this->getTitle(); |
||
| 176 | } |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Get iid. |
||
| 180 | * |
||
| 181 | * @return int |
||
| 182 | */ |
||
| 183 | public function getIid() |
||
| 184 | { |
||
| 185 | return $this->iid; |
||
| 186 | } |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Set title. |
||
| 190 | * |
||
| 191 | * @param string $title |
||
| 192 | */ |
||
| 193 | public function setTitle($title): self |
||
| 194 | { |
||
| 195 | $this->title = $title; |
||
| 196 | |||
| 197 | return $this; |
||
| 198 | } |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Get title. |
||
| 202 | * |
||
| 203 | * @return string |
||
| 204 | */ |
||
| 205 | public function getTitle() |
||
| 206 | { |
||
| 207 | return $this->title; |
||
| 208 | } |
||
| 209 | |||
| 210 | public function setDescription(string $description): self |
||
| 211 | { |
||
| 212 | $this->description = $description; |
||
| 213 | |||
| 214 | return $this; |
||
| 215 | } |
||
| 216 | |||
| 217 | public function getDescription(): ?string |
||
| 218 | { |
||
| 219 | return $this->description; |
||
| 220 | } |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Set author. |
||
| 224 | * |
||
| 225 | * @param string $author |
||
| 226 | */ |
||
| 227 | public function setAuthor($author): self |
||
| 228 | { |
||
| 229 | $this->author = $author; |
||
| 230 | |||
| 231 | return $this; |
||
| 232 | } |
||
| 233 | |||
| 234 | /** |
||
| 235 | * Get author. |
||
| 236 | * |
||
| 237 | * @return string |
||
| 238 | */ |
||
| 239 | public function getAuthor() |
||
| 240 | { |
||
| 241 | return $this->author; |
||
| 242 | } |
||
| 243 | |||
| 244 | public function setActive(int $active): self |
||
| 245 | { |
||
| 246 | $this->active = $active; |
||
| 247 | |||
| 248 | return $this; |
||
| 249 | } |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Get active. |
||
| 253 | * |
||
| 254 | * @return int |
||
| 255 | */ |
||
| 256 | public function getActive() |
||
| 257 | { |
||
| 258 | return $this->active; |
||
| 259 | } |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Set accepted. |
||
| 263 | * |
||
| 264 | * @param bool $accepted |
||
| 265 | */ |
||
| 266 | public function setAccepted($accepted): self |
||
| 267 | { |
||
| 268 | $this->accepted = $accepted; |
||
| 269 | |||
| 270 | return $this; |
||
| 271 | } |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Get accepted. |
||
| 275 | * |
||
| 276 | * @return bool |
||
| 277 | */ |
||
| 278 | public function getAccepted() |
||
| 279 | { |
||
| 280 | return $this->accepted; |
||
| 281 | } |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Set postGroupId. |
||
| 285 | * |
||
| 286 | * @param int $postGroupId |
||
| 287 | * |
||
| 288 | * @return CStudentPublication |
||
| 289 | */ |
||
| 290 | public function setPostGroupId($postGroupId) |
||
| 291 | { |
||
| 292 | $this->postGroupId = $postGroupId; |
||
| 293 | |||
| 294 | return $this; |
||
| 295 | } |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Get postGroupId. |
||
| 299 | * |
||
| 300 | * @return int |
||
| 301 | */ |
||
| 302 | public function getPostGroupId() |
||
| 303 | { |
||
| 304 | return $this->postGroupId; |
||
| 305 | } |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Set sentDate. |
||
| 309 | * |
||
| 310 | * @param DateTime $sentDate |
||
| 311 | */ |
||
| 312 | public function setSentDate($sentDate): self |
||
| 313 | { |
||
| 314 | $this->sentDate = $sentDate; |
||
| 315 | |||
| 316 | return $this; |
||
| 317 | } |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Get sentDate. |
||
| 321 | * |
||
| 322 | * @return DateTime |
||
| 323 | */ |
||
| 324 | public function getSentDate() |
||
| 325 | { |
||
| 326 | return $this->sentDate; |
||
| 327 | } |
||
| 328 | |||
| 329 | /** |
||
| 330 | * Set filetype. |
||
| 331 | * |
||
| 332 | * @param string $filetype |
||
| 333 | */ |
||
| 334 | public function setFiletype($filetype): self |
||
| 335 | { |
||
| 336 | $this->filetype = $filetype; |
||
| 337 | |||
| 338 | return $this; |
||
| 339 | } |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Get filetype. |
||
| 343 | * |
||
| 344 | * @return string |
||
| 345 | */ |
||
| 346 | public function getFiletype() |
||
| 347 | { |
||
| 348 | return $this->filetype; |
||
| 349 | } |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Set hasProperties. |
||
| 353 | * |
||
| 354 | * @param int $hasProperties |
||
| 355 | */ |
||
| 356 | public function setHasProperties($hasProperties): self |
||
| 357 | { |
||
| 358 | $this->hasProperties = $hasProperties; |
||
| 359 | |||
| 360 | return $this; |
||
| 361 | } |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Get hasProperties. |
||
| 365 | * |
||
| 366 | * @return int |
||
| 367 | */ |
||
| 368 | public function getHasProperties() |
||
| 369 | { |
||
| 370 | return $this->hasProperties; |
||
| 371 | } |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Set viewProperties. |
||
| 375 | * |
||
| 376 | * @param bool $viewProperties |
||
| 377 | */ |
||
| 378 | public function setViewProperties($viewProperties): self |
||
| 379 | { |
||
| 380 | $this->viewProperties = $viewProperties; |
||
| 381 | |||
| 382 | return $this; |
||
| 383 | } |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Get viewProperties. |
||
| 387 | * |
||
| 388 | * @return bool |
||
| 389 | */ |
||
| 390 | public function getViewProperties() |
||
| 391 | { |
||
| 392 | return $this->viewProperties; |
||
| 393 | } |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Set qualification. |
||
| 397 | * |
||
| 398 | * @param float $qualification |
||
| 399 | * |
||
| 400 | * @return CStudentPublication |
||
| 401 | */ |
||
| 402 | public function setQualification($qualification) |
||
| 403 | { |
||
| 404 | $this->qualification = $qualification; |
||
| 405 | |||
| 406 | return $this; |
||
| 407 | } |
||
| 408 | |||
| 409 | /** |
||
| 410 | * Get qualification. |
||
| 411 | * |
||
| 412 | * @return float |
||
| 413 | */ |
||
| 414 | public function getQualification() |
||
| 415 | { |
||
| 416 | return $this->qualification; |
||
| 417 | } |
||
| 418 | |||
| 419 | /** |
||
| 420 | * Set dateOfQualification. |
||
| 421 | * |
||
| 422 | * @param DateTime $dateOfQualification |
||
| 423 | * |
||
| 424 | * @return CStudentPublication |
||
| 425 | */ |
||
| 426 | public function setDateOfQualification($dateOfQualification) |
||
| 427 | { |
||
| 428 | $this->dateOfQualification = $dateOfQualification; |
||
| 429 | |||
| 430 | return $this; |
||
| 431 | } |
||
| 432 | |||
| 433 | /** |
||
| 434 | * Get dateOfQualification. |
||
| 435 | * |
||
| 436 | * @return DateTime |
||
| 437 | */ |
||
| 438 | public function getDateOfQualification() |
||
| 439 | { |
||
| 440 | return $this->dateOfQualification; |
||
| 441 | } |
||
| 442 | |||
| 443 | /** |
||
| 444 | * Set qualificatorId. |
||
| 445 | * |
||
| 446 | * @param int $qualificatorId |
||
| 447 | * |
||
| 448 | * @return CStudentPublication |
||
| 449 | */ |
||
| 450 | public function setQualificatorId($qualificatorId) |
||
| 451 | { |
||
| 452 | $this->qualificatorId = $qualificatorId; |
||
| 453 | |||
| 454 | return $this; |
||
| 455 | } |
||
| 456 | |||
| 457 | public function getQualificatorId(): int |
||
| 458 | { |
||
| 459 | return $this->qualificatorId; |
||
| 460 | } |
||
| 461 | |||
| 462 | /** |
||
| 463 | * Set weight. |
||
| 464 | * |
||
| 465 | * @param float $weight |
||
| 466 | * |
||
| 467 | * @return CStudentPublication |
||
| 468 | */ |
||
| 469 | public function setWeight($weight) |
||
| 470 | { |
||
| 471 | $this->weight = $weight; |
||
| 472 | |||
| 473 | return $this; |
||
| 474 | } |
||
| 475 | |||
| 476 | /** |
||
| 477 | * Get weight. |
||
| 478 | * |
||
| 479 | * @return float |
||
| 480 | */ |
||
| 481 | public function getWeight() |
||
| 482 | { |
||
| 483 | return $this->weight; |
||
| 484 | } |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Set allowTextAssignment. |
||
| 488 | * |
||
| 489 | * @param int $allowTextAssignment |
||
| 490 | */ |
||
| 491 | public function setAllowTextAssignment($allowTextAssignment): self |
||
| 492 | { |
||
| 493 | $this->allowTextAssignment = $allowTextAssignment; |
||
| 494 | |||
| 495 | return $this; |
||
| 496 | } |
||
| 497 | |||
| 498 | /** |
||
| 499 | * Get allowTextAssignment. |
||
| 500 | * |
||
| 501 | * @return int |
||
| 502 | */ |
||
| 503 | public function getAllowTextAssignment() |
||
| 504 | { |
||
| 505 | return $this->allowTextAssignment; |
||
| 506 | } |
||
| 507 | |||
| 508 | /** |
||
| 509 | * Set containsFile. |
||
| 510 | * |
||
| 511 | * @param int $containsFile |
||
| 512 | */ |
||
| 513 | public function setContainsFile($containsFile): self |
||
| 514 | { |
||
| 515 | $this->containsFile = $containsFile; |
||
| 516 | |||
| 517 | return $this; |
||
| 518 | } |
||
| 519 | |||
| 520 | /** |
||
| 521 | * Get containsFile. |
||
| 522 | * |
||
| 523 | * @return int |
||
| 524 | */ |
||
| 525 | public function getContainsFile() |
||
| 526 | { |
||
| 527 | return $this->containsFile; |
||
| 528 | } |
||
| 529 | |||
| 530 | /** |
||
| 531 | * @return int |
||
| 532 | */ |
||
| 533 | public function getDocumentId() |
||
| 534 | { |
||
| 535 | return $this->documentId; |
||
| 536 | } |
||
| 537 | |||
| 538 | /** |
||
| 539 | * @param int $documentId |
||
| 540 | */ |
||
| 541 | public function setDocumentId($documentId): self |
||
| 542 | { |
||
| 543 | $this->documentId = $documentId; |
||
| 544 | |||
| 545 | return $this; |
||
| 546 | } |
||
| 547 | |||
| 548 | public function getFileSize(): int |
||
| 549 | { |
||
| 550 | return $this->fileSize; |
||
|
|
|||
| 551 | } |
||
| 552 | |||
| 553 | public function setFileSize(int $fileSize): self |
||
| 554 | { |
||
| 555 | $this->fileSize = $fileSize; |
||
| 556 | |||
| 557 | return $this; |
||
| 558 | } |
||
| 559 | |||
| 560 | public function getCorrection(): ?ResourceNode |
||
| 561 | { |
||
| 562 | if ($this->hasResourceNode()) { |
||
| 563 | $children = $this->getResourceNode()->getChildren(); |
||
| 564 | foreach ($children as $child) { |
||
| 565 | $name = $child->getResourceType()->getName(); |
||
| 566 | if ('student_publications_corrections' === $name) { |
||
| 567 | return $child; |
||
| 568 | } |
||
| 569 | } |
||
| 570 | } |
||
| 571 | |||
| 572 | return null; |
||
| 573 | } |
||
| 574 | |||
| 575 | public function getAssignment(): ?CStudentPublicationAssignment |
||
| 576 | { |
||
| 577 | return $this->assignment; |
||
| 578 | } |
||
| 579 | |||
| 580 | public function setAssignment(?CStudentPublicationAssignment $assignment): self |
||
| 581 | { |
||
| 582 | $this->assignment = $assignment; |
||
| 583 | |||
| 584 | return $this; |
||
| 585 | } |
||
| 586 | |||
| 587 | /** |
||
| 588 | * @return CStudentPublication[]|Collection |
||
| 589 | */ |
||
| 590 | public function getChildren() |
||
| 591 | { |
||
| 592 | return $this->children; |
||
| 593 | } |
||
| 594 | |||
| 595 | public function setChildren(Collection $children): self |
||
| 596 | { |
||
| 597 | $this->children = $children; |
||
| 598 | |||
| 599 | return $this; |
||
| 600 | } |
||
| 601 | |||
| 602 | public function getPublicationParent(): ?self |
||
| 603 | { |
||
| 604 | return $this->publicationParent; |
||
| 605 | } |
||
| 606 | |||
| 607 | public function setPublicationParent(?self $publicationParent): self |
||
| 608 | { |
||
| 609 | $this->publicationParent = $publicationParent; |
||
| 610 | |||
| 611 | return $this; |
||
| 612 | } |
||
| 613 | |||
| 614 | public function getUser(): User |
||
| 615 | { |
||
| 616 | return $this->user; |
||
| 617 | } |
||
| 618 | |||
| 619 | public function setUser(User $user): self |
||
| 620 | { |
||
| 621 | $this->user = $user; |
||
| 622 | |||
| 623 | return $this; |
||
| 624 | } |
||
| 625 | |||
| 626 | /** |
||
| 627 | * @return CStudentPublicationComment[]|Collection |
||
| 628 | */ |
||
| 629 | public function getComments() |
||
| 630 | { |
||
| 631 | return $this->comments; |
||
| 632 | } |
||
| 633 | |||
| 634 | /** |
||
| 635 | * @param CStudentPublicationComment[]|Collection $comments |
||
| 636 | */ |
||
| 637 | public function setComments($comments): self |
||
| 638 | { |
||
| 639 | $this->comments = $comments; |
||
| 640 | |||
| 641 | return $this; |
||
| 642 | } |
||
| 643 | |||
| 644 | public function getResourceIdentifier(): int |
||
| 645 | { |
||
| 646 | return $this->getIid(); |
||
| 647 | } |
||
| 648 | |||
| 649 | public function getResourceName(): string |
||
| 650 | { |
||
| 651 | return $this->getTitle(); |
||
| 652 | } |
||
| 653 | |||
| 654 | public function setResourceName(string $name): self |
||
| 657 | } |
||
| 658 | } |
||
| 659 |