From f47fb17b8d4bd07f2fba604d6ef3e9407f14103e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 31 Mar 2022 12:46:13 +0200 Subject: [PATCH] fix denormalization of invalid dates --- .../Serializer/Normalizer/DateNormalizer.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/DateNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/DateNormalizer.php index 70958d5a9..81e953267 100644 --- a/src/Bundle/ChillMainBundle/Serializer/Normalizer/DateNormalizer.php +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/DateNormalizer.php @@ -44,13 +44,21 @@ class DateNormalizer implements ContextAwareNormalizerInterface, DenormalizerInt switch ($type) { case DateTime::class: - return DateTime::createFromFormat(DateTimeInterface::ISO8601, $data['datetime']); + $result = DateTime::createFromFormat(DateTimeInterface::ISO8601, $data['datetime']); + break; case DateTimeInterface::class: case DateTimeImmutable::class: - return DateTimeImmutable::createFromFormat(DateTimeInterface::ISO8601, $data['datetime']); + $result = DateTimeImmutable::createFromFormat(DateTimeInterface::ISO8601, $data['datetime']); + break; } + if (false === $result) { + return null; + } + + return $result; + throw new UnexpectedValueException(); }