Search code examples
phpphpstormphpdoc

PHPStorm PHPDoc #@+ syntax not working to define multiple vars of same type


i'm working with huge models on PHPStorm. I'm trying to minimize my annotations.

I want to turn this

Class Stack 
{
    /** @var string */
    public $foo;
    /** @var string */
    public $bar;
    /** @var int    */
    public $foobar;
}

into this:

Class Stack 
{
    /** @var string */ //for both vars
    public $foo;
    public $bar;
    /** @var int    */
    public $foobar;
}

I found the #@+ syntax to define multiple vars but seems that is not working. Maybe there is a workaround?

Thank you very much.

By the way, can i tell phpstorm that $this->MyModel is a MyModel type? Something like:

/** @var $this->MyModel MyModel **/
$this->MyModel

Because CodeIgniter puts all of your models inside a param of the controller.


Solution

  • I'm afraid that I've not seen any IDE that knows how to recognize the docblock template syntax of /*#@+/.

    As for $this->MyModel, you could try using the @property tag on that class where you are using $this->MyModel.

    Although some IDEs can reportedly recognize that @var syntax to set a datatype on a local variable:

    /** @var \MyModel $model */
    $model = $this->MyModel;
    

    I don't think it would work with a class property like that.