Feat: Refactor profile data validation

This commit is contained in:
Björn Fromme committed 2023-09-20 10:06:39 +02:00
1 parent 7f7a35e7a2
commit 2dd8a6de19
10 files changed
+76 -179

No files matched your search

+21 -2
View File
@@ -2,13 +2,12 @@
namespace App\Entity\Embeddable;
use App\Validator\Constraints as AppAssert;
use App\BusProNet\Model\ProfileResponse;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
#[ORM\Embeddable]
#[AppAssert\Communication(message: 'Bitte vervollständige deine Kontaktdaten', groups: ['profile_preflight'])]
class Communication
{
#[ORM\Column(type: 'string', nullable: true)]
@@ -23,6 +22,26 @@ class Communication
#[Assert\NotBlank(message: 'Bitte gib deine E-Mail-Adresse an', groups: ['profile'])]
protected ?string $email = null;
#[Assert\Callback(groups: ['profile_preflight'])]
public function preflightCheck(ExecutionContextInterface $executionContext): void
{
$missing = [];
if (empty($this->getEmail())) {
$missing[] = 'E-Mail';
}
if (empty($this->getMobile())) {
$missing[] = 'Mobilnummer';
}
if (0 < count($missing)) {
$executionContext
->buildViolation(sprintf('Bitte vervollständige deine Kontaktdaten (%s)', implode(', ', $missing)))
->addViolation()
;
}
}
public function toPayload(): array
{
return [