Closed dingo-d closed 1 year ago
I've just noticed a similar problem. I've got a function (function_a
) that is documented to throw either an InvalidArgumentException
or a RuntimeException
. "Delegating" these exceptions upward in the doc block for a wrapping function (function_b
) works fine. However, once I add a throw new InvalidArgumentException
in the wrapping function (in addition to those potentially thrown by function_a
), the sniff starts complaining about the second @throws
annotation.
Any update on this?
For me, this still happens, but I think this could be the issue of missing context.
phpcs doesn't know that certain function/method can throw an exception like phpstan does (IIRC I've added the exception in the doc block because of phpstan's suggestion).
Plus the example above is also using a custom ruleset, and the example is not a minimally reproducible one, so I'll close this for now.
@mundschenk-at if you have a better example you can open an issue, but I think the same thing happens in your case (not knowing the context of what is being thrown where).
Describe the bug When I sniff the code for errors it reports that I'm missing a throw tag. When I add it, I get wrong number of exceptions found (2 instead of 1).
Code sample
Custom ruleset
To reproduce Steps to reproduce the behavior:
test.php
with the code sample above.phpcs test.php
If I remove the RuntimeException I get
And since it extends the general
Exception
just throwing one should be ok.Expected behavior No error when just one throw tag is added.
Versions (please complete the following information):