PHP_CodeSniffer icon indicating copy to clipboard operation
PHP_CodeSniffer copied to clipboard

Param typehint fails for renamed imports

Open rcrowe opened this issue 11 years ago • 3 comments

The check for the param in the docblock doesn't take into account typehinted paramaters that have been used with a different name.

The example below throws the error Expected type hint "\React\EventLoop\LoopInterface"; found "EventLoopInterface" for $loop


    use React\EventLoop\LoopInterface as EventLoopInterface;

    /**
     * Get a new instance of datagram.
     *
     * @param \React\EventLoop\LoopInterface $loop
     *
     * @return \React\Datagram\Factory
     */
    public function getDatagram(EventLoopInterface $loop)
    {
        if (!$this->datagram) {
            $this->datagram = function (EventLoopInterface $loop) {
                return new Datagram($loop);
            };
        }

        return call_user_func($this->datagram, $loop);
    }

rcrowe avatar Nov 15 '14 08:11 rcrowe

  1. Any specific reason why you're using FQCN in DocBlock while class name is already imported and can be used without namespace prefix?
  2. What is expected result:
    • no warning
    • warning saying to use FQCN
    • warning saying to use non-FQCN ?

aik099 avatar Nov 15 '14 08:11 aik099

I guess it comes down to a more readable docblock for a human. FQCN in docblocks are a pretty common thing, with most packages that I use doing the same.

In an ideal world, no error.

rcrowe avatar Nov 15 '14 09:11 rcrowe

While it's still in draft PSR-5 states object types should use FQCN (unless undetermined): https://github.com/php-fig/fig-standards/blob/master/proposed/phpdoc.md#valid-class-name

FrittenKeeZ avatar Jun 23 '21 12:06 FrittenKeeZ