diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/DateNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/DateNormalizer.php index 3050ad268..032fa484d 100644 --- a/src/Bundle/ChillMainBundle/Serializer/Normalizer/DateNormalizer.php +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/DateNormalizer.php @@ -17,6 +17,7 @@ use DateTimeInterface; use IntlDateFormatter; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\Serializer\Exception\UnexpectedValueException; use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use function array_key_exists; @@ -36,15 +37,20 @@ class DateNormalizer implements ContextAwareNormalizerInterface, DenormalizerInt public function denormalize($data, string $type, ?string $format = null, array $context = []) { + if (null === $data) { + return null; + } + switch ($type) { case DateTime::class: return DateTime::createFromFormat(DateTimeInterface::ISO8601, $data['datetime']); case DateTimeInterface::class: case DateTimeImmutable::class: - default: return DateTimeImmutable::createFromFormat(DateTimeInterface::ISO8601, $data['datetime']); } + + throw new UnexpectedValueException(); } public function normalize($date, ?string $format = null, array $context = [])