There some cases where it turn need. For instance, on Eloquent (from Laravel) we have a feature called "scope", that is a method prefixed by this term that is called by it radical, instead. For instance:
public function scopeFilterByName($name) { ... }
You should call this method like $query->filterByName($name) instead of $query->scopeFilterByName($name).
Currently we could declare it directly on class, like:
/** @method void filterByName($name) */
class MyClass extends Model { ... }
But is hard to IDE, for instance, understand that it is related to scopeFilterByName().
Then my suggestion is make this declaration directly on method that supports that:
/** @method filterByName($name) */
public function scopeFilterByName($name) { ... }
The advantages:
- IDE could detects exactly "who" is the real method, then read all parameters related, description, etc.;
- The @method return typehint is optional, when not declared, copy from real method, if declared, override that;
- The @method parameters is optional, when not declared, copy from real method, if declared, override that;
---
The same case could be applied to properties.
Again, on Eloquent, we have a feature called relations, that is declared as methods, but called as properties.
/** @property User[] $users */
class MyClass extends Model {
...
/** @return HasMany */
public function users() { ... }
}
Currently that is the way that we should declares it, but again, IDE can't understand it to identify that this property is a relation declared by users() method.
Then it should be the solution:
class MyClass extends Model {
* @property User[] $users
*/
public function users() { ... }
The advantages are basically the same that @method.