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 703 forks source link

Incorrect annotation type-hinging #2293

Closed TheHett closed 3 years ago

TheHett commented 3 years ago

Hi. I'm using FOSRest version 3.0.x with new php 8 attributes. I noticed that you extends the Symfony Route annotation, but miss all constructor arguments (except data)

<?php

/*
 * This file is part of the FOSRestBundle package.
 *
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace FOS\RestBundle\Controller\Annotations;

use Symfony\Component\Routing\Annotation\Route as BaseRoute;

/**
 * Route annotation class.
 *
 * @Annotation
 */
class Route extends BaseRoute
{
    public function __construct(array $data)
    {
        parent::__construct($data);

        if (!$this->getMethods()) {
            $this->setMethods((array) $this->getMethod());
        }
    }

    /**
     * @return string|null
     */
    public function getMethod()
    {
        return;
    }
}

But the original consutructor looks like:

    /**
     * @param array|string      $data         data array managed by the Doctrine Annotations library or the path
     * @param array|string|null $path
     * @param string[]          $requirements
     * @param string[]          $methods
     * @param string[]          $schemes
     *
     * @throws \BadMethodCallException
     */
    public function __construct(
        $data = [],
        $path = null,
        string $name = null,
        array $requirements = [],
        array $options = [],
        array $defaults = [],
        string $host = null,
        array $methods = [],
        array $schemes = [],
        string $condition = null,
        int $priority = null,
        string $locale = null,
        string $format = null,
        bool $utf8 = null,
        bool $stateless = null
    ) {
       ....
       ....
    }

Because of what it is impossible to use such a expressions like this:

image

And more one notice in PhpStorm

image

To avoid this notice the annotation class shout be marked by annotation Attribute, like original Symfony Route class:

/**
 * Annotation class for @Route().
 *
 * @Annotation
 * @Target({"CLASS", "METHOD"})
 *
 * @author Fabien Potencier <fabien@symfony.com>
 * @author Alexander M. Turek <me@derrabus.de>
 */
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
class Route

Not only this annotation has some problem.

robmro27 commented 3 years ago

duplicate #2301 - attributes are not supported yet, please change to annotations for now

W0rma commented 3 years ago

Probably related to https://github.com/FriendsOfSymfony/FOSRestBundle/issues/2311

GuilhemN commented 3 years ago

Should be fixed by https://github.com/FriendsOfSymfony/FOSRestBundle/issues/2311