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

前端 未结 2 878
佛祖请我去吃肉
佛祖请我去吃肉 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:09

    Somewhat related to original question:

    You can also define this in phpstorm meta file. Here's an example for factory method (v2016.3):

    // Define in .phpstorm.meta.php
    namespace PHPSTORM_META {
        $STATIC_METHOD_TYPES = [
            \Factory::create('') => [],
        ];
    }
    
    // Then use in code
    $factory = new \Factory();
    $user = $factory->create(\User::class);
    // Here you get autocomplete.
    $user->subscribe();
    

    This way you don't have to docblock every possibility when magic happens.

    Have some docs for details.

提交回复
热议问题