Skip to content

Looking for a way to improve @method and exceptions. #8163

@VincentLanglet

Description

@VincentLanglet

Feature request

I still struggle with the following issue
#7667
When a library is relying a lot of __call method and @method there is no way to tell phpstan exceptions are thrown.

As explained in the issue,
Overriding the method with a stub is doing nothing since this is not a real method.

But if we have

/**
 * @method int test()
 */
class Foo
{
    /** @throws \Exception */
    public function __call($name, $args)
    {
          if (rand(1, 10) > 5) {
              throws \Exception()
          } 
    }
}

try {
     (new Foo())->test();
} catch (\Exception) {
}

Currently the catch is reported as a dead catch.

Would it be possible for phpstan to consider that the @throws tag of the __call method should be used for all the @method ?

I know @method is not a good practice. But when it's used by our vendor, we don't have a lot of solution...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions