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:*


   1. IDE could detects exactly "who" is the real method, then read all 
   parameters related, description, etc.;
   2. The @method return typehint is optional, when not declared, copy from 
   real method, if declared, override that;
   3. 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

     * @return HasMany 

          */

    public function users() { ... }
}


The advantages are basically the same that @method.


-- 
You received this message because you are subscribed to the Google Groups "PHP 
Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/php-fig/12d3737d-1a04-4215-be8d-2befb6a832d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
  • PSR-5: declar... David Rodrigues

Reply via email to