laminas-code icon indicating copy to clipboard operation
laminas-code copied to clipboard

Use 'static' return type in docblock

Open weierophinney opened this issue 6 years ago • 3 comments

For example:

    /**
     * @param  string $name
     * @return static
     */
    public function setName($name)
    {
        $this->name = (string) $name;
        return $this;
    }

Instead @return AbstractMemberGenerator


Originally posted by @ViktorPegy at https://github.com/zendframework/zend-code/issues/148

weierophinney avatar Dec 31 '19 21:12 weierophinney

I think in that case we should use $this, there is slightly difference between static and $this and I think it is good explained in PSR-5 draft (the bottom of the page): https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md

$this, the element to which this type applies is the same exact instance as the current class in the given context. As such this type is a stricter version of static as, in addition, the returned instance must not only be of the same class but also the same instance.


Originally posted by @michalbundyra at https://github.com/zendframework/zend-code/issues/148#issuecomment-350986774

weierophinney avatar Dec 31 '19 21:12 weierophinney

I agree


Originally posted by @ViktorPegy at https://github.com/zendframework/zend-code/issues/148#issuecomment-350989644

weierophinney avatar Dec 31 '19 21:12 weierophinney

The code is now uses @return AbstractMemberGenerator

https://github.com/laminas/laminas-code/blob/40919916c4ca6ad815874539cf528814429f0269/src/Generator/AbstractMemberGenerator.php#L200

samsonasik avatar Aug 05 '20 01:08 samsonasik