feat: refactor callback validators to dedicated class
This commit is contained in:
@@ -5,9 +5,10 @@ namespace App\Form\Model;
|
||||
use App\BusProNet\Model\PersonalData;
|
||||
use App\BusProNet\Model\Pickup;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\Validator\Constraints as AppAssert;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
#[AppAssert\Participant]
|
||||
class ParticipantData
|
||||
{
|
||||
public ?int $index = null;
|
||||
@@ -44,74 +45,6 @@ class ParticipantData
|
||||
public ?Service $transportationServiceFro = null;
|
||||
public ?Pickup $pickup = null;
|
||||
|
||||
#[Assert\Callback]
|
||||
public function assertBodyMeasurementsValid(ExecutionContextInterface $context): void
|
||||
{
|
||||
if (0 === count($this->rentals)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($this->height)) {
|
||||
$context->buildViolation('Bitte angeben wegen Leihmaterial')
|
||||
->atPath('height')
|
||||
->addViolation()
|
||||
;
|
||||
}
|
||||
|
||||
if (empty($this->shoeSize)) {
|
||||
$context->buildViolation('Bitte angeben wegen Leihmaterial')
|
||||
->atPath('shoeSize')
|
||||
->addViolation()
|
||||
;
|
||||
}
|
||||
|
||||
if (empty($this->weight)) {
|
||||
$context->buildViolation('Bitte angeben wegen Leihmaterial')
|
||||
->atPath('weight')
|
||||
->addViolation()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
#[Assert\Callback]
|
||||
public function assertTransportationSelected(ExecutionContextInterface $context): void
|
||||
{
|
||||
if ('S' === $this->status) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (null === $this->transportationServiceTo) {
|
||||
$context->buildViolation('Bitte angeben')
|
||||
->atPath('transportationServiceTo')
|
||||
->addViolation()
|
||||
;
|
||||
}
|
||||
|
||||
if (null === $this->transportationServiceFro) {
|
||||
$context->buildViolation('Bitte angeben')
|
||||
->atPath('transportationServiceFro')
|
||||
->addViolation()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
#[Assert\Callback]
|
||||
public function assertPickupSelected(ExecutionContextInterface $context): void
|
||||
{
|
||||
$transportationServiceTo = $this->transportationServiceTo;
|
||||
|
||||
if (
|
||||
null !== $transportationServiceTo
|
||||
&& 'BUS' === $transportationServiceTo->subType
|
||||
&& null === $this->pickup
|
||||
) {
|
||||
$context->buildViolation('Bitte auswählen')
|
||||
->atPath('pickup')
|
||||
->addViolation()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
public static function fromPersonalData(PersonalData $personalData): static
|
||||
{
|
||||
$instance = new static();
|
||||
@@ -133,4 +66,14 @@ class ParticipantData
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
public function isCanceled(): bool
|
||||
{
|
||||
return 'S' === $this->status;
|
||||
}
|
||||
|
||||
public function isOption(): bool
|
||||
{
|
||||
return 'O' === $this->status;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user