userlond userlond - 6 months ago 73
PHP Question

PhpStorm PHPDocs document static facade class type to enable autocomplete

I create alias for static class using class_alias function:

<?php
/**
* Class A
*/
class A {
static function doSomething() {
print 42;
}
}
// create alias, now calling B:: is the same like A::
class_alias('A', 'B');

// here autocomplete is not working
B::doSomething();


Everything work ok, except autocomplete is not working when I type
B::
and press Ctrl + Space.

Does PHPDoc or PhpStorm has some magic to help autocomplete to tell type of alias class to enable autocomplete, something as:

<?php
// /** @alias <full_name_of_original_class> <alias_name> */
/** @alias A B */
B::doSomething();

Answer
  1. Current PHPDoc (and PSR-5) has no @alias or similar tag

  2. Same with PhpStorm

  3. One day PhpStorm may support class_alias(). https://youtrack.jetbrains.com/issue/WI-11936 -- watch this ticket (star/vote/comment) to get notified on any progress.

  4. The only option I can offer you is to create something like class B extends A {} in a separate file that will be used by IDE only. BTW -- that's how Laravel's facades are supported (a way to tell IDE what those classes can do/what methods they have etc).