phpstorm-inheritdoc icon indicating copy to clipboard operation
phpstorm-inheritdoc copied to clipboard

Does not work on properties

Open najdanovicivan opened this issue 6 years ago • 1 comments

It does work well for methods but it won't work on class property

Superclass contains this

    /**
     * Show sidebar on page
     *
     * @var bool
     */
    protected $show_sidebar = FALSE;

And if I add this on subclass

     /**
     * {@inheritDoc}
     */
    protected $show_sidebar = TRUE;

It does not work when folded

najdanovicivan avatar Feb 14 '19 17:02 najdanovicivan

In my experience this is not a feature/the intention of the plugin. I would recommend you to not re-declare properties in sub-classes to change their values.

Instead use some setter (1) or change the property in the constructor (2) when an instance of the child-class is created.

Example 1:

class Base
{
    /**
     * Indicator if sidebar should be shown on the current page
     *
     * @var bool
     */
    protected $sidebar = false;

    /**
     * @param bool $sidebar
     * @return void
     */
    protected function setSidebar(bool $sidebar): void
    {
        $this->sidebar = $sidebar;
    }
}

class Child extends Base
{
    public function __construct()
    {
        $this->setSidebar(true);
    }
}

Example 2:

class Base
{
    /**
     * Indicator if sidebar should be shown on the current page
     *
     * @var bool
     */
    protected $sidebar = false;
}

class Child extends Base
{
    public function __construct()
    {
        $this->sidebar = true;
    }
}

SebTM avatar May 08 '19 13:05 SebTM