请问 phpstorm 如何给通过__call方式实现的方法函数增加方法调用提示功能?

比如我的mysql数据库操作类中有这样一些方法是通过 __call 方法实现的,代码如下:

    /**
     * 一些特殊操作的方法
     * @param string $method
     * @param array $arguments
     * @return mixed|string
     */
    final public function __call($method, $arguments) {
        switch ($method) {
            case 'count':
            case 'sum':
            case 'min':
            case 'max':
            case 'avg':
                /**
                 * 示例
                 * 1. $db->max('notice', 'add_time', ['type' => 1]); 获取 notice 表当 type 值为 1 的时候的 add_time 值最大的值
                 * 2. $db->sum('finance', 'num'); 获取 finance 表 num 字段值的和
                 */ $result = $this->getOne($arguments[0], sprintf('%s(`%s`)', strtoupper($method), $arguments[1]), isset($arguments[2]) ? $arguments[2] : '', '', '', MYSQLI_NUM);
                return $result[0];
            case 'table':
                break;
        }
    }

我改如何实现我在调用类似 max 方法的时候,phpstorm 也能给出方法调用提示呢?

阅读 3.2k
1 个回答

定义之前加一下注释:

/**
 * @method int count(string $table, string $field, array $conditions = [])
 * @method int sum(string $table, string $field, array $conditions = [])
 * @method int min(string $table, string $field, array $conditions = [])
 * @method int max(string $table, string $field, array $conditions = [])
 * @method float avg(string $table, string $field, array $conditions = [])
 */
class YourDatabaseClass
{
    // ...
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题