VIP-Coding-Standards icon indicating copy to clipboard operation
VIP-Coding-Standards copied to clipboard

WPQueryParams.PostNotIn_exclude: False positive outside get_posts context

Open rebeccahum opened this issue 4 years ago • 2 comments
trafficstars

Bug Description

We started flagging for exclude since it's an alias of post__not_in in #589. Unfortunately, when used outside of a get_posts() or WP_Query context, it's a false positive.

Minimal Code Snippet

	$users = get_users(
		array(
			'blog_id'        => false,
			'include'        => $include_blog_users,
			'exclude'        => $exclude_blog_users,
		)
	);

Error Code

WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude

Environment

Question Answer
PHP version 7.4
PHP_CodeSniffer version 3.6
VIPCS version 2.3

Tested Against master branch?

  • [x] I have verified the issue still exists in the master branch of VIPCS.
  • [x] I have verified the issue still exists in the develop branch of VIPCS.

rebeccahum avatar Apr 21 '21 20:04 rebeccahum

From https://github.com/Automattic/VIP-Coding-Standards/issues/369#issuecomment-705898613:

Also note that exclude is quite a generic array key name, so I suspect adding this key as one to be detected by this sniff will yield lots of false positives for exclude being used in other contexts than get_posts().

At the same time, hard linking the key detection to get_posts() is also not a realistic option as these kind of parameters are often set up outside of the function call / in class properties / class constants etc.

jrfnl avatar Apr 21 '21 22:04 jrfnl

I'm wondering if this might be worth changing the messaging to include a manual inspection disclaimer...

rebeccahum avatar Apr 21 '21 22:04 rebeccahum