From 490d546e7addfed009f2be090883a469fe115d1b Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 4 Aug 2025 17:16:42 +0200 Subject: [PATCH] ``` refactor: add type hints and improve method signatures - add return type declarations to methods in `ExportGenerationVoter` - add type hints to `EntityToJsonTransformer` methods - include `ExceptionInterface` in `EntityToJsonTransformer` for better error handling ``` --- .../Form/Type/DataTransformer/EntityToJsonTransformer.php | 6 ++++-- .../Security/Authorization/ExportGenerationVoter.php | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php index cf78cd33d..5e7c8280e 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php +++ b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php @@ -18,6 +18,7 @@ use Chill\PersonBundle\Entity\Person; use Chill\ThirdPartyBundle\Entity\ThirdParty; use Symfony\Component\Form\DataTransformerInterface; use Symfony\Component\Form\Exception\TransformationFailedException; +use Symfony\Component\Serializer\Exception\ExceptionInterface; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\SerializerInterface; @@ -26,7 +27,7 @@ class EntityToJsonTransformer implements DataTransformerInterface { public function __construct(private readonly DenormalizerInterface $denormalizer, private readonly SerializerInterface $serializer, private readonly bool $multiple, private readonly string $type) {} - public function reverseTransform($value) + public function reverseTransform(mixed $value): mixed { if ('' === $value) { return $this->multiple ? [] : null; @@ -54,8 +55,9 @@ class EntityToJsonTransformer implements DataTransformerInterface /** * @param User|User[] $value + * @throws ExceptionInterface */ - public function transform($value): string + public function transform(mixed $value): mixed { if (null === $value) { return $this->multiple ? 'null' : '[]'; diff --git a/src/Bundle/ChillMainBundle/Security/Authorization/ExportGenerationVoter.php b/src/Bundle/ChillMainBundle/Security/Authorization/ExportGenerationVoter.php index 008f76b40..9457d35fc 100644 --- a/src/Bundle/ChillMainBundle/Security/Authorization/ExportGenerationVoter.php +++ b/src/Bundle/ChillMainBundle/Security/Authorization/ExportGenerationVoter.php @@ -19,12 +19,12 @@ class ExportGenerationVoter extends Voter { public const VIEW = 'view'; - protected function supports(string $attribute, $subject) + protected function supports(string $attribute, $subject): bool { return self::VIEW === $attribute && $subject instanceof ExportGeneration; } - protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token) + protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool { /* @var ExportGeneration $subject */ return $token->getUser()->getUserIdentifier() === $subject->getCreatedBy()->getUserIdentifier();