Total Complexity | 78 |
Total Lines | 626 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Complex classes like CSurvey 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 CSurvey, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | #[ORM\Table(name: 'c_survey')] |
||
22 | #[ORM\Index(columns: ['code'], name: 'idx_survey_code')] |
||
23 | #[Gedmo\Tree(type: 'nested')] |
||
24 | #[ORM\Entity(repositoryClass: CSurveyRepository::class)] |
||
25 | class CSurvey extends AbstractResource implements ResourceInterface, Stringable |
||
26 | { |
||
27 | #[ORM\Column(name: 'iid', type: 'integer')] |
||
28 | #[ORM\Id] |
||
29 | #[ORM\GeneratedValue] |
||
30 | protected ?int $iid = null; |
||
31 | |||
32 | #[Assert\NotBlank] |
||
33 | #[ORM\Column(name: 'code', type: 'string', length: 40, nullable: true)] |
||
34 | protected ?string $code = null; |
||
35 | |||
36 | #[Assert\NotBlank] |
||
37 | #[ORM\Column(name: 'title', type: 'text', nullable: false)] |
||
38 | protected string $title; |
||
39 | |||
40 | #[ORM\Column(name: 'subtitle', type: 'text', nullable: true)] |
||
41 | protected ?string $subtitle; |
||
42 | |||
43 | #[ORM\Column(name: 'lang', type: 'string', length: 20, nullable: true)] |
||
44 | protected ?string $lang; |
||
45 | |||
46 | #[ORM\Column(name: 'avail_from', type: 'datetime', nullable: true)] |
||
47 | protected ?DateTime $availFrom = null; |
||
48 | |||
49 | #[ORM\Column(name: 'avail_till', type: 'datetime', nullable: true)] |
||
50 | protected ?DateTime $availTill = null; |
||
51 | |||
52 | #[ORM\Column(name: 'is_shared', type: 'string', length: 1, nullable: true)] |
||
53 | protected ?string $isShared = null; |
||
54 | |||
55 | #[ORM\Column(name: 'template', type: 'string', length: 20, nullable: true)] |
||
56 | protected ?string $template = null; |
||
57 | |||
58 | #[ORM\Column(name: 'intro', type: 'text', nullable: true)] |
||
59 | protected ?string $intro = null; |
||
60 | |||
61 | #[ORM\Column(name: 'surveythanks', type: 'text', nullable: true)] |
||
62 | protected ?string $surveyThanks = null; |
||
63 | |||
64 | #[ORM\Column(name: 'creation_date', type: 'datetime', nullable: false)] |
||
65 | protected DateTime $creationDate; |
||
66 | |||
67 | #[ORM\Column(name: 'invited', type: 'integer', nullable: false)] |
||
68 | protected int $invited; |
||
69 | |||
70 | #[ORM\Column(name: 'answered', type: 'integer', nullable: false)] |
||
71 | protected int $answered; |
||
72 | |||
73 | #[ORM\Column(name: 'invite_mail', type: 'text', nullable: false)] |
||
74 | protected string $inviteMail; |
||
75 | |||
76 | #[ORM\Column(name: 'reminder_mail', type: 'text', nullable: false)] |
||
77 | protected string $reminderMail; |
||
78 | |||
79 | #[ORM\Column(name: 'mail_subject', type: 'string', length: 255, nullable: false)] |
||
80 | protected string $mailSubject; |
||
81 | |||
82 | #[Assert\NotBlank] |
||
83 | #[ORM\Column(name: 'anonymous', type: 'string', length: 10, nullable: false)] |
||
84 | protected string $anonymous; |
||
85 | |||
86 | #[ORM\Column(name: 'access_condition', type: 'text', nullable: true)] |
||
87 | protected ?string $accessCondition = null; |
||
88 | |||
89 | #[ORM\Column(name: 'shuffle', type: 'boolean', nullable: false)] |
||
90 | protected bool $shuffle; |
||
91 | |||
92 | #[ORM\Column(name: 'one_question_per_page', type: 'boolean', nullable: false)] |
||
93 | protected bool $oneQuestionPerPage; |
||
94 | |||
95 | #[ORM\Column(name: 'survey_version', type: 'string', length: 255, nullable: false)] |
||
96 | protected string $surveyVersion; |
||
97 | |||
98 | #[Gedmo\TreeLeft] |
||
99 | #[ORM\Column(name: 'lft', type: 'integer', unique: false, nullable: true)] |
||
100 | protected ?int $lft = null; |
||
101 | |||
102 | #[Gedmo\TreeRight] |
||
103 | #[ORM\Column(name: 'rgt', type: 'integer', unique: false, nullable: true)] |
||
104 | protected ?int $rgt = null; |
||
105 | |||
106 | #[Gedmo\TreeLevel] |
||
107 | #[ORM\Column(name: 'lvl', type: 'integer', unique: false, nullable: true)] |
||
108 | protected ?int $lvl = null; |
||
109 | |||
110 | /** |
||
111 | * @var Collection<int, CSurveyQuestion> |
||
112 | */ |
||
113 | #[ORM\OneToMany(mappedBy: 'survey', targetEntity: CSurveyQuestion::class, cascade: ['remove'])] |
||
114 | protected Collection $questions; |
||
115 | |||
116 | /** |
||
117 | * @var Collection<int, CSurveyInvitation> |
||
118 | */ |
||
119 | #[ORM\OneToMany(mappedBy: 'survey', targetEntity: CSurveyInvitation::class, cascade: ['remove'])] |
||
120 | protected Collection $invitations; |
||
121 | |||
122 | #[Gedmo\TreeParent] |
||
123 | #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')] |
||
124 | #[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'iid', onDelete: 'CASCADE')] |
||
125 | protected ?CSurvey $surveyParent = null; |
||
126 | |||
127 | /** |
||
128 | * @var Collection<int, CSurvey> |
||
129 | */ |
||
130 | #[ORM\OneToMany(mappedBy: 'surveyParent', targetEntity: self::class)] |
||
131 | protected Collection $children; |
||
132 | |||
133 | /** |
||
134 | * @var Collection<int, CSurveyQuestionOption> |
||
135 | */ |
||
136 | #[ORM\OrderBy(['sort' => 'ASC'])] |
||
137 | #[ORM\OneToMany(mappedBy: 'survey', targetEntity: CSurveyQuestionOption::class, cascade: ['remove'])] |
||
138 | protected Collection $options; |
||
139 | |||
140 | #[ORM\Column(name: 'survey_type', type: 'integer', nullable: false)] |
||
141 | protected int $surveyType; |
||
142 | |||
143 | #[ORM\Column(name: 'show_form_profile', type: 'integer', nullable: false)] |
||
144 | protected int $showFormProfile; |
||
145 | |||
146 | #[ORM\Column(name: 'form_fields', type: 'text', nullable: false)] |
||
147 | protected string $formFields; |
||
148 | |||
149 | #[ORM\Column(name: 'visible_results', type: 'integer', nullable: true)] |
||
150 | protected ?int $visibleResults = null; |
||
151 | |||
152 | #[ORM\Column(name: 'is_mandatory', type: 'boolean', options: ['default' => false])] |
||
153 | protected bool $isMandatory = false; |
||
154 | |||
155 | #[ORM\Column(name: 'display_question_number', type: 'boolean', options: ['default' => true])] |
||
156 | protected bool $displayQuestionNumber; |
||
157 | |||
158 | public function __construct() |
||
159 | { |
||
160 | $this->title = ''; |
||
161 | $this->creationDate = new DateTime(); |
||
162 | $this->invited = 0; |
||
163 | $this->answered = 0; |
||
164 | $this->anonymous = '0'; |
||
165 | $this->formFields = '0'; |
||
166 | $this->subtitle = ''; |
||
167 | $this->inviteMail = ''; |
||
168 | $this->lang = ''; |
||
169 | $this->reminderMail = ''; |
||
170 | $this->mailSubject = ''; |
||
171 | $this->shuffle = false; |
||
172 | $this->oneQuestionPerPage = false; |
||
173 | $this->surveyVersion = ''; |
||
174 | $this->surveyType = 0; |
||
175 | $this->showFormProfile = 0; |
||
176 | $this->questions = new ArrayCollection(); |
||
177 | $this->children = new ArrayCollection(); |
||
178 | $this->invitations = new ArrayCollection(); |
||
179 | $this->options = new ArrayCollection(); |
||
180 | $this->displayQuestionNumber = true; |
||
181 | } |
||
182 | |||
183 | public function __toString(): string |
||
184 | { |
||
185 | return (string) $this->getCode(); |
||
186 | } |
||
187 | |||
188 | public function getCode(): ?string |
||
189 | { |
||
190 | return $this->code; |
||
191 | } |
||
192 | |||
193 | public function setCode(string $code): self |
||
194 | { |
||
195 | $this->code = $code; |
||
196 | |||
197 | return $this; |
||
198 | } |
||
199 | |||
200 | public function getTitle(): string |
||
201 | { |
||
202 | return $this->title; |
||
203 | } |
||
204 | |||
205 | public function setTitle(string $title): self |
||
206 | { |
||
207 | $this->title = $title; |
||
208 | |||
209 | return $this; |
||
210 | } |
||
211 | |||
212 | public function getSubtitle(): ?string |
||
213 | { |
||
214 | return $this->subtitle; |
||
215 | } |
||
216 | |||
217 | public function setSubtitle(string $subtitle): self |
||
222 | } |
||
223 | |||
224 | public function getLang(): ?string |
||
225 | { |
||
226 | return $this->lang; |
||
227 | } |
||
228 | |||
229 | public function setLang(string $lang): self |
||
234 | } |
||
235 | |||
236 | public function getAvailFrom(): ?DateTime |
||
237 | { |
||
238 | return $this->availFrom; |
||
239 | } |
||
240 | |||
241 | public function setAvailFrom(DateTime $availFrom = null): self |
||
242 | { |
||
243 | if (null === $availFrom) { |
||
244 | $availFrom = new DateTime(); |
||
245 | } |
||
246 | $this->availFrom = $availFrom; |
||
247 | |||
248 | return $this; |
||
249 | } |
||
250 | |||
251 | public function getAvailTill(): ?DateTime |
||
252 | { |
||
253 | return $this->availTill; |
||
254 | } |
||
255 | |||
256 | public function setAvailTill(DateTime $availTill = null): self |
||
257 | { |
||
258 | if (null === $availTill) { |
||
259 | $availTill = new DateTime(); |
||
260 | } |
||
261 | $this->availTill = $availTill; |
||
262 | |||
263 | return $this; |
||
264 | } |
||
265 | |||
266 | public function getIsShared(): ?string |
||
267 | { |
||
268 | return $this->isShared; |
||
269 | } |
||
270 | |||
271 | public function setIsShared(string $isShared): self |
||
272 | { |
||
273 | $this->isShared = $isShared; |
||
274 | |||
275 | return $this; |
||
276 | } |
||
277 | |||
278 | public function getTemplate(): ?string |
||
279 | { |
||
280 | return $this->template; |
||
281 | } |
||
282 | |||
283 | public function setTemplate(string $template): self |
||
284 | { |
||
285 | $this->template = $template; |
||
286 | |||
287 | return $this; |
||
288 | } |
||
289 | |||
290 | public function getIntro(): ?string |
||
291 | { |
||
292 | return $this->intro; |
||
293 | } |
||
294 | |||
295 | public function setIntro(string $intro): self |
||
296 | { |
||
297 | $this->intro = $intro; |
||
298 | |||
299 | return $this; |
||
300 | } |
||
301 | |||
302 | public function getSurveythanks(): ?string |
||
303 | { |
||
304 | return $this->surveyThanks; |
||
305 | } |
||
306 | |||
307 | public function setSurveythanks(string $surveythanks): self |
||
308 | { |
||
309 | $this->surveyThanks = $surveythanks; |
||
310 | |||
311 | return $this; |
||
312 | } |
||
313 | |||
314 | public function getCreationDate(): DateTime |
||
315 | { |
||
316 | return $this->creationDate; |
||
317 | } |
||
318 | |||
319 | public function setCreationDate(DateTime $creationDate): self |
||
320 | { |
||
321 | $this->creationDate = $creationDate; |
||
322 | |||
323 | return $this; |
||
324 | } |
||
325 | |||
326 | public function getInvited(): int |
||
327 | { |
||
328 | return $this->invited; |
||
329 | } |
||
330 | |||
331 | public function setInvited(int $invited): self |
||
332 | { |
||
333 | $this->invited = $invited; |
||
334 | |||
335 | return $this; |
||
336 | } |
||
337 | |||
338 | public function getAnswered(): int |
||
339 | { |
||
340 | return $this->answered; |
||
341 | } |
||
342 | |||
343 | public function setAnswered(int $answered): self |
||
344 | { |
||
345 | $this->answered = $answered; |
||
346 | |||
347 | return $this; |
||
348 | } |
||
349 | |||
350 | public function getInviteMail(): string |
||
351 | { |
||
352 | return $this->inviteMail; |
||
353 | } |
||
354 | |||
355 | public function setInviteMail(string $inviteMail): self |
||
356 | { |
||
357 | $this->inviteMail = $inviteMail; |
||
358 | |||
359 | return $this; |
||
360 | } |
||
361 | |||
362 | public function getReminderMail(): string |
||
363 | { |
||
364 | return $this->reminderMail; |
||
365 | } |
||
366 | |||
367 | public function setReminderMail(string $reminderMail): self |
||
368 | { |
||
369 | $this->reminderMail = $reminderMail; |
||
370 | |||
371 | return $this; |
||
372 | } |
||
373 | |||
374 | public function getMailSubject(): string |
||
375 | { |
||
376 | return $this->mailSubject; |
||
377 | } |
||
378 | |||
379 | public function setMailSubject(string $mailSubject): self |
||
380 | { |
||
381 | $this->mailSubject = $mailSubject; |
||
382 | |||
383 | return $this; |
||
384 | } |
||
385 | |||
386 | public function getAnonymous(): string |
||
387 | { |
||
388 | return $this->anonymous; |
||
389 | } |
||
390 | |||
391 | public function setAnonymous(string $anonymous): self |
||
392 | { |
||
393 | $this->anonymous = $anonymous; |
||
394 | |||
395 | return $this; |
||
396 | } |
||
397 | |||
398 | public function getAccessCondition(): ?string |
||
399 | { |
||
400 | return $this->accessCondition; |
||
401 | } |
||
402 | |||
403 | public function setAccessCondition(string $accessCondition): self |
||
404 | { |
||
405 | $this->accessCondition = $accessCondition; |
||
406 | |||
407 | return $this; |
||
408 | } |
||
409 | |||
410 | public function getShuffle(): bool |
||
411 | { |
||
412 | return $this->shuffle; |
||
413 | } |
||
414 | |||
415 | public function setShuffle(bool $shuffle): self |
||
416 | { |
||
417 | $this->shuffle = $shuffle; |
||
418 | |||
419 | return $this; |
||
420 | } |
||
421 | |||
422 | public function getOneQuestionPerPage(): bool |
||
423 | { |
||
424 | return $this->oneQuestionPerPage; |
||
425 | } |
||
426 | |||
427 | public function setOneQuestionPerPage(bool $oneQuestionPerPage): self |
||
428 | { |
||
429 | $this->oneQuestionPerPage = $oneQuestionPerPage; |
||
430 | |||
431 | return $this; |
||
432 | } |
||
433 | |||
434 | public function getSurveyVersion(): string |
||
435 | { |
||
436 | return $this->surveyVersion; |
||
437 | } |
||
438 | |||
439 | public function setSurveyVersion(string $surveyVersion): self |
||
440 | { |
||
441 | $this->surveyVersion = $surveyVersion; |
||
442 | |||
443 | return $this; |
||
444 | } |
||
445 | |||
446 | public function getSurveyType(): int |
||
447 | { |
||
448 | return $this->surveyType; |
||
449 | } |
||
450 | |||
451 | public function setSurveyType(int $surveyType): self |
||
452 | { |
||
453 | $this->surveyType = $surveyType; |
||
454 | |||
455 | return $this; |
||
456 | } |
||
457 | |||
458 | public function getShowFormProfile(): int |
||
459 | { |
||
460 | return $this->showFormProfile; |
||
461 | } |
||
462 | |||
463 | public function setShowFormProfile(int $showFormProfile): self |
||
464 | { |
||
465 | $this->showFormProfile = $showFormProfile; |
||
466 | |||
467 | return $this; |
||
468 | } |
||
469 | |||
470 | public function getFormFields(): string |
||
471 | { |
||
472 | return $this->formFields; |
||
473 | } |
||
474 | |||
475 | public function setFormFields(string $formFields): self |
||
476 | { |
||
477 | $this->formFields = $formFields; |
||
478 | |||
479 | return $this; |
||
480 | } |
||
481 | |||
482 | public function getVisibleResults(): ?int |
||
483 | { |
||
484 | return $this->visibleResults; |
||
485 | } |
||
486 | |||
487 | public function setVisibleResults(int $visibleResults): self |
||
488 | { |
||
489 | $this->visibleResults = $visibleResults; |
||
490 | |||
491 | return $this; |
||
492 | } |
||
493 | |||
494 | public function isMandatory(): bool |
||
495 | { |
||
496 | return $this->isMandatory; |
||
497 | } |
||
498 | |||
499 | public function setIsMandatory(bool $isMandatory): self |
||
500 | { |
||
501 | $this->isMandatory = $isMandatory; |
||
502 | |||
503 | return $this; |
||
504 | } |
||
505 | |||
506 | /** |
||
507 | * @return Collection<int, CSurveyQuestion> |
||
508 | */ |
||
509 | public function getQuestions(): Collection |
||
510 | { |
||
511 | return $this->questions; |
||
512 | } |
||
513 | |||
514 | public function setQuestions(Collection $questions): self |
||
515 | { |
||
516 | $this->questions = $questions; |
||
517 | |||
518 | return $this; |
||
519 | } |
||
520 | |||
521 | public function getSurveyParent(): ?self |
||
522 | { |
||
523 | return $this->surveyParent; |
||
524 | } |
||
525 | |||
526 | public function setSurveyParent(?self $surveyParent): self |
||
527 | { |
||
528 | $this->surveyParent = $surveyParent; |
||
529 | |||
530 | return $this; |
||
531 | } |
||
532 | |||
533 | public function getLft(): ?int |
||
534 | { |
||
535 | return $this->lft; |
||
536 | } |
||
537 | |||
538 | public function setLft(?int $lft): self |
||
539 | { |
||
540 | $this->lft = $lft; |
||
541 | |||
542 | return $this; |
||
543 | } |
||
544 | |||
545 | public function getRgt(): ?int |
||
546 | { |
||
547 | return $this->rgt; |
||
548 | } |
||
549 | |||
550 | public function setRgt(?int $rgt): self |
||
551 | { |
||
552 | $this->rgt = $rgt; |
||
553 | |||
554 | return $this; |
||
555 | } |
||
556 | |||
557 | public function getLvl(): ?int |
||
558 | { |
||
559 | return $this->lvl; |
||
560 | } |
||
561 | |||
562 | public function setLvl(?int $lvl): self |
||
563 | { |
||
564 | $this->lvl = $lvl; |
||
565 | |||
566 | return $this; |
||
567 | } |
||
568 | |||
569 | /** |
||
570 | * @return Collection<int, CSurvey> |
||
571 | */ |
||
572 | public function getChildren(): Collection |
||
573 | { |
||
574 | return $this->children; |
||
575 | } |
||
576 | |||
577 | /** |
||
578 | * @param Collection<int, CSurvey> $children |
||
579 | */ |
||
580 | public function setChildren(Collection $children): self |
||
581 | { |
||
582 | $this->children = $children; |
||
583 | |||
584 | return $this; |
||
585 | } |
||
586 | |||
587 | /** |
||
588 | * @return Collection<int, CSurveyQuestionOption> |
||
589 | */ |
||
590 | public function getOptions(): Collection |
||
591 | { |
||
592 | return $this->options; |
||
593 | } |
||
594 | |||
595 | public function setOptions(Collection $options): self |
||
596 | { |
||
597 | $this->options = $options; |
||
598 | |||
599 | return $this; |
||
600 | } |
||
601 | |||
602 | /** |
||
603 | * @return Collection<int, CSurveyInvitation> |
||
604 | */ |
||
605 | public function getInvitations(): Collection |
||
606 | { |
||
607 | return $this->invitations; |
||
608 | } |
||
609 | |||
610 | public function setInvitations(Collection $invitations): self |
||
611 | { |
||
612 | $this->invitations = $invitations; |
||
613 | |||
614 | return $this; |
||
615 | } |
||
616 | |||
617 | public function getResourceIdentifier(): int|Uuid |
||
618 | { |
||
619 | return (int) $this->getIid(); |
||
620 | } |
||
621 | |||
622 | public function getIid(): ?int |
||
623 | { |
||
624 | return $this->iid; |
||
625 | } |
||
626 | |||
627 | public function getResourceName(): string |
||
628 | { |
||
629 | return (string) $this->getCode(); |
||
630 | } |
||
631 | |||
632 | public function setResourceName(string $name): self |
||
633 | { |
||
634 | return $this->setCode($name); |
||
635 | } |
||
636 | |||
637 | public function isDisplayQuestionNumber(): bool |
||
638 | { |
||
639 | return $this->displayQuestionNumber; |
||
640 | } |
||
641 | |||
642 | public function setDisplayQuestionNumber(bool $displayQuestionNumber): static |
||
647 | } |
||
648 | } |
||
649 |