Closed
Description
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;
}
}