PHPDOC @property associated with the receiver

I use YII and freely install @property phpdoc expressions to all my models.

In my IDE (phpstorm), I can use the Control + Click methods and fields to implement them, but when I do this for magic methods, it leads me to the top of the class definition, which is wrong.

How can I configure it so that it links me to the corresponding getter method?

+4
source share
1 answer

What do I understand that

Method Tags

@property and @method are allowed only in the docblock class level. Both of these tags give a hint to the developer about the availability of methods / properties implemented using the megalogical methods __call($method,$params) , __get($var) and __set($var,$val) .

In yii, you do not need to explicitly define getter / setter methods for class attributes. Thus, attributes are access through 'get'.$attributeName eg

  /** * Class User * * @method string getFirstName() * @method void setFirstName(string $firstName) * */ class User extends CModel{ var $firstName; } $u= new User(); $username=$u->getFirstName(); $u->setFirstName('Testuser'); 

In the Yii context, the above code is the true bcz of the magic method 'get'.$attributeName AttributeName for call attributes.

Since @property and @method are levels of the @tags class, your only bet is to add them to the class, and Ctrl + click will send focus to the corresponding docblock class

+1
source

Source: https://habr.com/ru/post/1496172/


All Articles