Question

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.

Was it helpful?

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.

OTHER TIPS

Why you cannot declare it with @property in the PHPDoc block of the class?

/**
 * @property myModel MyModelClass
 */
class Test
{}

$t = new Test();
$t->myModel->[CTRL+Space will return available methods];

Anyway most better to declare property manually in the class. Just make it transparent.

It's really weird to use group comment for objects. I haven't had such practice. But feel free to use similar code:

/**#@+
 * Test
 *
 * @var int
 */
protected $_aa = 1;
protected $_aa2 = 2;
/**#@-*/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top