Total Complexity | 78 |
Total Lines | 621 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like CLp 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 CLp, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
26 | #[ORM\Table(name: 'c_lp')] |
||
27 | #[ORM\Entity(repositoryClass: CLpRepository::class)] |
||
28 | class CLp extends AbstractResource implements ResourceInterface, ResourceShowCourseResourcesInSessionInterface, Stringable |
||
29 | { |
||
30 | public const LP_TYPE = 1; |
||
31 | public const SCORM_TYPE = 2; |
||
32 | public const AICC_TYPE = 3; |
||
33 | |||
34 | #[ORM\Column(name: 'iid', type: 'integer')] |
||
35 | #[ORM\Id] |
||
36 | #[ORM\GeneratedValue] |
||
37 | protected ?int $iid = null; |
||
38 | |||
39 | #[Assert\NotBlank] |
||
40 | #[ORM\Column(name: 'lp_type', type: 'integer', nullable: false)] |
||
41 | protected int $lpType; |
||
42 | |||
43 | #[Assert\NotBlank] |
||
44 | #[ORM\Column(name: 'title', type: 'string', length: 255, nullable: false)] |
||
45 | protected string $title; |
||
46 | |||
47 | #[ORM\Column(name: 'ref', type: 'text', nullable: true)] |
||
48 | protected ?string $ref = null; |
||
49 | |||
50 | #[ORM\Column(name: 'description', type: 'text', nullable: true)] |
||
51 | protected ?string $description; |
||
52 | |||
53 | #[ORM\Column(name: 'path', type: 'text', nullable: false)] |
||
54 | protected string $path; |
||
55 | |||
56 | #[ORM\Column(name: 'force_commit', type: 'boolean', nullable: false)] |
||
57 | protected bool $forceCommit; |
||
58 | |||
59 | #[ORM\Column(name: 'default_view_mod', type: 'string', length: 32, nullable: false, options: ['default' => 'embedded'])] |
||
60 | protected string $defaultViewMod; |
||
61 | |||
62 | #[ORM\Column(name: 'default_encoding', type: 'string', length: 32, nullable: false, options: ['default' => 'UTF-8'])] |
||
63 | protected string $defaultEncoding; |
||
64 | |||
65 | #[ORM\Column(name: 'content_maker', type: 'text', nullable: false)] |
||
66 | protected string $contentMaker; |
||
67 | |||
68 | #[ORM\Column(name: 'content_local', type: 'string', length: 32, nullable: false, options: ['default' => 'local'])] |
||
69 | protected string $contentLocal; |
||
70 | |||
71 | #[ORM\Column(name: 'content_license', type: 'text', nullable: false)] |
||
72 | protected string $contentLicense; |
||
73 | |||
74 | #[ORM\Column(name: 'prevent_reinit', type: 'boolean', nullable: false, options: ['default' => 1])] |
||
75 | protected bool $preventReinit; |
||
76 | |||
77 | #[ORM\Column(name: 'js_lib', type: 'text', nullable: false)] |
||
78 | protected string $jsLib; |
||
79 | |||
80 | #[ORM\Column(name: 'debug', type: 'boolean', nullable: false)] |
||
81 | protected bool $debug; |
||
82 | |||
83 | #[Assert\NotBlank] |
||
84 | #[ORM\Column(name: 'theme', type: 'string', length: 255, nullable: false)] |
||
85 | protected string $theme; |
||
86 | |||
87 | #[Assert\NotBlank] |
||
88 | #[ORM\Column(name: 'author', type: 'text', nullable: false)] |
||
89 | protected string $author; |
||
90 | |||
91 | #[ORM\Column(name: 'prerequisite', type: 'integer', nullable: false)] |
||
92 | protected int $prerequisite; |
||
93 | |||
94 | #[ORM\Column(name: 'hide_toc_frame', type: 'boolean', nullable: false)] |
||
95 | protected bool $hideTocFrame; |
||
96 | |||
97 | #[ORM\Column(name: 'seriousgame_mode', type: 'boolean', nullable: false)] |
||
98 | protected bool $seriousgameMode; |
||
99 | |||
100 | #[ORM\Column(name: 'use_max_score', type: 'integer', nullable: false, options: ['default' => 1])] |
||
101 | protected int $useMaxScore; |
||
102 | |||
103 | #[ORM\Column(name: 'autolaunch', type: 'integer', nullable: false)] |
||
104 | protected int $autolaunch; |
||
105 | |||
106 | #[ORM\ManyToOne(targetEntity: CLpCategory::class, inversedBy: 'lps')] |
||
107 | #[ORM\JoinColumn(name: 'category_id', referencedColumnName: 'iid')] |
||
108 | protected ?CLpCategory $category = null; |
||
109 | |||
110 | #[ORM\Column(name: 'max_attempts', type: 'integer', nullable: false)] |
||
111 | protected int $maxAttempts; |
||
112 | |||
113 | #[ORM\Column(name: 'subscribe_users', type: 'integer', nullable: false)] |
||
114 | protected int $subscribeUsers; |
||
115 | |||
116 | #[Gedmo\Timestampable(on: 'create')] |
||
117 | #[ORM\Column(name: 'created_on', type: 'datetime', nullable: false)] |
||
118 | protected DateTime $createdOn; |
||
119 | |||
120 | #[Gedmo\Timestampable(on: 'update')] |
||
121 | #[ORM\Column(name: 'modified_on', type: 'datetime', nullable: false)] |
||
122 | protected DateTime $modifiedOn; |
||
123 | |||
124 | #[ORM\Column(name: 'published_on', type: 'datetime', nullable: true)] |
||
125 | protected ?DateTime $publishedOn; |
||
126 | |||
127 | #[ORM\Column(name: 'expired_on', type: 'datetime', nullable: true)] |
||
128 | protected ?DateTime $expiredOn = null; |
||
129 | |||
130 | #[ORM\Column(name: 'accumulate_scorm_time', type: 'integer', nullable: false, options: ['default' => 1])] |
||
131 | protected int $accumulateScormTime; |
||
132 | |||
133 | #[ORM\Column(name: 'accumulate_work_time', type: 'integer', nullable: false, options: ['default' => 0])] |
||
134 | protected int $accumulateWorkTime; |
||
135 | |||
136 | #[ORM\Column(name: 'next_lp_id', type: 'integer', nullable: false, options: ['default' => 0])] |
||
137 | protected int $nextLpId; |
||
138 | |||
139 | #[ORM\OneToMany(mappedBy: 'lp', targetEntity: CLpItem::class, cascade: ['persist', 'remove'], orphanRemoval: true)] |
||
140 | protected Collection $items; |
||
141 | |||
142 | /** |
||
143 | * @var Collection<int, CForum> |
||
144 | */ |
||
145 | #[ORM\OneToMany(mappedBy: 'lp', targetEntity: CForum::class, cascade: ['persist', 'remove'])] |
||
146 | protected Collection $forums; |
||
147 | |||
148 | #[ORM\ManyToOne(targetEntity: Asset::class, cascade: ['persist', 'remove'])] |
||
149 | #[ORM\JoinColumn(name: 'asset_id', referencedColumnName: 'id')] |
||
150 | protected ?Asset $asset = null; |
||
151 | |||
152 | #[ORM\Column(name: 'duration', type: 'integer', nullable: true)] |
||
153 | protected ?int $duration = null; |
||
154 | |||
155 | #[ORM\Column(name: 'validity_in_days', type: 'integer', nullable: true)] |
||
156 | protected ?int $validityInDays = null; |
||
157 | |||
158 | public function __construct() |
||
159 | { |
||
160 | $now = new DateTime(); |
||
161 | $this->createdOn = $now; |
||
162 | $this->modifiedOn = $now; |
||
163 | $this->publishedOn = $now; |
||
164 | $this->accumulateScormTime = 1; |
||
165 | $this->accumulateWorkTime = 0; |
||
166 | $this->author = ''; |
||
167 | $this->autolaunch = 0; |
||
168 | $this->contentLocal = 'local'; |
||
169 | $this->contentMaker = 'chamilo'; |
||
170 | $this->contentLicense = ''; |
||
171 | $this->defaultEncoding = 'UTF-8'; |
||
172 | $this->defaultViewMod = 'embedded'; |
||
173 | $this->description = ''; |
||
174 | $this->debug = false; |
||
175 | $this->forceCommit = false; |
||
176 | $this->hideTocFrame = false; |
||
177 | $this->jsLib = ''; |
||
178 | $this->maxAttempts = 0; |
||
179 | $this->preventReinit = true; |
||
180 | $this->path = ''; |
||
181 | $this->prerequisite = 0; |
||
182 | $this->seriousgameMode = false; |
||
183 | $this->subscribeUsers = 0; |
||
184 | $this->useMaxScore = 1; |
||
185 | $this->theme = ''; |
||
186 | $this->nextLpId = 0; |
||
187 | $this->items = new ArrayCollection(); |
||
188 | $this->forums = new ArrayCollection(); |
||
189 | } |
||
190 | |||
191 | public function __toString(): string |
||
192 | { |
||
193 | return $this->getTitle(); |
||
194 | } |
||
195 | |||
196 | public function setLpType(int $lpType): self |
||
197 | { |
||
198 | $this->lpType = $lpType; |
||
199 | |||
200 | return $this; |
||
201 | } |
||
202 | |||
203 | public function getLpType(): int |
||
204 | { |
||
205 | return $this->lpType; |
||
206 | } |
||
207 | |||
208 | public function setTitle(string $title): self |
||
209 | { |
||
210 | $this->title = $title; |
||
211 | |||
212 | return $this; |
||
213 | } |
||
214 | |||
215 | public function getTitle(): string |
||
216 | { |
||
217 | return $this->title; |
||
218 | } |
||
219 | |||
220 | public function setRef(string $ref): self |
||
225 | } |
||
226 | |||
227 | public function getRef(): ?string |
||
228 | { |
||
229 | return $this->ref; |
||
230 | } |
||
231 | |||
232 | public function setDescription(string $description): self |
||
233 | { |
||
234 | $this->description = $description; |
||
235 | |||
236 | return $this; |
||
237 | } |
||
238 | |||
239 | public function getDescription(): ?string |
||
240 | { |
||
241 | return $this->description; |
||
242 | } |
||
243 | |||
244 | public function setPath(string $path): self |
||
245 | { |
||
246 | $this->path = $path; |
||
247 | |||
248 | return $this; |
||
249 | } |
||
250 | |||
251 | public function getPath(): string |
||
252 | { |
||
253 | return $this->path; |
||
254 | } |
||
255 | |||
256 | public function setForceCommit(bool $forceCommit): self |
||
257 | { |
||
258 | $this->forceCommit = $forceCommit; |
||
259 | |||
260 | return $this; |
||
261 | } |
||
262 | |||
263 | public function getForceCommit(): bool |
||
264 | { |
||
265 | return $this->forceCommit; |
||
266 | } |
||
267 | |||
268 | public function setDefaultViewMod(string $defaultViewMod): self |
||
269 | { |
||
270 | $this->defaultViewMod = $defaultViewMod; |
||
271 | |||
272 | return $this; |
||
273 | } |
||
274 | |||
275 | public function getDefaultViewMod(): string |
||
276 | { |
||
277 | return $this->defaultViewMod; |
||
278 | } |
||
279 | |||
280 | public function setDefaultEncoding(string $defaultEncoding): self |
||
281 | { |
||
282 | $this->defaultEncoding = $defaultEncoding; |
||
283 | |||
284 | return $this; |
||
285 | } |
||
286 | |||
287 | public function getDefaultEncoding(): string |
||
288 | { |
||
289 | return $this->defaultEncoding; |
||
290 | } |
||
291 | |||
292 | public function setContentMaker(string $contentMaker): self |
||
293 | { |
||
294 | $this->contentMaker = $contentMaker; |
||
295 | |||
296 | return $this; |
||
297 | } |
||
298 | |||
299 | public function getContentMaker(): string |
||
300 | { |
||
301 | return $this->contentMaker; |
||
302 | } |
||
303 | |||
304 | public function setContentLocal(string $contentLocal): self |
||
305 | { |
||
306 | $this->contentLocal = $contentLocal; |
||
307 | |||
308 | return $this; |
||
309 | } |
||
310 | |||
311 | public function getContentLocal(): string |
||
312 | { |
||
313 | return $this->contentLocal; |
||
314 | } |
||
315 | |||
316 | public function setContentLicense(string $contentLicense): self |
||
317 | { |
||
318 | $this->contentLicense = $contentLicense; |
||
319 | |||
320 | return $this; |
||
321 | } |
||
322 | |||
323 | public function getContentLicense(): string |
||
324 | { |
||
325 | return $this->contentLicense; |
||
326 | } |
||
327 | |||
328 | public function setPreventReinit(bool $preventReinit): self |
||
329 | { |
||
330 | $this->preventReinit = $preventReinit; |
||
331 | |||
332 | return $this; |
||
333 | } |
||
334 | |||
335 | public function getPreventReinit(): bool |
||
336 | { |
||
337 | return $this->preventReinit; |
||
338 | } |
||
339 | |||
340 | public function setJsLib(string $jsLib): self |
||
341 | { |
||
342 | $this->jsLib = $jsLib; |
||
343 | |||
344 | return $this; |
||
345 | } |
||
346 | |||
347 | public function getJsLib(): string |
||
348 | { |
||
349 | return $this->jsLib; |
||
350 | } |
||
351 | |||
352 | public function setDebug(bool $debug): self |
||
353 | { |
||
354 | $this->debug = $debug; |
||
355 | |||
356 | return $this; |
||
357 | } |
||
358 | |||
359 | public function getDebug(): bool |
||
360 | { |
||
361 | return $this->debug; |
||
362 | } |
||
363 | |||
364 | public function setTheme(string $theme): self |
||
365 | { |
||
366 | $this->theme = $theme; |
||
367 | |||
368 | return $this; |
||
369 | } |
||
370 | |||
371 | public function getTheme(): string |
||
372 | { |
||
373 | return $this->theme; |
||
374 | } |
||
375 | |||
376 | public function setAuthor(string $author): self |
||
377 | { |
||
378 | $this->author = $author; |
||
379 | |||
380 | return $this; |
||
381 | } |
||
382 | |||
383 | public function getAuthor(): string |
||
384 | { |
||
385 | return $this->author; |
||
386 | } |
||
387 | |||
388 | public function setPrerequisite(int $prerequisite): self |
||
389 | { |
||
390 | $this->prerequisite = $prerequisite; |
||
391 | |||
392 | return $this; |
||
393 | } |
||
394 | |||
395 | public function getPrerequisite(): int |
||
396 | { |
||
397 | return $this->prerequisite; |
||
398 | } |
||
399 | |||
400 | public function setHideTocFrame(bool $hideTocFrame): self |
||
401 | { |
||
402 | $this->hideTocFrame = $hideTocFrame; |
||
403 | |||
404 | return $this; |
||
405 | } |
||
406 | |||
407 | public function getHideTocFrame(): bool |
||
408 | { |
||
409 | return $this->hideTocFrame; |
||
410 | } |
||
411 | |||
412 | public function setSeriousgameMode(bool $seriousgameMode): self |
||
413 | { |
||
414 | $this->seriousgameMode = $seriousgameMode; |
||
415 | |||
416 | return $this; |
||
417 | } |
||
418 | |||
419 | public function getSeriousgameMode(): bool |
||
420 | { |
||
421 | return $this->seriousgameMode; |
||
422 | } |
||
423 | |||
424 | public function setUseMaxScore(int $useMaxScore): self |
||
425 | { |
||
426 | $this->useMaxScore = $useMaxScore; |
||
427 | |||
428 | return $this; |
||
429 | } |
||
430 | |||
431 | public function getUseMaxScore(): int |
||
432 | { |
||
433 | return $this->useMaxScore; |
||
434 | } |
||
435 | |||
436 | public function setAutolaunch(int $autolaunch): self |
||
437 | { |
||
438 | $this->autolaunch = $autolaunch; |
||
439 | |||
440 | return $this; |
||
441 | } |
||
442 | |||
443 | public function getAutolaunch(): int |
||
444 | { |
||
445 | return $this->autolaunch; |
||
446 | } |
||
447 | |||
448 | public function setCreatedOn(DateTime $createdOn): self |
||
449 | { |
||
450 | $this->createdOn = $createdOn; |
||
451 | |||
452 | return $this; |
||
453 | } |
||
454 | |||
455 | public function getCreatedOn(): DateTime |
||
456 | { |
||
457 | return $this->createdOn; |
||
458 | } |
||
459 | |||
460 | public function setModifiedOn(DateTime $modifiedOn): self |
||
461 | { |
||
462 | $this->modifiedOn = $modifiedOn; |
||
463 | |||
464 | return $this; |
||
465 | } |
||
466 | |||
467 | public function getModifiedOn(): DateTime |
||
468 | { |
||
469 | return $this->modifiedOn; |
||
470 | } |
||
471 | |||
472 | public function setPublishedOn(?DateTime $publishedOn): self |
||
473 | { |
||
474 | $this->publishedOn = $publishedOn; |
||
475 | |||
476 | return $this; |
||
477 | } |
||
478 | |||
479 | public function getPublishedOn(): ?DateTime |
||
480 | { |
||
481 | return $this->publishedOn; |
||
482 | } |
||
483 | |||
484 | public function setExpiredOn(?DateTime $expiredOn): self |
||
485 | { |
||
486 | $this->expiredOn = $expiredOn; |
||
487 | |||
488 | return $this; |
||
489 | } |
||
490 | |||
491 | public function getExpiredOn(): ?DateTime |
||
492 | { |
||
493 | return $this->expiredOn; |
||
494 | } |
||
495 | |||
496 | public function getCategory(): ?CLpCategory |
||
497 | { |
||
498 | return $this->category; |
||
499 | } |
||
500 | |||
501 | public function hasCategory(): bool |
||
502 | { |
||
503 | return null !== $this->category; |
||
504 | } |
||
505 | |||
506 | public function setCategory(?CLpCategory $category = null): self |
||
507 | { |
||
508 | $this->category = $category; |
||
509 | |||
510 | return $this; |
||
511 | } |
||
512 | |||
513 | public function getAccumulateScormTime(): int |
||
514 | { |
||
515 | return $this->accumulateScormTime; |
||
516 | } |
||
517 | |||
518 | public function setAccumulateScormTime(int $accumulateScormTime): self |
||
519 | { |
||
520 | $this->accumulateScormTime = $accumulateScormTime; |
||
521 | |||
522 | return $this; |
||
523 | } |
||
524 | |||
525 | public function getAccumulateWorkTime(): int |
||
526 | { |
||
527 | return $this->accumulateWorkTime; |
||
528 | } |
||
529 | |||
530 | public function setAccumulateWorkTime(int $accumulateWorkTime): self |
||
531 | { |
||
532 | $this->accumulateWorkTime = $accumulateWorkTime; |
||
533 | |||
534 | return $this; |
||
535 | } |
||
536 | |||
537 | public function getMaxAttempts(): int |
||
538 | { |
||
539 | return $this->maxAttempts; |
||
540 | } |
||
541 | |||
542 | public function getNextLpId(): int |
||
543 | { |
||
544 | return $this->nextLpId; |
||
545 | } |
||
546 | |||
547 | public function setNextLpId(int $nextLpId): self |
||
548 | { |
||
549 | $this->nextLpId = $nextLpId; |
||
550 | |||
551 | return $this; |
||
552 | } |
||
553 | |||
554 | /** |
||
555 | * @return Collection<int, CLpItem> |
||
556 | */ |
||
557 | public function getItems(): Collection |
||
558 | { |
||
559 | return $this->items; |
||
560 | } |
||
561 | |||
562 | public function getIid(): ?int |
||
563 | { |
||
564 | return $this->iid; |
||
565 | } |
||
566 | |||
567 | public function getSubscribeUsers(): int |
||
568 | { |
||
569 | return $this->subscribeUsers; |
||
570 | } |
||
571 | |||
572 | public function setSubscribeUsers(int $value): self |
||
573 | { |
||
574 | $this->subscribeUsers = $value; |
||
575 | |||
576 | return $this; |
||
577 | } |
||
578 | |||
579 | /** |
||
580 | * @return Collection<int, CForum> |
||
581 | */ |
||
582 | public function getForums(): Collection |
||
583 | { |
||
584 | return $this->forums; |
||
585 | } |
||
586 | |||
587 | public function setForums(ArrayCollection|Collection $forums): self |
||
588 | { |
||
589 | $this->forums = $forums; |
||
590 | |||
591 | return $this; |
||
592 | } |
||
593 | |||
594 | public function getAsset(): ?Asset |
||
595 | { |
||
596 | return $this->asset; |
||
597 | } |
||
598 | |||
599 | public function hasAsset(): bool |
||
600 | { |
||
601 | return null !== $this->asset; |
||
602 | } |
||
603 | |||
604 | public function setAsset(?Asset $asset): self |
||
605 | { |
||
606 | $this->asset = $asset; |
||
607 | |||
608 | return $this; |
||
609 | } |
||
610 | |||
611 | public function getDuration(): ?int |
||
612 | { |
||
613 | return $this->duration; |
||
614 | } |
||
615 | |||
616 | public function setDuration(?int $duration): self |
||
617 | { |
||
618 | $this->duration = $duration; |
||
619 | |||
620 | return $this; |
||
621 | } |
||
622 | |||
623 | public function getValidityInDays(): ?int |
||
624 | { |
||
625 | return $this->validityInDays; |
||
626 | } |
||
627 | |||
628 | public function setValidityInDays(?int $validityInDays): self |
||
629 | { |
||
630 | $this->validityInDays = $validityInDays; |
||
631 | return $this; |
||
632 | } |
||
633 | |||
634 | public function getResourceIdentifier(): int|Uuid |
||
637 | } |
||
638 | |||
639 | public function getResourceName(): string |
||
640 | { |
||
641 | return $this->getTitle(); |
||
642 | } |
||
643 | |||
644 | public function setResourceName(string $name): self |
||
645 | { |
||
646 | return $this->setTitle($name); |
||
647 | } |
||
648 | } |
||
649 |