*/ #[ORM\OneToMany(targetEntity: Answer::class, mappedBy: 'question', cascade: ['persist'], orphanRemoval: true)] private Collection $answers; public function __construct() { $this->answers = new ArrayCollection(); } public function getId(): ?Uuid { return $this->id; } public function getQuestion(): string { return $this->question; } public function setQuestion(string $question): static { $this->question = $question; return $this; } public function getQuiz(): Quiz { return $this->quiz; } public function setQuiz(Quiz $quiz): static { $this->quiz = $quiz; return $this; } public function isEnabled(): ?bool { return $this->enabled; } public function setEnabled(bool $enabled): static { $this->enabled = $enabled; return $this; } /** @return Collection */ public function getAnswers(): Collection { return $this->answers; } public function addAnswer(Answer $answer): static { if (!$this->answers->contains($answer)) { $this->answers->add($answer); $answer->setQuestion($this); } return $this; } public function getErrors(): ?string { if (0 === \count($this->answers)) { return 'This question has no answers'; } $correctAnswers = $this->answers->filter(static fn (Answer $answer): ?bool => $answer->isRightAnswer())->count(); if (0 === $correctAnswers) { return 'This question has no correct answers'; } if ($correctAnswers > 1) { return 'This question has multiple correct answers'; } return null; } }