fix: normalize non-numeric body dimension values of existing drafts

This commit is contained in:
Björn Fromme
2026-05-28 15:35:34 +02:00
parent 02b1cbfd6c
commit ee8c6a6545
5 changed files with 148 additions and 0 deletions
+55
View File
@@ -360,6 +360,61 @@ class ParticipantDto
return $ageThreshold > $age;
}
/**
* Normalizes body-dimension fields to canonical string values.
*
* Keeps plain integers and digit-only strings, converting them to a
* normalized string representation. Anything else is treated as legacy
* garbage and reset to null so form hydration can continue safely.
*/
public function normalizeBodyDimensions(): void
{
$this->height = $this->normalizeBodyDimensionValue($this->height);
$this->weight = $this->normalizeBodyDimensionValue($this->weight);
$this->shoeSize = $this->normalizeBodyDimensionValue($this->shoeSize);
}
/**
* Restores the DTO from session/serialization data.
*
* @param array<string, mixed> $data
*/
public function __unserialize(array $data): void
{
foreach ($data as $key => $value) {
if (false === property_exists($this, $key)) {
continue;
}
$this->$key = $value;
}
if (false === isset($this->address)) {
$this->address = new Address();
}
// TODO: Remove after all legacy drafts/session snapshots with body-dimension strings have expired.
$this->normalizeBodyDimensions();
}
private function normalizeBodyDimensionValue(mixed $value): ?string
{
if (true === is_int($value)) {
return (string) $value;
}
if (false === is_string($value)) {
return null;
}
$value = trim($value);
if ('' === $value || false === ctype_digit($value)) {
return null;
}
return (string) (int) $value;
}
/**
* Validates that the applicant (index 0) has a complete address.
*