From 98f47ac512ff33d69e7a1246acfe6677d5f43834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 12 Jun 2024 16:30:02 +0200 Subject: [PATCH] fixes for normalising accompanying periods in docgen context --- .../Normalizer/AccompanyingPeriodDocGenNormalizer.php | 2 +- .../Normalizer/AccompanyingPeriodWorkNormalizer.php | 4 ++-- .../Serializer/Normalizer/SocialActionNormalizer.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizer.php index c20d48984..dece2526f 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodDocGenNormalizer.php @@ -139,7 +139,7 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf 'locationPerson' => $this->normalizer->normalize($period->getPersonLocation(), $format, array_merge($context, ['docgen:expects' => Person::class])), 'location' => $this->normalizer->normalize($period->getLocation(), $format, $addressContext), 'administrativeLocation' => $this->normalizer->normalize($period->getAdministrativeLocation(), $format, $administrativeLocationContext), - 'works' => $this->normalizer->normalize($period->getWorks(), $format, $workContext), + 'works' => $this->normalizer->normalize($period->getWorks()->getValues(), $format, $workContext), 'comments' => $this->normalizer->normalize($period->getComments(), $format, array_merge($context, ['docgen:expects' => AccompanyingPeriod\Comment::class])), 'pinnedComment' => $this->normalizer->normalize($period->getPinnedComment(), $format, array_merge($context, ['docgen:expects' => AccompanyingPeriod\Comment::class])), ]; diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkNormalizer.php index dbaa00728..22742fdc8 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkNormalizer.php @@ -42,7 +42,7 @@ class AccompanyingPeriodWorkNormalizer implements ContextAwareNormalizerInterfac throw new UnexpectedValueException('Object cannot be null or empty when format is json'); } if ('docgen' === $format && !($object instanceof AccompanyingPeriodWork || null === $object)) { - throw new UnexpectedValueException(sprintf('Object must be an instanceof AccompanyingPeriodWork or null when format is docgen, %s given', is_object($object) ? get_class($object) : gettype($object))); + throw new UnexpectedValueException(sprintf('Object must be an instanceof AccompanyingPeriodWork or null when format is docgen, %s given', get_debug_type($object))); } $cleanContext = array_filter($context, fn (string|int $key) => !in_array($key, ['docgen:expects', self::IGNORE_WORK], true), ARRAY_FILTER_USE_KEY); @@ -134,7 +134,7 @@ class AccompanyingPeriodWorkNormalizer implements ContextAwareNormalizerInterfac { return match ($format) { 'json' => $data instanceof AccompanyingPeriodWork && ($context[self::IGNORE_WORK] ?? null) !== spl_object_hash($data), - 'docgen' => ($data instanceof AccompanyingPeriodWork || ($context['docgen:expects'] ?? null) === AccompanyingPeriodWork::class) + 'docgen' => ($data instanceof AccompanyingPeriodWork || (null === $data && ($context['docgen:expects'] ?? null) === AccompanyingPeriodWork::class)) && !array_key_exists(self::IGNORE_WORK, $context), default => false, }; diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialActionNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialActionNormalizer.php index 12c36b286..542876350 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialActionNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/SocialActionNormalizer.php @@ -50,7 +50,7 @@ class SocialActionNormalizer implements NormalizerAwareInterface, NormalizerInte 'type' => 'social_work_social_action', 'text' => $this->render->renderString($socialAction, []), 'title' => $socialAction->getTitle(), - 'parent' => $this->normalizer->normalize($socialAction->getParent(), $format, $context), + 'parent' => $this->normalizer->normalize($socialAction->getParent(), $format, [...$context, 'docgen:expects' => SocialAction::class]), 'issue' => $this->normalizer->normalize($socialAction->getIssue(), $format, $context), ];