php style fixer

This commit is contained in:
Julie Lenaerts 2024-02-12 14:37:54 +01:00
parent 1b96deb4ee
commit addc623add
6 changed files with 35 additions and 22 deletions

View File

@ -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');

View File

@ -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)
{
}

View File

@ -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']);
}

View File

@ -1,20 +1,32 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Templating\Entity;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\UserJob;
use Chill\MainBundle\Templating\Entity\UserRender;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Clock\MockClock;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
/**
* @internal
*
* @coversNothing
*/
class UserRenderTest extends WebTestCase
{
use ProphecyTrait;
@ -96,5 +108,4 @@ class UserRenderTest extends WebTestCase
$expectedStringC = 'BOB ISLA (directrice) (service B)';
$this->assertEquals($expectedStringC, $renderer->renderString($user, $optionsNoDate));
}
}

View File

@ -394,6 +394,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
/**
* @return ReadableCollection<int, User>
*
* @Serializer\Groups({"accompanying_period_work:edit"})
*/
public function getReferrers(): ReadableCollection

View File

@ -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);
}
}