label = $label; $this->type = $type; } /** * Last line of defence: forms validate first, but no path may store a malformed number. * Labels are immutable, so checking them once is enough. */ #[ORM\PrePersist] public function assertValid(): void { if (!$this->type->isValid($this->label)) { throw new \DomainException(\sprintf('"%s" is not a valid %s label.', $this->label, $this->type->value)); } } public function getId(): ?int { return $this->id; } public function getType(): LabelType { return $this->type; } public function getLabel(): string { return $this->label; } }