webmozarts / assert

Assertions to validate method input/output with nice error messages.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PhpStrom detecting either redundant throw annotation or catch statement

TonyVlcek opened this issue · comments

commented

To throw or not to throw that is the question...

PhpStrom can detect redundant throw annotations and also redundant catch statements. (more info)

If the throw statement is mentioned directly in the method PhpStorm can detect this, however, in other cases, it relies on annotations.

Webmozart/assert produces exceptions in a non-standard way and that causes PhpStrom to get confused. See images below.

In this case, it warns me about unnecessary @throw annotation, even though the exception can be thrown.
image

If I do it the other way around, I get an unnecessary catch statement notification.
image

I'd propose we add annotations to all the methods in Assert.php. It can be done either manually or using some linter, this would then be part of the tests or even added automatically in CI.

commented

I'm happy to prepare PR for this.

But I thought I'd post the issue to gather some feedback. There might also be some other workaround which would require changes directly in Assert which I'm not aware of.

Assert has annotations to indicate that it throws on all assertion methods. In order to use those you may have to update to the latest version.