| Total Complexity | 49 |
| Total Lines | 523 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like GradebookCategory 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 GradebookCategory, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 22 | class GradebookCategory |
||
| 23 | { |
||
| 24 | use UserTrait; |
||
| 25 | use CourseTrait; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @ORM\Column(name="id", type="integer") |
||
| 29 | * @ORM\Id |
||
| 30 | * @ORM\GeneratedValue |
||
| 31 | */ |
||
| 32 | protected int $id; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @Assert\NotBlank |
||
| 36 | * |
||
| 37 | * @ORM\Column(name="name", type="text", nullable=false) |
||
| 38 | */ |
||
| 39 | protected string $name; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @ORM\Column(name="description", type="text", nullable=true) |
||
| 43 | */ |
||
| 44 | protected ?string $description; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User", inversedBy="gradeBookCategories") |
||
| 48 | * @ORM\JoinColumn(name="user_id", referencedColumnName="id") |
||
| 49 | */ |
||
| 50 | protected User $user; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", inversedBy="gradebookCategories") |
||
| 54 | * @ORM\JoinColumn(name="c_id", referencedColumnName="id", onDelete="CASCADE") |
||
| 55 | */ |
||
| 56 | protected Course $course; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\GradebookCategory") |
||
| 60 | * @ORM\JoinColumn(name="parent_id", referencedColumnName="id") |
||
| 61 | */ |
||
| 62 | protected ?GradebookCategory $parent = null; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session") |
||
| 66 | * @ORM\JoinColumn(name="session_id", referencedColumnName="id", onDelete="CASCADE") |
||
| 67 | */ |
||
| 68 | protected ?Session $session = null; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\GradebookCategory", mappedBy="parent") |
||
| 72 | * |
||
| 73 | * @var GradebookCategory[]|Collection |
||
| 74 | */ |
||
| 75 | protected Collection $subCategories; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SkillRelGradebook", mappedBy="gradeBookCategory") |
||
| 79 | * |
||
| 80 | * @var SkillRelGradebook[]|Collection |
||
| 81 | */ |
||
| 82 | protected Collection $skills; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var Collection|GradebookEvaluation[] |
||
| 86 | * |
||
| 87 | * @ORM\OneToMany(targetEntity="GradebookEvaluation", mappedBy="category", cascade={"persist", "remove"}) |
||
| 88 | */ |
||
| 89 | protected Collection $evaluations; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @var Collection|GradebookLink[] |
||
| 93 | * |
||
| 94 | * @ORM\OneToMany(targetEntity="GradebookLink", mappedBy="category", cascade={"persist", "remove"}) |
||
| 95 | */ |
||
| 96 | protected Collection $links; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @var Collection|GradebookComment[] |
||
| 100 | * |
||
| 101 | * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\GradebookComment", mappedBy="gradeBook") |
||
| 102 | */ |
||
| 103 | protected Collection $comments; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\GradeModel") |
||
| 107 | * @ORM\JoinColumn(name="grade_model_id", referencedColumnName="id", onDelete="CASCADE") |
||
| 108 | */ |
||
| 109 | protected ?GradeModel $gradeModel = null; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @ORM\Column(name="weight", type="float", precision=10, scale=0, nullable=false) |
||
| 113 | */ |
||
| 114 | protected float $weight; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @ORM\Column(name="visible", type="boolean", nullable=false) |
||
| 118 | */ |
||
| 119 | protected bool $visible; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @ORM\Column(name="certif_min_score", type="integer", nullable=true) |
||
| 123 | */ |
||
| 124 | protected ?int $certifMinScore = null; |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @ORM\Column(name="document_id", type="integer", nullable=true) |
||
| 128 | */ |
||
| 129 | protected ?int $documentId = null; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @ORM\Column(name="locked", type="integer", nullable=false) |
||
| 133 | */ |
||
| 134 | protected ?int $locked; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @ORM\Column(name="default_lowest_eval_exclude", type="boolean", nullable=true) |
||
| 138 | */ |
||
| 139 | protected ?bool $defaultLowestEvalExclude = null; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @ORM\Column(name="generate_certificates", type="boolean", nullable=false) |
||
| 143 | */ |
||
| 144 | protected bool $generateCertificates; |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @ORM\Column( |
||
| 148 | * name="is_requirement", |
||
| 149 | * type="boolean", |
||
| 150 | * nullable=false, |
||
| 151 | * options={"default":0 } |
||
| 152 | * ) |
||
| 153 | */ |
||
| 154 | protected bool $isRequirement; |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @ORM\Column(name="depends", type="text", nullable=true) |
||
| 158 | */ |
||
| 159 | protected ?string $depends = null; |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @ORM\Column(name="minimum_to_validate", type="integer", nullable=true) |
||
| 163 | */ |
||
| 164 | protected ?int $minimumToValidate = null; |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @ORM\Column(name="gradebooks_to_validate_in_dependence", type="integer", nullable=true) |
||
| 168 | */ |
||
| 169 | protected ?int $gradeBooksToValidateInDependence = null; |
||
| 170 | |||
| 171 | public function __construct() |
||
| 172 | { |
||
| 173 | $this->comments = new ArrayCollection(); |
||
| 174 | $this->evaluations = new ArrayCollection(); |
||
| 175 | $this->links = new ArrayCollection(); |
||
| 176 | $this->subCategories = new ArrayCollection(); |
||
| 177 | $this->skills = new ArrayCollection(); |
||
| 178 | |||
| 179 | $this->description = ''; |
||
| 180 | $this->locked = 0; |
||
| 181 | $this->generateCertificates = false; |
||
| 182 | $this->isRequirement = false; |
||
| 183 | } |
||
| 184 | |||
| 185 | /** |
||
| 186 | * Get id. |
||
| 187 | * |
||
| 188 | * @return int |
||
| 189 | */ |
||
| 190 | public function getId() |
||
| 191 | { |
||
| 192 | return $this->id; |
||
| 193 | } |
||
| 194 | |||
| 195 | public function setName(string $name): self |
||
| 196 | { |
||
| 197 | $this->name = $name; |
||
| 198 | |||
| 199 | return $this; |
||
| 200 | } |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Get name. |
||
| 204 | * |
||
| 205 | * @return string |
||
| 206 | */ |
||
| 207 | public function getName() |
||
| 208 | { |
||
| 209 | return $this->name; |
||
| 210 | } |
||
| 211 | |||
| 212 | public function setDescription(?string $description): self |
||
| 217 | } |
||
| 218 | |||
| 219 | public function getDescription(): ?string |
||
| 220 | { |
||
| 221 | return $this->description; |
||
| 222 | } |
||
| 223 | |||
| 224 | public function setWeight(float $weight): self |
||
| 225 | { |
||
| 226 | $this->weight = $weight; |
||
| 227 | |||
| 228 | return $this; |
||
| 229 | } |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Get weight. |
||
| 233 | * |
||
| 234 | * @return float |
||
| 235 | */ |
||
| 236 | public function getWeight() |
||
| 237 | { |
||
| 238 | return $this->weight; |
||
| 239 | } |
||
| 240 | |||
| 241 | public function setVisible(bool $visible): self |
||
| 242 | { |
||
| 243 | $this->visible = $visible; |
||
| 244 | |||
| 245 | return $this; |
||
| 246 | } |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Get visible. |
||
| 250 | * |
||
| 251 | * @return bool |
||
| 252 | */ |
||
| 253 | public function getVisible() |
||
| 254 | { |
||
| 255 | return $this->visible; |
||
| 256 | } |
||
| 257 | |||
| 258 | public function setCertifMinScore(int $certifMinScore): self |
||
| 259 | { |
||
| 260 | $this->certifMinScore = $certifMinScore; |
||
| 261 | |||
| 262 | return $this; |
||
| 263 | } |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Get certifMinScore. |
||
| 267 | * |
||
| 268 | * @return int |
||
| 269 | */ |
||
| 270 | public function getCertifMinScore() |
||
| 271 | { |
||
| 272 | return $this->certifMinScore; |
||
| 273 | } |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Set documentId. |
||
| 277 | * |
||
| 278 | * @return GradebookCategory |
||
| 279 | */ |
||
| 280 | public function setDocumentId(int $documentId) |
||
| 281 | { |
||
| 282 | $this->documentId = $documentId; |
||
| 283 | |||
| 284 | return $this; |
||
| 285 | } |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Get documentId. |
||
| 289 | * |
||
| 290 | * @return int |
||
| 291 | */ |
||
| 292 | public function getDocumentId() |
||
| 293 | { |
||
| 294 | return $this->documentId; |
||
| 295 | } |
||
| 296 | |||
| 297 | public function setLocked(int $locked): self |
||
| 302 | } |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Get locked. |
||
| 306 | * |
||
| 307 | * @return int |
||
| 308 | */ |
||
| 309 | public function getLocked() |
||
| 312 | } |
||
| 313 | |||
| 314 | public function setDefaultLowestEvalExclude(bool $defaultLowestEvalExclude): self |
||
| 315 | { |
||
| 316 | $this->defaultLowestEvalExclude = $defaultLowestEvalExclude; |
||
| 317 | |||
| 318 | return $this; |
||
| 319 | } |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Get defaultLowestEvalExclude. |
||
| 323 | * |
||
| 324 | * @return bool |
||
| 325 | */ |
||
| 326 | public function getDefaultLowestEvalExclude() |
||
| 327 | { |
||
| 328 | return $this->defaultLowestEvalExclude; |
||
| 329 | } |
||
| 330 | |||
| 331 | public function setGenerateCertificates(bool $generateCertificates): self |
||
| 332 | { |
||
| 333 | $this->generateCertificates = $generateCertificates; |
||
| 334 | |||
| 335 | return $this; |
||
| 336 | } |
||
| 337 | |||
| 338 | /** |
||
| 339 | * Get generateCertificates. |
||
| 340 | * |
||
| 341 | * @return bool |
||
| 342 | */ |
||
| 343 | public function getGenerateCertificates() |
||
| 344 | { |
||
| 345 | return $this->generateCertificates; |
||
| 346 | } |
||
| 347 | |||
| 348 | public function setIsRequirement(bool $isRequirement): self |
||
| 349 | { |
||
| 350 | $this->isRequirement = $isRequirement; |
||
| 351 | |||
| 352 | return $this; |
||
| 353 | } |
||
| 354 | |||
| 355 | public function getCourse(): Course |
||
| 356 | { |
||
| 357 | return $this->course; |
||
| 358 | } |
||
| 359 | |||
| 360 | public function setCourse(Course $course): self |
||
| 361 | { |
||
| 362 | $this->course = $course; |
||
| 363 | |||
| 364 | return $this; |
||
| 365 | } |
||
| 366 | |||
| 367 | public function getParent(): ?self |
||
| 368 | { |
||
| 369 | return $this->parent; |
||
| 370 | } |
||
| 371 | |||
| 372 | public function setParent(?self $parent): self |
||
| 373 | { |
||
| 374 | $this->parent = $parent; |
||
| 375 | |||
| 376 | return $this; |
||
| 377 | } |
||
| 378 | |||
| 379 | public function getSession(): ?Session |
||
| 380 | { |
||
| 381 | return $this->session; |
||
| 382 | } |
||
| 383 | |||
| 384 | public function setSession(?Session $session): self |
||
| 385 | { |
||
| 386 | $this->session = $session; |
||
| 387 | |||
| 388 | return $this; |
||
| 389 | } |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Get isRequirement. |
||
| 393 | * |
||
| 394 | * @return bool |
||
| 395 | */ |
||
| 396 | public function getIsRequirement() |
||
| 397 | { |
||
| 398 | return $this->isRequirement; |
||
| 399 | } |
||
| 400 | |||
| 401 | public function getGradeBooksToValidateInDependence(): int |
||
| 404 | } |
||
| 405 | |||
| 406 | public function setGradeBooksToValidateInDependence(int $value): self |
||
| 407 | { |
||
| 408 | $this->gradeBooksToValidateInDependence = $value; |
||
| 409 | |||
| 410 | return $this; |
||
| 411 | } |
||
| 412 | |||
| 413 | /** |
||
| 414 | * @return GradebookComment[]|Collection |
||
| 415 | */ |
||
| 416 | public function getComments() |
||
| 417 | { |
||
| 418 | return $this->comments; |
||
| 419 | } |
||
| 420 | |||
| 421 | /** |
||
| 422 | * @param GradebookComment[]|Collection $comments |
||
| 423 | */ |
||
| 424 | public function setComments(Collection $comments): self |
||
| 425 | { |
||
| 426 | $this->comments = $comments; |
||
| 427 | |||
| 428 | return $this; |
||
| 429 | } |
||
| 430 | |||
| 431 | public function getGradeModel(): ?GradeModel |
||
| 432 | { |
||
| 433 | return $this->gradeModel; |
||
| 434 | } |
||
| 435 | |||
| 436 | public function setGradeModel(?GradeModel $gradeModel): self |
||
| 437 | { |
||
| 438 | $this->gradeModel = $gradeModel; |
||
| 439 | |||
| 440 | return $this; |
||
| 441 | } |
||
| 442 | |||
| 443 | public function getUser(): User |
||
| 444 | { |
||
| 445 | return $this->user; |
||
| 446 | } |
||
| 447 | |||
| 448 | public function setUser(User $user): self |
||
| 449 | { |
||
| 450 | $this->user = $user; |
||
| 451 | |||
| 452 | return $this; |
||
| 453 | } |
||
| 454 | |||
| 455 | /** |
||
| 456 | * @return GradebookEvaluation[]|Collection |
||
| 457 | */ |
||
| 458 | public function getEvaluations() |
||
| 459 | { |
||
| 460 | return $this->evaluations; |
||
| 461 | } |
||
| 462 | |||
| 463 | /** |
||
| 464 | * @param GradebookEvaluation[]|Collection $evaluations |
||
| 465 | */ |
||
| 466 | public function setEvaluations(Collection $evaluations) |
||
| 467 | { |
||
| 468 | $this->evaluations = $evaluations; |
||
| 469 | |||
| 470 | return $this; |
||
| 471 | } |
||
| 472 | |||
| 473 | /** |
||
| 474 | * @return GradebookLink[]|Collection |
||
| 475 | */ |
||
| 476 | public function getLinks() |
||
| 479 | } |
||
| 480 | |||
| 481 | /** |
||
| 482 | * @param GradebookLink[]|Collection $links |
||
| 483 | */ |
||
| 484 | public function setLinks(Collection $links): self |
||
| 485 | { |
||
| 486 | $this->links = $links; |
||
| 487 | |||
| 488 | return $this; |
||
| 489 | } |
||
| 490 | |||
| 491 | public function getSubCategories() |
||
| 492 | { |
||
| 493 | return $this->subCategories; |
||
| 494 | } |
||
| 495 | |||
| 496 | public function hasSubCategories(): bool |
||
| 497 | { |
||
| 498 | return $this->subCategories->count() > 0; |
||
| 499 | } |
||
| 500 | |||
| 501 | public function setSubCategories(Collection $subCategories): self |
||
| 502 | { |
||
| 503 | $this->subCategories = $subCategories; |
||
| 504 | |||
| 505 | return $this; |
||
| 506 | } |
||
| 507 | |||
| 508 | public function getDepends(): ?string |
||
| 509 | { |
||
| 510 | return $this->depends; |
||
| 511 | } |
||
| 512 | |||
| 513 | public function setDepends(?string $depends): self |
||
| 514 | { |
||
| 515 | $this->depends = $depends; |
||
| 516 | |||
| 517 | return $this; |
||
| 518 | } |
||
| 519 | |||
| 520 | public function getMinimumToValidate(): ?int |
||
| 521 | { |
||
| 522 | return $this->minimumToValidate; |
||
| 523 | } |
||
| 524 | |||
| 525 | public function setMinimumToValidate(?int $minimumToValidate): self |
||
| 526 | { |
||
| 527 | $this->minimumToValidate = $minimumToValidate; |
||
| 528 | |||
| 529 | return $this; |
||
| 530 | } |
||
| 531 | |||
| 532 | public function getSkills() |
||
| 535 | } |
||
| 536 | |||
| 537 | /** |
||
| 538 | * @param GradebookCategory[]|Collection $skills |
||
| 539 | */ |
||
| 540 | public function setSkills(Collection $skills): self |
||
| 541 | { |
||
| 542 | $this->skills = $skills; |
||
| 543 | |||
| 544 | return $this; |
||
| 545 | } |
||
| 546 | |||
| 547 | |||
| 548 | } |
||
| 549 |