-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Squiz.Commenting.FunctionCommentThrowTag.WrongNumber Error for throwing exceptions from called methods #2683
Comments
PHPCS does not analyse an entire project to determine method calls, so the sniff will never work like this. You would need to look into using a different tool if you want something that analyses your entire source and determines execution paths. |
Yes, I would not expect PHPCS to do a deep analysis of what could be possible thrown somewhere. But since it is parsing the code-block for possible thrown exceptions for me it would make sense to also consider the @throw-tags of the phpdoc of called functions/methods. The bigger problem here for me is, that if i exclude this sniff-part |
The WrongNumber part has another bug. The following code doesn't count as exception:
It seems better to remove the WrongNumber part of this sniff.
But still get error with
or
|
The sniff is never going to figure that out. It doesn't trace variables throughout the code, and you could keep coming up with more and more complex failing examples if it tried to. |
The sniff is making the assumption that your docblock is wrong. If it assumed the docblock is right, there really isn't any need for it. |
But sometimes the docblock is wrong and sometimes the docblock is right.
Yeah, I don't expect this sniff to report error for missing docblock. But he should not report error if I use the correct docblock. I think it's better to catch sometimes error and never having false-positive than catch more often error and having sometimes false-positive. |
If your docblock says it throws a second exception but there isn't anywhere in the method where the exception is being thrown, the sniff cant possible know if this docblock is actually correct. It might be correct (an exception thrown from a called method) or it might be a mistake. At some point, the sniff has to decide if it trusts the docblock or not. Should it throw an error for a developer to look at, or not? |
I agree
I prefer to not throw error. If the sniff throw the error, a developper can miss the fact the annotation is needed, and removing it. Plus, I don't want to see everywhere in my code some @phpcs-ignore comment. And finally, when a sniff throw an error when there is not, you lost the trust in this sniff. |
Closing as the sniff is working as expected, even though it may not be considered useful in these cases. |
Hey,
I wanted to use the sniff
Squiz.Commenting.FunctionCommentThrowTag.WrongNumber
but I have to enable it since it is not working as expected. Additional to the different expected behaviour forwrongNumber
theMissing
sniff is not called when wrongNumber is disabled but found a violation (because of areturn
in FunctionCommentThrowTagSniff.php).My use-case:
Example phpcs-file
Error for checking the php-file:
29 | ERROR | Expected 1 @throws tag(s) in function comment; 2 found
My expectation for this sniff would be that it counts in the documented thrown tags from the called methods as well. Also: when switched off the sniff
WrongNumber
it should still findMissing
but it does not. It just findsMissing
case if there is no WrongNumber regardless of it being enabled or not.All the best,
Florian
The text was updated successfully, but these errors were encountered: