Lewis Tudor
Lewis Tudor

Reputation: 77

Add to custom methods to method signature autocomplete

When in a class there is the ability to autocomplete certain methods, e.g. the constructor or some inherited functions. I'd like to add some custom methods like public function foo():void to the autocomplete if a specific trait is applied. First I thought of Live Templates but they cannot be constrained to be only applied if there is a certain trait present.

Do you have any idea how I could achieve this? Maybe by generating some docblocks?

Upvotes: 0

Views: 121

Answers (1)

LazyOne
LazyOne

Reputation: 165178

You can use @method tag in PHPDoc comment for the trait to declare such "virtual" methods. Modern PhpStorm versions can offer such signature when invoking code completion when declaring a new method.

<?php
declare(strict_types=1);

/**
 * @method void traitPublic()
 */
trait T
{
    private function traitPrivate(): void
    {
    }
}

class C
{
    use T;
}

enter image description here

Upvotes: 1

Related Questions