Feat: Refactor profile data validation
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
#[\Attribute]
|
||||
class Address extends Constraint
|
||||
{
|
||||
public string $message = 'Die Anschrift ist unvollständig';
|
||||
|
||||
public function __construct(string $message = null, array $groups = null, $payload = null)
|
||||
{
|
||||
parent::__construct([], $groups, $payload);
|
||||
|
||||
$this->message = $message ?? $this->message;
|
||||
}
|
||||
|
||||
public function getTargets(): string
|
||||
{
|
||||
return Constraint::CLASS_CONSTRAINT;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Validator\Constraints;
|
||||
|
||||
use App\Entity\Embeddable\Address as AddressEntity;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
|
||||
class AddressValidator extends ConstraintValidator
|
||||
{
|
||||
public function validate(mixed $value, Constraint $constraint): void
|
||||
{
|
||||
if (!$value instanceof AddressEntity) {
|
||||
throw new UnexpectedTypeException($value, AddressEntity::class);
|
||||
}
|
||||
|
||||
if (!$constraint instanceof Address) {
|
||||
throw new UnexpectedTypeException($constraint, Address::class);
|
||||
}
|
||||
|
||||
$isIncomplete = null === $value->getStreet()
|
||||
|| null === $value->getCity()
|
||||
|| null === $value->getPostCode()
|
||||
|| null === $value->getCountry()
|
||||
;
|
||||
|
||||
if ($isIncomplete) {
|
||||
$this->context
|
||||
->buildViolation($constraint->message)
|
||||
->addViolation()
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
#[\Attribute]
|
||||
class BankAccount extends Constraint
|
||||
{
|
||||
public string $message = 'Die Bankverbindung ist unvollständig';
|
||||
|
||||
public function __construct(string $message = null, array $groups = null, $payload = null)
|
||||
{
|
||||
parent::__construct([], $groups, $payload);
|
||||
|
||||
$this->message = $message ?? $this->message;
|
||||
}
|
||||
|
||||
public function getTargets(): string
|
||||
{
|
||||
return Constraint::CLASS_CONSTRAINT;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Validator\Constraints;
|
||||
|
||||
use App\Entity\Embeddable\BankAccount as BankAccountEntity;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
|
||||
class BankAccountValidator extends ConstraintValidator
|
||||
{
|
||||
public function validate(mixed $value, Constraint $constraint): void
|
||||
{
|
||||
if (!$value instanceof BankAccountEntity) {
|
||||
throw new UnexpectedTypeException($value, BankAccountEntity::class);
|
||||
}
|
||||
|
||||
if (!$constraint instanceof BankAccount) {
|
||||
throw new UnexpectedTypeException($constraint, BankAccount::class);
|
||||
}
|
||||
|
||||
$isIncomplete = null === $value->getIban()
|
||||
|| null === $value->getBic()
|
||||
|| null === $value->getBank()
|
||||
|| null === $value->getHolder()
|
||||
;
|
||||
|
||||
if ($isIncomplete) {
|
||||
$this->context
|
||||
->buildViolation($constraint->message)
|
||||
->addViolation()
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
#[\Attribute]
|
||||
class Communication extends Constraint
|
||||
{
|
||||
public string $message = 'Die Kontaktdaten sind unvollständig';
|
||||
|
||||
public function __construct(string $message = null, array $groups = null, $payload = null)
|
||||
{
|
||||
parent::__construct([], $groups, $payload);
|
||||
|
||||
$this->message = $message ?? $this->message;
|
||||
}
|
||||
|
||||
public function getTargets(): string
|
||||
{
|
||||
return Constraint::CLASS_CONSTRAINT;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Validator\Constraints;
|
||||
|
||||
use App\Entity\Embeddable\Communication as CommunicationEntity;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
|
||||
class CommunicationValidator extends ConstraintValidator
|
||||
{
|
||||
public function validate(mixed $value, Constraint $constraint): void
|
||||
{
|
||||
if (!$value instanceof CommunicationEntity) {
|
||||
throw new UnexpectedTypeException($value, CommunicationEntity::class);
|
||||
}
|
||||
|
||||
if (!$constraint instanceof Communication) {
|
||||
throw new UnexpectedTypeException($constraint, Communication::class);
|
||||
}
|
||||
|
||||
$isIncomplete = null === $value->getEmail() || null === $value->getMobile();
|
||||
|
||||
if ($isIncomplete) {
|
||||
$this->context
|
||||
->buildViolation($constraint->message)
|
||||
->addViolation()
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user