From addc623add07f2757757ad8c30bc0be1f08710b3 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 12 Feb 2024 14:37:54 +0100 Subject: [PATCH] php style fixer --- src/Bundle/ChillMainBundle/Entity/User.php | 4 ++-- .../Serializer/Normalizer/UserNormalizer.php | 2 +- .../Templating/Entity/UserRender.php | 21 +++++++++---------- .../Templating/Entity/UserRenderTest.php | 17 ++++++++++++--- .../AccompanyingPeriodWork.php | 1 + .../AccompanyingPeriodWorkNormalizer.php | 12 ++++++----- 6 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Entity/User.php b/src/Bundle/ChillMainBundle/Entity/User.php index 2d155b54a..b94d90760 100644 --- a/src/Bundle/ChillMainBundle/Entity/User.php +++ b/src/Bundle/ChillMainBundle/Entity/User.php @@ -274,7 +274,7 @@ class User implements UserInterface, \Stringable return $this->mainLocation; } - public function getMainScope(\DateTimeImmutable $atDate = null): ?Scope + public function getMainScope(?\DateTimeImmutable $atDate = null): ?Scope { $atDate ??= new \DateTimeImmutable('now'); @@ -326,7 +326,7 @@ class User implements UserInterface, \Stringable return $this->salt; } - public function getUserJob(\DateTimeImmutable $atDate = null): ?UserJob + public function getUserJob(?\DateTimeImmutable $atDate = null): ?UserJob { $atDate ??= new \DateTimeImmutable('now'); diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/UserNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/UserNormalizer.php index ea8c8a0f4..99e76c5ff 100644 --- a/src/Bundle/ChillMainBundle/Serializer/Normalizer/UserNormalizer.php +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/UserNormalizer.php @@ -41,7 +41,7 @@ class UserNormalizer implements ContextAwareNormalizerInterface, NormalizerAware 'isAbsent' => false, ]; - public function __construct(private readonly UserRender $userRender) + public function __construct(private readonly UserRender $userRender, private readonly ClockInterface $clock) { } diff --git a/src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php b/src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php index 77b4255cc..de9f4abbe 100644 --- a/src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php +++ b/src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php @@ -35,14 +35,15 @@ class UserRender implements ChillEntityRenderInterface public function __construct( private readonly TranslatableStringHelper $translatableStringHelper, - private readonly \Twig\Environment $engine, private readonly TranslatorInterface $translator, + private readonly \Twig\Environment $engine, + private readonly TranslatorInterface $translator, private readonly ClockInterface $clock, - ) {} + ) { + } /** - * @param $entity - * @param array{main_scope?: bool, user_job?: bool, absence?: bool, at_date?: null|DateTimeImmutable|DateTime} $options - * @return string + * @param array{main_scope?: bool, user_job?: bool, absence?: bool, at_date?: DateTimeImmutable|\DateTime|null} $options + * * @throws LoaderError * @throws RuntimeError * @throws SyntaxError @@ -53,7 +54,7 @@ class UserRender implements ChillEntityRenderInterface if (null === $opts['at_date']) { $opts['at_date'] = $this->clock->now(); - } elseif ($opts['at_date'] instanceof DateTime) { + } elseif ($opts['at_date'] instanceof \DateTime) { $opts['at_date'] = DateTimeImmutable::createFromMutable($opts['at_date']); } @@ -64,19 +65,17 @@ class UserRender implements ChillEntityRenderInterface } /** - * @param $entity - * @param array{main_scope?: bool, user_job?: bool, absence?: bool, at_date?: null|DateTimeImmutable|DateTimeMutable} $options - * @return string + * @param array{main_scope?: bool, user_job?: bool, absence?: bool, at_date?: DateTimeImmutable|DateTimeMutable|null} $options */ public function renderString($entity, array $options): string { $opts = \array_merge(self::DEFAULT_OPTIONS, $options); -// $immutableAtDate = $opts['at_date'] instanceOf DateTime ? DateTimeImmutable::createFromMutable($opts['at_date']) : $opts['at_date']; + // $immutableAtDate = $opts['at_date'] instanceOf DateTime ? DateTimeImmutable::createFromMutable($opts['at_date']) : $opts['at_date']; if (null === $opts['at_date']) { $opts['at_date'] = $this->clock->now(); - } elseif ($opts['at_date'] instanceof DateTime) { + } elseif ($opts['at_date'] instanceof \DateTime) { $opts['at_date'] = DateTimeImmutable::createFromMutable($opts['at_date']); } diff --git a/src/Bundle/ChillMainBundle/Tests/Templating/Entity/UserRenderTest.php b/src/Bundle/ChillMainBundle/Tests/Templating/Entity/UserRenderTest.php index 574d272e1..ef08348b4 100644 --- a/src/Bundle/ChillMainBundle/Tests/Templating/Entity/UserRenderTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Templating/Entity/UserRenderTest.php @@ -1,20 +1,32 @@ assertEquals($expectedStringC, $renderer->renderString($user, $optionsNoDate)); } - } diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php index 73bc0729d..53a1434a4 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php @@ -394,6 +394,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues /** * @return ReadableCollection + * * @Serializer\Groups({"accompanying_period_work:edit"}) */ public function getReferrers(): ReadableCollection diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkNormalizer.php index 040576fa6..94c440519 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkNormalizer.php @@ -63,13 +63,15 @@ class AccompanyingPeriodWorkNormalizer implements ContextAwareNormalizerInterfac continue; } - $initial['referrers'][] = $this->normalizer->normalize($referrerHistory->getUser(), - $format, [...$context, UserNormalizer::AT_DATE => $referrerHistory->getStartDate()]); + $initial['referrers'][] = $this->normalizer->normalize( + $referrerHistory->getUser(), + $format, + [...$context, UserNormalizer::AT_DATE => $referrerHistory->getStartDate()] + ); } } - if ($format === 'json') { - + if ('json' === $format) { // then, we add normalization for things which are not into the entity $initial['workflows_availables'] = $this->metadataExtractor->availableWorkflowFor( AccompanyingPeriodWork::class, @@ -98,7 +100,7 @@ class AccompanyingPeriodWorkNormalizer implements ContextAwareNormalizerInterfac public function supportsNormalization($data, ?string $format = null, array $context = []): bool { return ('json' === $format || 'docgen' === $format) - && ($data instanceof AccompanyingPeriodWork || ('docgen' === $format && $data === null && ($context['docgen:expects'] ?? null) === AccompanyingPeriodWork::class)) + && ($data instanceof AccompanyingPeriodWork || ('docgen' === $format && null === $data && ($context['docgen:expects'] ?? null) === AccompanyingPeriodWork::class)) && !\array_key_exists(self::IGNORE_WORK, $context); } }