How to document magic (_call and _callStatic) methods for IDEs

前端 未结 2 881
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 00:57

After many happy years coding in notepad++ and sublime, I\'ve been advised to give a PHP IDE a go. I\'m trying out phpStorm and it seems nice. The code completion and docum

2条回答
  •  误落风尘
    2020-12-01 01:27

    Use class-level PHPDoc comment -- specifically @method tag -- works fine in PhpStorm:

    /**
     * @method static someClass get_by_user_id(int $id) Bla-bla
     * @method static someClass get_first_by_id(int $id) 
     */
    abstract class a {
    ...
    

    In the above:

    • @method -- PHPDoc tag
    • static -- tells that this is static method
    • someClass or $this -- return type
    • get_by_user_id -- method name
    • (int $id) -- method signature: ([[type] [parameter]<, ...>])
    • Bla-bla -- some optional description

    More about @method:

    • https://docs.phpdoc.org/latest/references/phpdoc/tags/method.html
    • https://github.com/phpDocumentor/phpDocumentor2/blob/develop/docs/PSR.md#711-method

    P.S. While @method static works fine in PhpStorm (tells IDE that method is static) it may not be (yet?) supported by actual phpDocumentor tool (sorry, have not used it for a while).


    Alternatively: (in PhpStorm, of course) Settings | Inspections | PHP | Undefined | Undefined method --> Downgrade severity if __magic methods are present in class -- it will not help with code completion for such methods in any way, but will not mark those magic methods as "undefined method" errors.


    phpDocumentor's ticket regarding using RegEx/partial names for @property/@method tags (how it can be useful for documentation and how little help it may bring to the actual IDE when dealing with code completion):

    • https://github.com/phpDocumentor/phpDocumentor2/issues/689

提交回复
热议问题