From 8ceb937e0ee5982260e517d6b207a07c8c089e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 9 Jan 2026 16:01:56 +0100 Subject: [PATCH] Refactor normalizers: update `getSupportedTypes` to use `match`, ensure explicit fallback with `'*' => false`, and improve type handling. --- .../Normalizer/CommentEmbeddableDocGenNormalizer.php | 2 +- .../Serializer/Normalizer/DateNormalizer.php | 1 + .../Serializer/Normalizer/PhonenumberNormalizer.php | 12 +++++------- .../Serializer/Normalizer/UserNormalizer.php | 12 +++++------- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/CommentEmbeddableDocGenNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/CommentEmbeddableDocGenNormalizer.php index b1984b0a1..5f91ee2df 100644 --- a/src/Bundle/ChillMainBundle/Serializer/Normalizer/CommentEmbeddableDocGenNormalizer.php +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/CommentEmbeddableDocGenNormalizer.php @@ -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] : []; } } diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/DateNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/DateNormalizer.php index c0f5d99ca..29e229d07 100644 --- a/src/Bundle/ChillMainBundle/Serializer/Normalizer/DateNormalizer.php +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/DateNormalizer.php @@ -137,6 +137,7 @@ class DateNormalizer implements NormalizerInterface, DenormalizerInterface \DateTimeInterface::class => true, \DateTime::class => true, \DateTimeImmutable::class => true, + '*' => false, ]; } diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/PhonenumberNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/PhonenumberNormalizer.php index 571e8ec11..3c08e84d4 100644 --- a/src/Bundle/ChillMainBundle/Serializer/Normalizer/PhonenumberNormalizer.php +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/PhonenumberNormalizer.php @@ -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 => [], + }; } } diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/UserNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/UserNormalizer.php index 74ea9edd3..ab5f8356e 100644 --- a/src/Bundle/ChillMainBundle/Serializer/Normalizer/UserNormalizer.php +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/UserNormalizer.php @@ -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 => [], + }; } }