feat: pre-flight check of agency bookings
addresses #869bqxr4q
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use function Symfony\Component\String\u;
|
||||
|
||||
/**
|
||||
* Represents a physical address with street, postal code, city, and country information.
|
||||
@@ -29,6 +30,21 @@ class Address
|
||||
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['personal_data'])]
|
||||
public ?string $country = null;
|
||||
|
||||
/**
|
||||
* Normalizes legacy string data loaded from API/session sources.
|
||||
*
|
||||
* Trims whitespace and converts empty strings to null so load-time audits
|
||||
* and form hydration see canonical values.
|
||||
*/
|
||||
public function normalize(): void
|
||||
{
|
||||
$this->street = $this->normalizeNullableString($this->street);
|
||||
$this->postCode = $this->normalizeNullableString($this->postCode);
|
||||
$this->city = $this->normalizeNullableString($this->city);
|
||||
$this->district = $this->normalizeNullableString($this->district);
|
||||
$this->country = $this->normalizeNullableString($this->country);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the address to API payload format.
|
||||
*
|
||||
@@ -47,4 +63,15 @@ class Address
|
||||
'land' => $this->country,
|
||||
];
|
||||
}
|
||||
|
||||
private function normalizeNullableString(?string $value): ?string
|
||||
{
|
||||
if (null === $value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$trimmed = u($value)->trim()->toString();
|
||||
|
||||
return '' === $trimmed ? null : $trimmed;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user