简体   繁体   中英

PhpStorm auto complete class methods

I have an abstract class that gets a container with a magic method to pick up the container DI, in a PHPDoc documentation block I'm going to describe the container's variables with the class, I'd like the PhpStorm voce covers the autocomplete functions.

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

for example

<?php
namespace App\Model;

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

Use @property in PHPDoc block for the class: 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
{
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM