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
```
This commit is contained in:
2025-08-04 17:16:42 +02:00
parent 7a4416109e
commit 490d546e7a
2 changed files with 6 additions and 4 deletions

View File

@@ -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' : '[]';

View File

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