PhpStorm自动完成类方法

时间:2017-07-05 13:56:39

标签: php phpstorm

我有一个抽象类,它获取一个带有魔术方法的容器来获取容器DI,在PHPDoc文档块中我将用类描述容器的变量,我希望PhpStorm voce涵盖了自动完成功能。

<?php
namespace App\Model;

use Slim\Container;

abstract class Model
{
    protected $container;

    /**
     * @var \Slim\Container $container
     * @var \PDO $conn1
     * @var \PDO $conn2
     * @var \App\Model\Contribuinte $contribuinte
     * @var \App\Model\Debito $debito
     * @var \App\Model\Endereco $endereco
     * @var \App\Model\Imagem $imagem
     * @var \App\Model\Sistema $sistema
     * @var \App\Model\Inspecao $inspecao
     */


    public function __construct(Container $container)
    {
        $this->container = $container;
    }

    public function __get($key)
    {
        if ($this->container->has($key)) {
            return $this->container->{$key};
        }
        return null;
    }
}

例如

<?php
namespace App\Model;

class Contribuinte extends Model
{
    public function list()
    {
        $this->conn1->prep ....
    }
}

1 个答案:

答案 0 :(得分:2)

在PHPDoc块中使用@property作为类:https://phpdoc.org/docs/latest/references/phpdoc/tags/property.html

/**
 * My class description
 *
 * @property \PDO $conn1 Optional description here
 * @property \App\Model\Endereco $endereco
 * @property \App\Model\Imagem $imagem Optional description here
 */
abstract class Model
{
...