chore: fix phpstan errors

This commit is contained in:
Björn Fromme
2026-04-16 16:27:35 +02:00
parent 4e925171b3
commit 0fcecc9c58
109 changed files with 510 additions and 429 deletions
@@ -16,12 +16,12 @@ use Symfony\Component\Form\Exception\TransformationFailedException;
* the full object (including price) via choiceData while the form binds
* the scalar ID to the participant's assignedRoomId property.
*
* @implements DataTransformerInterface<int|null, RoomSelectionDto|null>
* @implements DataTransformerInterface<mixed, mixed>
*/
class RoomSelectionToIdTransformer implements DataTransformerInterface
{
/**
* @param RoomSelectionDto[] $roomSelections Available room selections for reverse lookup
* @param array<RoomSelectionDto> $roomSelections Available room selections for reverse lookup
*/
public function __construct(
private readonly array $roomSelections,
@@ -29,11 +29,8 @@ class RoomSelectionToIdTransformer implements DataTransformerInterface
}
/**
* Transforms an integer room ID to a RoomSelectionDto for form display.
*
* @param int|null $value The room ID from the model
*
* @return RoomSelectionDto|null The matching RoomSelectionDto or null
* Converts the persisted room id from the model into the matching
* RoomSelectionDto so the form can render labels and pricing details.
*/
public function transform(mixed $value): ?RoomSelectionDto
{
@@ -51,29 +48,28 @@ class RoomSelectionToIdTransformer implements DataTransformerInterface
}
/**
* Transforms a RoomSelectionDto back to an integer room ID for the model.
* Converts the submitted choice value back into the model's integer room id.
*
* @param RoomSelectionDto|null $value The selected RoomSelectionDto from the form
*
* @return int|null The room ID or null
*
* @throws TransformationFailedException If an unexpected value type is received
* ChoiceType submits the selected room id as a scalar, so this method accepts
* an empty value, an int, or a digit-only string and rejects everything else.
*/
public function reverseTransform(mixed $value): ?int
{
if (null === $value) {
if (null === $value || '' === $value) {
return null;
}
if ($value instanceof RoomSelectionDto) {
return $value->id;
if (is_int($value)) {
return $value;
}
// Handle case where form submits scalar ID directly
if (is_int($value) || is_string($value)) {
if (is_string($value) && ctype_digit($value)) {
return (int) $value;
}
throw new TransformationFailedException(sprintf('Expected RoomSelectionDto, int, or null, got %s', get_debug_type($value)));
throw new TransformationFailedException(sprintf(
'Invalid room id value: %s',
get_debug_type($value)
));
}
}