Skip to content
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

PrefixAllGlobals/GlobalVariablesOverride: detect variables being set via list() #1774

Closed
1 task done
jrfnl opened this issue Jul 23, 2019 · 0 comments · Fixed by #1783
Closed
1 task done

PrefixAllGlobals/GlobalVariablesOverride: detect variables being set via list() #1774

jrfnl opened this issue Jul 23, 2019 · 0 comments · Fixed by #1783
Assignees
Milestone

Comments

@jrfnl
Copy link
Member

jrfnl commented Jul 23, 2019

Bug Description

Variables being assigned a value via the list() construct - including PHP 7.1 short list syntax - are not recognized as variable assignments for the purposes of the GlobalVariablesOverride and the PrefixAllGlobals sniffs.

This causes false negatives.

Minimal Code Snippet

The below code doesn't produce any errors for the above mentioned sniffs, while it should.

// PREFIX ALL GLOBALS.
// Detect variables being set via the list() construct.
list( $var1, $var2 )                 = $array; // Bad x 2.
list( $acronym_var1, $acronym_var2 ) = $array;

[ $var1, $var2 ]                 = $array; // Bad x 2.
[ $acronym_var1, $acronym_var2 ] = $array;

/**
 * GLOBAL VARS OVERRIDE.
 * Detect var override via list construct.
 */
function acronym_prepare_items() {
	global $wp_query, $post_mime_types, $avail_post_mime_types, $mode;
	list( $post_mime_types, $avail_post_mime_types ) = get_an_array(); // Bad x2.
	[ $post_mime_types, $avail_post_mime_types ]     = get_an_array(); // PHP 7.1 short list syntax, bad x2.
}

Tested Against develop branch?

  • I have verified the issue still exists in the develop branch of WPCS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant