-
Notifications
You must be signed in to change notification settings - Fork 40
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
Ignore return values when a filter callback is abstract #581
Ignore return values when a filter callback is abstract #581
Conversation
* Adjust the "abstract method" test to: 1. Expect a warning. 2. Prevent the hook in getting confused with other functions in the same test file. * Remove the "abstract method implementation" test as it wasn't testing anything. 1. The sniff does not look for child classes, so wouldn't examine that code snippet anyway. Adding this functionality is not that useful either as in most cases, the child class will not be in the same file as the abstract parent class. 2. And even if the sniff did examine it, it would still not recognize it as a child class as the class doesn't `extend` the abstract. * Add a test for a typical case where declared functions do not have a scope opener/closer due to a tokenizer bug. PR squizlabs/PHP_CodeSniffer 3066 is open upstream to fix this. * Add a "live coding" test case.
I've added two additional commits to this PR, updating the unit tests and implementing my suggestion from #580 (comment) |
Noting that the new Warning will now appear when there was no warning previously (which was a false negative due to the lack of support for short array syntax). |
Correct. I've also given it a separate error code on purpose with that in mind. Semver-wise, it should probably go into a minor rather than a patch version as it can be seen as a new feature. |
… error This implements the suggestion made in Automattic#580 (comment) If the method a filter callback points to is an abstract method, a warning will be thrown asking for manual inspection of the child class implementations of the abstract method. In case of parse or tokenizer error, the sniff will bow out and stay silent.
14c9d9b
to
4356274
Compare
Co-authored-by: Rebecca Hum <16962021+rebeccahum@users.noreply.github.com>
If a filter is defined in the constructor of an abstract class, and uses an abstract method as its callback, relying on implementing classes to define the return value, the
WordPressVIPMinimum.Hooks.AlwaysReturnInFilter.MissingReturnStatement
sniff causes phpcs to crash.This PR adds a unit test to confirm the issue, and implements a fix using the same code that is used by phpcs itself.
Fixes #580