【问题标题】:PhpStorm auto complete class methodsPhpStorm 自动完成类方法
【发布时间】:2017-07-05 13:56:39
【问题描述】:

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

<?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 ....
    }
}

【问题讨论】:

    标签: php phpstorm


    【解决方案1】:

    在类的 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
    {
    ...
    

    【讨论】:

    • 太棒了,非常感谢 PHPStorm 认可了所有的自动补码。谢谢
    • @ElvisReis 如果解决了您的问题,请接受答案。
    猜你喜欢
    • 1970-01-01
    • 2019-04-01
    • 2017-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-13
    相关资源
    最近更新 更多