Skip to content

Commit 36f1684

Browse files
committed
WordPressVIPMinimum RulesetTest: fix it
To be honest, I'm completely stumped. I can't, for the life of me, think of a reason why the update of the WPCS dependency would suddenly cause all sorts of notices from the `VariableAnalysis` to show, where they previously did not. * It can't be related to the version update of the `VariableAnalysis` sniff in VIPCS 2.3.4, nor the move of the properties from the Go ruleset to the Minimum ruleset as, in that case, the build for the earlier PR/commit should also have been failing. * It can't be related to the VIPCS native `VariableAnalysis` sniff being removed as, in that case, the build for the earlier PR/commit should also have been failing. * VA and WPCS currently have two overlapping CS related dependencies. - PHP_CodeSniffer itself, but as they both use the same version, that can not be a reason for the change in the results. - The Composer plugin, but that shouldn't influence the scan results, other than if a ruleset would not be registered, but if that were the case (for VA), the tests should have been failing before on line 264, which specifically tests the VA standard triggering a notice (and yes, I checked, it did do so correctly before and after). * No new parse errors were accidentally introduced into the test files. As things are, I'm out of ideas of why these warnings are now suddenly showing up, so all I can do is fix them (by selectively silencing the notices from VA). Note: this is only happening in the Minimum ruleset test as VIPGo silences the `UnusedVariable` notice completely.
1 parent 4094eec commit 36f1684

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

WordPressVIPMinimum/ruleset-test.inc

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
<?php // Error - Squiz.WhiteSpace.SuperfluousWhitespace.
5-
$hello = ''; $posts_not_in = ''; $listofthings = ''; $cachedlistofthings = ''; $title = ''; $ch = ''; $thing = ''; $descriptorspec = ''; $pipes = ''; $cwd = ''; $env = ''; $page_title = ''; $menu_title = ''; $capability = ''; $function = ''; $icon_url = ''; $position = ''; $wpdb = ''; $file = ''; $fp = ''; $dir = ''; $test = ''; $post = ''; $bar = ''; $array = []; $query_args = []; $url = ''; $query = ''; $page_title = ''; $true = true; $some_nasty_var = ''; $data = ''; $group = ''; $testing = ''; $stdClass = new stdClass(); $needle = ''; $some_var = ''; $blogid = 1; $text = ''; $category_id = 123; $foo = ''; $bar = ''; $var = ''; $wp_rewrite = ''; $count = 1; $loop = 1; $a = ''; $b = ''; $obj = ''; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- All set for VariableAnalysis checks.
5+
$hello = ''; $posts_not_in = ''; $title = ''; $ch = ''; $thing = ''; $descriptorspec = ''; $pipes = ''; $cwd = ''; $env = ''; $page_title = ''; $menu_title = ''; $capability = ''; $function = ''; $icon_url = ''; $position = ''; $wpdb = ''; $file = ''; $fp = ''; $test = ''; $post = ''; $bar = ''; $array = []; $query_args = []; $url = ''; $page_title = ''; $true = true; $data = ''; $group = ''; $stdClass = new stdClass(); $needle = ''; $some_var = ''; $blogid = 1; $text = ''; $category_id = 123; $foo = ''; $bar = ''; $var = ''; $wp_rewrite = ''; $count = 1; $loop = 1; $obj = ''; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- All set for VariableAnalysis checks.
66
// Generic.PHP.Syntax
77
foreach() { // Error.
88
}
@@ -25,7 +25,7 @@ function bar() {
2525
// WordPress.Security.ValidatedSanitizedInput
2626
if ( isset( $_POST['nonce'] ) && wp_verify_nonce( sanitize_text_field( $_POST['nonce'] ) ) ) {
2727
bar( $_POST['foo2'] ); // Error x 2.
28-
$foo2 = isset( $_POST['foo2'] ) ?? foo( sanitize_text_field( $_POST['foo2'] ) ); // Ok - exclude WordPress.Security.ValidatedSanitizedInput.MissingUnslash.
28+
$foo2 = isset( $_POST['foo2'] ) ?? foo( sanitize_text_field( $_POST['foo2'] ) ); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Ok - exclude WordPress.Security.ValidatedSanitizedInput.MissingUnslash.
2929
}
3030

3131
// WordPress.Security.PluginMenuSlug
@@ -35,7 +35,7 @@ add_menu_page( $page_title, $menu_title, $capability, __FILE__, $function, $icon
3535
?> <script src="http://someurl/somefile.js"></script> <?php // Error.
3636

3737
// WordPress.WP.PostsPerPage
38-
$args = array(
38+
$args = array( // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
3939
'posts_per_page' => 999, // Warning.
4040
);
4141
_query_posts( 'posts_per_page=999' ); // Warning.
@@ -45,7 +45,7 @@ $query_args['posts_per_page'] = 999; // Warning.
4545
date_default_timezone_set( 'FooBar' ); // Error.
4646

4747
// WordPress.DB.PreparedSQL
48-
$b = function () {
48+
$b = function () { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
4949
global $wpdb;
5050
$listofthings = wp_cache_get( 'foo' );
5151
if ( ! $listofthings ) {
@@ -57,7 +57,7 @@ $b = function () {
5757
};
5858

5959
// WordPress.DB.DirectDatabaseQuery
60-
$baz = $wpdb->get_results( $wpdb->prepare( 'SELECT X FROM Y ' ) ); // Warning x 2.
60+
$baz = $wpdb->get_results( $wpdb->prepare( 'SELECT X FROM Y ' ) ); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Warning x 2.
6161

6262
// WordPress.DB.SlowDBQuery
6363
$test = [
@@ -139,9 +139,9 @@ serialize(); // Warning.
139139
unserialize(); // Warning.
140140
urlencode(); // Warning.
141141
passthru( 'cat myfile.zip', $err ); // Warning.
142-
$process = proc_open( 'php', $descriptorspec, $pipes, $cwd, $env ); // Warning.
143-
$last_line = system( 'ls', $retval ); // Warning.
144-
$handle = popen( '/bin/ls', 'r' ); // Warning.
142+
$process = proc_open( 'php', $descriptorspec, $pipes, $cwd, $env ); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Warning.
143+
$last_line = system( 'ls', $retval ); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Warning.
144+
$handle = popen( '/bin/ls', 'r' ); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Warning.
145145

146146
// WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_error_reporting
147147
error_reporting(); // Error.
@@ -174,7 +174,7 @@ dl(); // Error.
174174
exec( 'whoami' ); // Error.
175175

176176
// WordPress.PHP.DiscouragedPHPFunctions.system_calls_shell_exec
177-
$output = shell_exec( 'ls -lart' ); // Error.
177+
$output = shell_exec( 'ls -lart' ); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Error.
178178

179179
// WordPress.PHP.DevelopmentFunctions
180180
var_dump(); // Warning.
@@ -243,7 +243,7 @@ curl_init(); // Warning + Message.
243243
curl_close( $ch ); // Warning + Message.
244244
CURL_getinfo(); // Warning + Message.
245245
parse_url( 'http://example.com/' ); // Warning.
246-
$json = json_encode( $thing ); // Warning.
246+
$json = json_encode( $thing ); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Warning.
247247
readfile(); // Warning.
248248
fclose(); // Warning.
249249
fopen(); // Warning.
@@ -402,7 +402,7 @@ wp_remote_get( $url ); // Warning.
402402
setcookie( 'cookie[three]', 'cookiethree' ); // Error.
403403
get_posts(); // Warning.
404404
wp_get_recent_posts(); // Warning.
405-
$wp_random_testing = create_function( '$a, $b', 'return ( $b / $a ); '); // Warning.
405+
$wp_random_testing = create_function( '$a, $b', 'return ( $b / $a ); '); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Warning.
406406
wpcom_vip_get_term_link(); // Warning.
407407
wpcom_vip_get_term_by(); // Warning.
408408
wpcom_vip_get_category_by_slug(); // Warning.
@@ -447,25 +447,25 @@ add_filter( 'robots_txt', function() { // Warning.
447447

448448

449449
// WordPressVIPMinimum.Performance.CacheValueOverride
450-
$bad_wp_users = wp_cache_get( md5( self::CACHE_KEY . '_wp_users'), self::CACHE_GROUP );
451-
$bad_wp_users = false; // Error.
450+
$bad_wp_users = wp_cache_get( md5( self::CACHE_KEY . '_wp_users'), self::CACHE_GROUP ); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
451+
$bad_wp_users = false; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Error.
452452

453453
// WordPressVIPMinimum.Performance.FetchingRemoteData
454-
$external_resource = file_get_contents( 'https://example.com' ); // Warning.
454+
$external_resource = file_get_contents( 'https://example.com' ); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Warning.
455455

456456
// WordPressVIPMinimum.Performance.LowExpiryCacheTime
457457
wp_cache_set( 'test', $data, $group, 100 ); // Warning.
458458
wp_cache_add( 123, $data, null, 1.5 * MINUTE_IN_SECONDS ); // Warning.
459459
wp_cache_replace( 'test', $data, $group, 2*MINUTE_IN_SECONDS ); // Warning.
460460

461461
// WordPressVIPMinimum.Performance.NoPaging
462-
$args = array(
462+
$args = array( // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
463463
'nopaging' => true, // Error.
464464
);
465465
_query_posts( 'nopaging=true' ); // Error.
466466

467467
// WordPressVIPMinimum.Performance.OrderByRand
468-
$args = array(
468+
$args = array( // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
469469
"orderby" => "RAND", // Error.
470470
);
471471
$query_args['orderby'] = 'rand'; // Error.
@@ -585,8 +585,8 @@ echo '<style type="text/css">.show-admin-bar { visibility: hidden; }</style>'; /
585585
</style> <?php
586586

587587
// WordPressVIPMinimum.Variables.RestrictedVariables
588-
$query = "SELECT * FROM $wpdb->users"; // Error.
589-
$x = foo( sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated -- Warning.
588+
$query = "SELECT * FROM $wpdb->users"; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Error.
589+
$x = foo( sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated,VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- Warning.
590590
foo( $_SESSION['bar'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- Error.
591591

592592
// WordPressVIPMinimum.Variables.ServerVariables

0 commit comments

Comments
 (0)