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