mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-21 06:05:00 +00:00
```
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:
@@ -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' : '[]';
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user