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