Passed
Pull Request — master (#6374)
by
unknown
08:17
created

GradebookCategory   C

Complexity

Total Complexity 53

Size/Duplication

Total Lines 526
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 168
c 0
b 0
f 0
dl 0
loc 526
rs 6.96
wmc 53

53 Methods

Rating   Name   Duplication   Size   Complexity  
A getGradeBooksToValidateInDependence() 0 3 1
A getLinks() 0 3 1
A setAllowSkillsBySubcategory() 0 5 1
A getSkills() 0 3 1
A setSession() 0 5 1
A getTitle() 0 3 1
A setIsRequirement() 0 5 1
A setGradeBooksToValidateInDependence() 0 5 1
A getUser() 0 3 1
A getId() 0 3 1
A getParent() 0 3 1
A setEvaluations() 0 5 1
A getCertifMinScore() 0 3 1
A hasSubCategories() 0 3 1
A getSession() 0 3 1
A getAllowSkillsBySubcategory() 0 3 1
A setCourse() 0 5 1
A getGradeModel() 0 3 1
A setGradeModel() 0 5 1
A setSkills() 0 5 1
A setDepends() 0 5 1
A setTitle() 0 5 1
A getEvaluations() 0 3 1
A setLinks() 0 5 1
A setComments() 0 5 1
A getMinimumToValidate() 0 3 1
A setDescription() 0 5 1
A setVisible() 0 5 1
A setWeight() 0 5 1
A getCourse() 0 3 1
A setUser() 0 5 1
A getComments() 0 3 1
A setCertifMinScore() 0 5 1
A getSubCategories() 0 3 1
A getDescription() 0 3 1
A __construct() 0 12 1
A getWeight() 0 3 1
A getVisible() 0 3 1
A setParent() 0 5 1
A setMinimumToValidate() 0 5 1
A getIsRequirement() 0 3 1
A setSubCategories() 0 5 1
A getDepends() 0 3 1
A setLocked() 0 5 1
A getDocument() 0 3 1
A setCertificateValidityPeriod() 0 5 1
A setDocument() 0 5 1
A setDefaultLowestEvalExclude() 0 5 1
A getDefaultLowestEvalExclude() 0 3 1
A getCertificateValidityPeriod() 0 3 1
A getGenerateCertificates() 0 3 1
A getLocked() 0 3 1
A setGenerateCertificates() 0 5 1

How to fix   Complexity   

Complex Class

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
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Entity;
8
9
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
10
use ApiPlatform\Metadata\ApiFilter;
11
use ApiPlatform\Metadata\ApiResource;
12
use Chamilo\CoreBundle\Traits\CourseTrait;
13
use Chamilo\CoreBundle\Traits\UserTrait;
14
use Chamilo\CourseBundle\Entity\CDocument;
15
use Doctrine\Common\Collections\ArrayCollection;
16
use Doctrine\Common\Collections\Collection;
17
use Doctrine\ORM\Mapping as ORM;
18
use Symfony\Component\Serializer\Annotation\Groups;
19
use Symfony\Component\Validator\Constraints as Assert;
20
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
182
    {
183
        return $this->title;
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()
245
    {
246
        return $this->certifMinScore;
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
262
    {
263
        $this->locked = $locked;
264
265
        return $this;
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
279
    {
280
        $this->defaultLowestEvalExclude = $defaultLowestEvalExclude;
281
282
        return $this;
283
    }
284
285
    /**
286
     * Get defaultLowestEvalExclude.
287
     *
288
     * @return bool
289
     */
290
    public function getDefaultLowestEvalExclude()
291
    {
292
        return $this->defaultLowestEvalExclude;
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()
308
    {
309
        return $this->generateCertificates;
310
    }
311
312
    public function getCertificateValidityPeriod(): ?int
313
    {
314
        return $this->certificateValidityPeriod;
315
    }
316
317
    public function setCertificateValidityPeriod(?int $certificateValidityPeriod): self
318
    {
319
        $this->certificateValidityPeriod = $certificateValidityPeriod;
320
321
        return $this;
322
    }
323
324
    public function setIsRequirement(bool $isRequirement): self
325
    {
326
        $this->isRequirement = $isRequirement;
327
328
        return $this;
329
    }
330
331
    public function getCourse(): Course
332
    {
333
        return $this->course;
334
    }
335
336
    public function setCourse(Course $course): self
337
    {
338
        $this->course = $course;
339
340
        return $this;
341
    }
342
343
    public function getParent(): ?self
344
    {
345
        return $this->parent;
346
    }
347
348
    public function setParent(?self $parent): self
349
    {
350
        $this->parent = $parent;
351
352
        return $this;
353
    }
354
355
    public function getSession(): ?Session
356
    {
357
        return $this->session;
358
    }
359
360
    public function setSession(?Session $session): self
361
    {
362
        $this->session = $session;
363
364
        return $this;
365
    }
366
367
    /**
368
     * Get isRequirement.
369
     *
370
     * @return bool
371
     */
372
    public function getIsRequirement()
373
    {
374
        return $this->isRequirement;
375
    }
376
377
    public function getGradeBooksToValidateInDependence(): int
378
    {
379
        return $this->gradeBooksToValidateInDependence;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->gradeBooksToValidateInDependence could return the type null which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
380
    }
381
382
    public function setGradeBooksToValidateInDependence(int $value): self
383
    {
384
        $this->gradeBooksToValidateInDependence = $value;
385
386
        return $this;
387
    }
388
389
    /**
390
     * @return GradebookComment[]|Collection
391
     */
392
    public function getComments(): array|Collection
393
    {
394
        return $this->comments;
395
    }
396
397
    /**
398
     * @param GradebookComment[]|Collection $comments
399
     */
400
    public function setComments(array|Collection $comments): self
401
    {
402
        $this->comments = $comments;
403
404
        return $this;
405
    }
406
407
    public function getGradeModel(): ?GradeModel
408
    {
409
        return $this->gradeModel;
410
    }
411
412
    public function setGradeModel(?GradeModel $gradeModel): self
413
    {
414
        $this->gradeModel = $gradeModel;
415
416
        return $this;
417
    }
418
419
    public function getUser(): User
420
    {
421
        return $this->user;
422
    }
423
424
    public function setUser(User $user): self
425
    {
426
        $this->user = $user;
427
428
        return $this;
429
    }
430
431
    /**
432
     * @return GradebookEvaluation[]|Collection
433
     */
434
    public function getEvaluations(): array|Collection
435
    {
436
        return $this->evaluations;
437
    }
438
439
    /**
440
     * @param GradebookEvaluation[]|Collection $evaluations
441
     */
442
    public function setEvaluations(array|Collection $evaluations): self
443
    {
444
        $this->evaluations = $evaluations;
445
446
        return $this;
447
    }
448
449
    /**
450
     * @return GradebookLink[]|Collection
451
     */
452
    public function getLinks(): array|Collection
453
    {
454
        return $this->links;
455
    }
456
457
    /**
458
     * @param GradebookLink[]|Collection $links
459
     */
460
    public function setLinks(array|Collection $links): self
461
    {
462
        $this->links = $links;
463
464
        return $this;
465
    }
466
467
    /**
468
     * @return GradebookCategory[]|Collection
469
     */
470
    public function getSubCategories(): array|Collection
471
    {
472
        return $this->subCategories;
473
    }
474
475
    public function hasSubCategories(): bool
476
    {
477
        return $this->subCategories->count() > 0;
478
    }
479
480
    public function setSubCategories(Collection $subCategories): self
481
    {
482
        $this->subCategories = $subCategories;
483
484
        return $this;
485
    }
486
487
    public function getDepends(): ?string
488
    {
489
        return $this->depends;
490
    }
491
492
    public function setDepends(?string $depends): self
493
    {
494
        $this->depends = $depends;
495
496
        return $this;
497
    }
498
499
    public function getMinimumToValidate(): ?int
500
    {
501
        return $this->minimumToValidate;
502
    }
503
504
    public function setMinimumToValidate(?int $minimumToValidate): self
505
    {
506
        $this->minimumToValidate = $minimumToValidate;
507
508
        return $this;
509
    }
510
511
    /**
512
     * @return SkillRelGradebook[]|Collection
513
     */
514
    public function getSkills(): array|Collection
515
    {
516
        return $this->skills;
517
    }
518
519
    /**
520
     * @param SkillRelGradebook[]|Collection $skills
521
     */
522
    public function setSkills(array|Collection $skills): self
523
    {
524
        $this->skills = $skills;
525
526
        return $this;
527
    }
528
529
    /**
530
     * @return int
531
     */
532
    public function getAllowSkillsBySubcategory()
533
    {
534
        return $this->allowSkillsBySubcategory;
535
    }
536
537
    /**
538
     * @param int $allowSkillsBySubcategory
539
     *
540
     * @return GradebookCategory
541
     */
542
    public function setAllowSkillsBySubcategory($allowSkillsBySubcategory)
543
    {
544
        $this->allowSkillsBySubcategory = $allowSkillsBySubcategory;
545
546
        return $this;
547
    }
548
}
549