1

Is there any way how I can also document the thrown exceptions if the method is documented via the PHPdoc tag @method? According to the official documentation on @method this seems impossible. But maybe there is an unofficial way which is understood by most IDEs? (My IDE is PHPstorm).

Example for a use case:

The PHP framework Laravel supports so-called "facade" classes which allow to access the method of an instance of a class in a static way. Hence, I frequently have a class like this:

class MyFooProvider {

  /**
   * Does something fancy.
   *
   * @param  string                    $arg  bla bla bla
   * @return int                             blub blub blub
   * @throws \InvalidArgumentException       thrown, if ...
   */
  public function bar(string $arg): int {
    ...
  }
}

/*
 * Provides access to methods of {@link MyFooProvider} in a static way.
 *
 * @internal keep the list of documented methods in sync with {@link MyFooProvider}
 *
 * @method static int bar(string $arg)  Does something fancy.
 */
class Foo extends Facade {
  protected static function getFacadeAccessor(): string {
    return 'MyFooProvider';
  }
}

However, if I use Foo::bar the IDE does not know that Foo::bar might throw the exception \InvalidArgumentException.

user2690527
  • 1,729
  • 1
  • 22
  • 38
  • Don't think there's any way around this. Laravel's "magic" doesn't work well with IDE completions. – miken32 Dec 23 '21 at 18:59

0 Answers0