Refactor normalizers: update getSupportedTypes to use match, ensure explicit fallback with '*' => false, and improve type handling.

This commit is contained in:
2026-01-09 16:01:56 +01:00
parent f5e923ca39
commit 8ceb937e0e
4 changed files with 12 additions and 15 deletions

View File

@@ -85,6 +85,6 @@ class CommentEmbeddableDocGenNormalizer implements NormalizerInterface, Normaliz
public function getSupportedTypes(?string $format): array
{
return 'docgen' === $format ? [CommentEmbeddable::class => true] : [];
return 'docgen' === $format ? [CommentEmbeddable::class => true, '*' => false] : [];
}
}

View File

@@ -137,6 +137,7 @@ class DateNormalizer implements NormalizerInterface, DenormalizerInterface
\DateTimeInterface::class => true,
\DateTime::class => true,
\DateTimeImmutable::class => true,
'*' => false,
];
}

View File

@@ -84,12 +84,10 @@ class PhonenumberNormalizer implements NormalizerInterface, DenormalizerInterfac
public function getSupportedTypes(?string $format): array
{
if ('json' === $format || 'docgen' === $format) {
return [
PhoneNumber::class => true,
];
}
return [];
return match ($format) {
'json' => [PhoneNumber::class => true],
'docgen' => [PhoneNumber::class => true, '*' => false],
default => [],
};
}
}

View File

@@ -149,12 +149,10 @@ class UserNormalizer implements NormalizerInterface, NormalizerAwareInterface
public function getSupportedTypes(?string $format): array
{
if ('json' === $format || 'docgen' === $format) {
return [
User::class => true,
];
}
return [];
return match ($format) {
'json' => [User::class => true],
'docgen' => [User::class => true, '*' => false],
default => [],
};
}
}