-
Notifications
You must be signed in to change notification settings - Fork 43
Closed
Labels
Description
Bug Description
If you define an abstract class that sets up a filter in its constructor and sets the callback to an abstract method in the class which will be defined by implementing classes, the WordPressVIPMinimum.Hooks.AlwaysReturnInFilter.MissingReturnStatement sniff causes phpcs to crash, because it's trying to evaluate the return statement in an abstract method.
The specific error message being returned is this:
An error occurred during processing; checking has been aborted. The error message was: Undefined index: scope_opener in /path/to/.composer/vendor/automattic/vipwpcs/WordPressVIPMinimum/Sniffs/Hooks/AlwaysReturnInFilterSniff.php on line 194 (Internal.Exception)
Minimal Code Snippet
abstract class good_example_abstract_class { // Ok.
public function __construct() {
add_filter( 'good_example_class_filter', [ $this, 'class_filter' ] );
}
abstract public function class_filter( $param );
}
class good_example_abstract_class_implementation { // Ok.
public function class_filter( $param ) {
if ( 1 === 1 ) {
if ( 1 === 0 ) {
return 'whoops';
} else {
return 'here!';
}
}
return 'This is Okay';
}
}Error Code
No error code should be triggered.
Environment
Use php -v and composer show to get versions.
| Question | Answer |
|---|---|
| PHP version | 7.3.0 |
| PHP_CodeSniffer version | 3.5.6 |
| VIPCS version | 2.2.0 |
Additional Context (optional)
Fixed in PR #581
Tested Against master branch?
- I have verified the issue still exists in the
masterbranch of VIPCS. - I have verified the issue still exists in the
developbranch of VIPCS.
Reactions are currently unavailable