Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make:serializer:encoder generates invalid (untyped) class #1050

Closed
Radiergummi opened this issue Jan 19, 2022 · 0 comments · Fixed by #1525
Closed

make:serializer:encoder generates invalid (untyped) class #1050

Radiergummi opened this issue Jan 19, 2022 · 0 comments · Fixed by #1525
Labels

Comments

@Radiergummi
Copy link

In Symfony 6.0, using the symfony console make:serializer:encoder command results in method stubs without parameter type hints, which conflicts with the typed interface. Thus, this will cause the application to crash due to an incompatible implementation:

Compile Error: Declaration of App\Serializer\FooEncoder::encode($data, $format, array $context = []) must be compatible with Symfony\Component\Serializer\Encoder\EncoderInterface::encode(mixed $data, string $format, array $context = []): string

This should be solvable by updating the template as follows:

<?= "<?php\n" ?>

namespace <?= $namespace; ?>;

use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Symfony\Component\Serializer\Encoder\EncoderInterface;

class <?= $class_name ?> implements EncoderInterface, DecoderInterface
{
    public const FORMAT = '<?= $format ?>';

-   public function encode($data, $format, array $context = [])
+   public function encode(mixed $data, string $format, array $context = []): string
    {
        // TODO: return your encoded data
        return '';
    }

-   public function supportsEncoding($format): bool
+   public function supportsEncoding(string $format): bool
    {
        return self::FORMAT === $format;
    }

-   public function decode($data, $format, array $context = [])
+   public function decode(string $data, string $format, array $context = [])
    {
        // TODO: return your decoded data
        return '';
    }

-   public function supportsDecoding($format): bool
+   public function supportsDecoding(string $format): bool
    {
        return self::FORMAT === $format;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants