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

+28 -2
View File
@@ -2,12 +2,11 @@
namespace App\Entity\Embeddable;
use App\Validator\Constraints as AppAssert;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
#[ORM\Embeddable]
#[AppAssert\BankAccount(message: 'Bitte vervollständige deine Bankverbindung', groups: ['profile_preflight'])]
class BankAccount
{
#[ORM\Column(nullable: true)]
@@ -27,6 +26,33 @@ class BankAccount
#[Assert\NotBlank(message: 'Bitte gib den Kontoinhaber an', groups: ['profile'])]
private ?string $holder = null;
#[Assert\Callback(groups: ['profile_preflight'])]
public function preflightCheck(ExecutionContextInterface $executionContext): void
{
$missing = [];
if (empty($this->getIban())) {
$missing[] = 'IBAN';
}
if (empty($this->getBic())) {
$missing[] = 'BIC';
}
if (empty($this->getBank())) {
$missing[] = 'Name der Bank';
}
if (empty($this->getHolder())) {
$missing[] = 'Kontoinhaber';
}
if (0 < count($missing)) {
$executionContext
->buildViolation(sprintf('Bitte vervollständige deine Bankverbindung (%s)', implode(', ', $missing)))
->addViolation()
;
}
}
public function getIban(bool $obfuscated = false): ?string
{
if (false === $obfuscated) {