FriendsOfSymfony / FOSRestBundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony
http://symfony.com/doc/master/bundles/FOSRestBundle/index.html
MIT License
2.79k stars 707 forks source link

Deprecation warning about return type declaration for JMSHandlerRegistryV2 in Symfony 5.4 #2353

Open DevMcC opened 2 years ago

DevMcC commented 2 years ago

I recently upgraded to Symfony 5.4 and now I am receiving a deprecration warning about JMSHandlerRegistryV2:

[2021-12-09T11:52:40.460108+01:00] php.INFO: User Deprecated: Method "JMS\Serializer\Handler\HandlerRegistryInterface::getHandler()" might add "callable|object" as a native return type declaration in the future. Do the same in implementation "FOS\RestBundle\Serializer\JMSHandlerRegistryV2" now to avoid errors or add an explicit @return annotation to suppress this message. {"exception":"[object] (ErrorException(code: 0): User Deprecated: Method \"JMS\\Serializer\\Handler\\HandlerRegistryInterface::getHandler()\" might add \"callable|object\" as a native return type declaration in the future. Do the same in implementation \"FOS\\RestBundle\\Serializer\\JMSHandlerRegistryV2\" now to avoid errors or add an explicit @return annotation to suppress this message. at /app/vendor/symfony/error-handler/DebugClassLoader.php:325)"} []

I can't seem to fix this deprecration in my project, so I think it can only be fixed in here instead. If wanted, I can create a PR to fix this.

I fixed the deprecation in the vendor folder by adding @return to the getHandler method:

    /**
     * {@inheritdoc}
+     *
+     * @return callable|object
     */
    public function getHandler(int $direction, string $typeName, string $format)

Reproduction path:

ko4a commented 2 years ago

Hi are there any updates ? :)

pburggraf commented 2 years ago

Suppressing the deprecation messages here in this project is probably the wrong way as the "problem" is based on the external interface "HandlerRegistryInterface".

These message should be considered as a hint for the developer to use native return types instead of just rely on doctypes. For reference and better explaination see the following links: https://github.com/symfony/symfony/issues/44802#issuecomment-1001776200 https://github.com/sebastianbergmann/php-file-iterator/pull/74