Skip to content

AlwaysReturnSniff does not detect filters with no return statement #290

@nickdaugherty

Description

@nickdaugherty

Bug Description

AlwaysReturnSniff doesn't actually trigger if the filter function doesn't include the return statement anywhere.

We have a bunch of tests to ensure AlwaysReturnSniff flags various problematic ways of returning from inside WP filters, but there is no test that ensures it raises a flag when return is omitted entirely.

Minimal Code Snippet

add_filter( 'bad_example_closure_with_no_returns', function( $input ) {
	$input = $input . ' hello!';

	// But we never return _anywhere_
}, 10, 2 );

Error Code

WordPressVIPMinimum.Filters.AlwaysReturn.missingReturnStatement

Environment

Use php -v and composer show to get versions.

Question Answer
PHP version 7.1.19
PHP_CodeSniffer version 3.3.2
VIPCS version master

Tested Against master branch?

  • I have verified the issue still exists in the master branch of VIPCS.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions