diff --git a/WordPressVIPMinimum/ruleset-test.inc b/WordPressVIPMinimum/ruleset-test.inc index 59f6d6d2..5a66acb7 100644 --- a/WordPressVIPMinimum/ruleset-test.inc +++ b/WordPressVIPMinimum/ruleset-test.inc @@ -1,34 +1,83 @@ - - - -query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '" . $_GET['title'] . "';" ); // Error + Warning. - -// WordPress.Variables.GlobalVariables -function foo() { - global $page; // WordPressVIPMinimum.Variables.VariableAnalysis.UnusedVariable // Warning. - $page = get_post( $post_id ); // WordPressVIPMinimum.Variables.VariableAnalysis.UndefinedVariable // Error + Warning. +// WordPress.Security.ValidatedSanitizedInput +if ( isset( $_POST['nonce'] ) && wp_verify_nonce( sanitize_text_field( $_POST['nonce'] ) ) ) { + bar( $_POST['foo2'] ); // Error x 2. + $foo2 = isset( $_POST['foo2'] ) ?? foo( sanitize_text_field( $_POST['foo2'] ) ); // Ok - exclude WordPress.Security.ValidatedSanitizedInput.MissingUnslash. } +// WordPress.Security.PluginMenuSlug +add_menu_page( $page_title, $menu_title, $capability, __FILE__, $function, $icon_url, $position ); // Warning. + +// WordPress.WP.EnqueuedResources +?> 999, // Warning. +); +_query_posts( 'posts_per_page=999' ); // Warning. +$query_args['posts_per_page'] = 999; // Warning. + +// WordPress.WP.TimezoneChange +date_default_timezone_set( 'FooBar' ); // Error. + +// WordPress.DB.PreparedSQL +$b = function () { + global $wpdb; + $listofthings = wp_cache_get( $listofthings ); + if ( ! $listofthings ) { + $foo = "column = 'test'"; + + $listofthings = $wpdb->query( 'SELECT something FROM somewhere WHERE ' . $foo ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Error. + wp_cache_set( 'foo', $listofthings ); + } +}; + +// WordPress.DB.DirectDatabaseQuery +$baz = $wpdb->get_results( $wpdb->prepare( 'SELECT X FROM Y ' ) ); // Warning x 2. + +// WordPress.DB.SlowDBQuery +$test = [ + 'tax_query' => [], // Warning. +]; +new WP_Query( array( + 'meta_query' => [], // Warning. + 'meta_key' => 'foo', // Warning. + 'meta_value' => 'bar', // Warning. +) ); + +// WordPress.WP.GlobalVariablesOverride +$GLOBALS['wpdb'] = 'test'; // Error. + // WordPress.PHP.StrictComparisons if ( true == $true ) { // Warning. } -// WordPress.PHP.YodaConditions -if ( $true === true ) { // Ok. +// WordPress.CodeAnalysis.AssignmentInCondition +if ( $test = get_post( $post ) ) { // Warning. } // WordPress.PHP.StrictInArray @@ -38,14 +87,30 @@ if ( true === in_array( $foo, $bar ) ) { // Warning. // WordPress.Functions.DontExtract extract( $foobar ); // Error. -// WordPress.PHP.DevelopmentFunctions -error_log( 'Hey there!' ); // Error. -var_export( $foo ); // Warning. -var_dump( $bar ); // Warning. +// WordPress.WP.CronInterval +function my_add_weekly( $schedules ) { + $schedules['every_6_mins'] = array( + 'interval' => 360, + 'display' => __( 'Once every 6 minutes' ) + ); + return $schedules; +} +add_filter( 'cron_schedules', 'my_add_weekly'); // Warning. -// WordPress.PHP.DiscouragedPHPFunctions -error_reporting(); // Error. -ini_set(); // Error. +// Generic.NamingConventions.ConstructorName +class TestClass extends MyClass +{ + function __construct() { + parent::MYCLASS(); // Error. + parent::__construct(); + } +} +class OldClass +{ + function OldClass() // Error. + { + } +} // Generic.NamingConventions.ConstructorName class TestClass extends MyClass { @@ -55,138 +120,350 @@ class TestClass extends MyClass { } } -?> - - +// Generic.PHP.DisallowShortOpenTag +?> +// if (empty($this)) {echo 'This is will not work';} -// WordPressVIPMinimum.Hooks.PreGetPosts -add_action( 'pre_get_posts', function( $wp_query ) { - if ( ! $wp_query->is_search() ) { - $wp_query->set( 'cat', '-5' ); // Warning. - } -} ); +// Squiz.PHP.Eval +eval('$var = 4;'); // Error + Message. -// WordPressVIPMinimum.Cache.CacheValueOverride -$bad_wp_users = wp_cache_get( md5( self::CACHE_KEY . '_wp_users'), self::CACHE_GROUP ); -$bad_wp_users = false; // Error. +// WordPress.PHP.DiscouragedPHPFunctions +base64_decode( 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw=='); // Ok - exclude obfuscation group. +base64_encode( 'This is an encoded string' ); // Ok - exclude obfuscation group. +convert_uudecode( "+22!L;W9E(%!(4\"$`\n`" ); // Ok - exclude obfuscation group. +convert_uuencode( "test\ntext text\r\n" ); // Ok - exclude obfuscation group. +str_rot13( 'The quick brown fox jumps over the lazy dog.' ); // Ok - exclude obfuscation group. +serialize(); // Warning. +unserialize(); // Warning. +urlencode(); // Warning. +passthru( 'cat myfile.zip', $err ); // Warning. +$process = proc_open( 'php', $descriptorspec, $pipes, $cwd, $env ); // Warning. +$last_line = system( 'ls', $retval ); // Warning. +$handle = popen( '/bin/ls', 'r' ); // Warning. + +// WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_error_reporting +error_reporting(); // Error. -// WordPressVIPMinimum.Classes.DeclarationCompatibility -class MyWidget extends WP_Widget { - function widget() { - } // Error (line above), missing $args and $instance params. -} +// WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_ini_set +ini_set(); // Error. -// WordPressVIPMinimum.Constants.RestrictedConstants -if ( A8C_PROXIED_REQUEST === true ) { // Warning. -} +// WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_ini_alter +ini_alter(); // Error. -// WordPressVIPMinimum.Files.IncludingFile -require_once "my_file.php"; // Error. +// WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_ini_restore +ini_restore(); // Error. -// WordPressVIPMinimum.Functions.CheckReturnValue -$my_theme_options = get_option( 'my_theme', false ); -if ( array_key_exists( 'key', $my_theme_options ) ) { // Error. -} +// WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_apache_setenv +apache_setenv(); // Error. -// Generic.PHP>NoSilencedErrors + WordPressVIPMinimum.Functions.RestrictedFunctions.file_get_contents_file_get_contents -@file_get_contents( $foo ); // Error + Warning. +// WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_putenv +putenv(); // Error. -// WordPressVIPMinimum.Performance.RegexpCompare + WordPress.DB.SlowDBQuery -$query_args = array( - 'posts_per_page' => 1, - 'post_status' => 'draft', - 'meta_key' => 'my_awesome_meta_key', // WordPress.DB.SlowDBQuery. // Warning. - 'meta_value' => "(^|\n|\r\n)99999($|\n|\r\n)", // WordPress.DB.SlowDBQuery. // Warning. - 'meta_compare' => 'REGEXP', // Error. -); +// WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_set_include_path +set_include_path(); // Error. -// WordPressVIPMinimum.Performance.RemoteRequestTimeout -wp_remote_post( $this->endpoint, array( - 'method' => 'POST', - 'timeout' => 45, // Error. - 'httpversion' => '1.1', - 'blocking' => false, - 'body' => wp_json_encode( $this->logs, JSON_UNESCAPED_SLASHES ), - ) -); +// WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_restore_include_path +restore_include_path(); // Error. -// Squiz.PHP.Eval -eval( ';' ); // Error. +// WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_magic_quotes_runtime +magic_quotes_runtime(); // Error. -// WordPressVIPMinimum.Functions.RestrictedFunctions -wpcom_vip_irc(); // Error. +// WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_set_magic_quotes_runtime +set_magic_quotes_runtime(); // Error. -get_children(); // Error + Message. +// WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_dl +dl(); // Error. -attachment_url_to_postid(); // Error. +// WordPress.PHP.DiscouragedPHPFunctions.system_calls_exec +exec( 'whoami' ); // Error. -str_replace( 'foo', 'bar', 'foobar' ); // Error. +// WordPress.PHP.DiscouragedPHPFunctions.system_calls_shell_exec +$output = shell_exec( 'ls -lart' ); // Error. -wpcom_vip_get_term_link(); // Warning. +// WordPress.PHP.DevelopmentFunctions +var_dump(); // Warning. +var_export(); // Warning. +print_r(); // Warning. +trigger_error(); // Warning. +set_error_handler(); // Warning. +debug_backtrace(); // Warning. +debug_print_backtrace(); // Warning. +wp_debug_backtrace_summary(); // Warning. -wpcom_vip_get_term_by(); // Warning. +// WordPress.PHP.DevelopmentFunctions.prevent_path_disclosure_phpinfo +phpinfo(); // Error. -wpcom_vip_get_category_by_slug(); // Warning. +// WordPress.PHP.DevelopmentFunctions.error_log_error_log +error_log(); // Error. -get_cat_ID(); // Ok. +// WordPress.WP.AlternativeFunctions +curl_init(); // Warning + Message. +curl_close( $ch ); // Warning + Message. +CURL_getinfo(); // Warning + Message. +parse_url( 'http://example.com/' ); // Warning + Message. +$json = json_encode( $thing ); // Warning + Message. +readfile(); // Warning. +fclose(); // Warning. +fopen(); // Warning. +fread(); // Warning. +fsockopen(); // Warning. +pfsockopen(); // Warning. +srand(); // Warning. +mt_srand(); // Warning. +rand(); // Warning. +mt_rand(); // Warning. + +// WordPressVIPMinimum.Functions.RestrictedFunctions.get_posts_get_children +get_children(); // Error + Message. -get_category_link(); // Ok. +// WordPressVIPMinimum.Variables.VariableAnalysis +function foo() { + $a = 'Hello'; + $c = compact( $a, $b ); // Warning x 2. + try { + do_something_silly(); + } catch ( Exception $e ) {} // Ok. +} -get_tag_link(); // Ok. +/* The below rules are implicitly included via WordPressVIPMinimum */ -get_category_by_slug(); // Ok. +// WordPressVIPMinimum.Classes.DeclarationCompatibility +class MyWidget extends WP_Widget { + function widget() { // Error. + } +} -get_term_by(); // Ok. +// WordPressVIPMinimum.Classes.RestrictedExtendClasses +class BadTestClass extends WP_CLI_Command { } // Warning. -get_term_link(); // Ok. +// WordPressVIPMinimum.Compatibility.ZoninatorSniff +wpcom_vip_load_plugin( 'zoninator', 'plugins', '0.8' ); // Warning. -wp_mail(); // Warning. +// WordPressVIPMinimum.Constants.ConstantString +define( WPCOM_VIP ); // Error. -mail(); // Warning. +// WordPressVIPMinimum.Constants.RestrictedConstants +if ( A8C_PROXIED_REQUEST === true ) { // Warning. +} +define( 'JETPACK_DEV_DEBUG', true ); // Error. -dbDelta(); // Error. +// WordPressVIPMinimum.Files.IncludingFile +include ( MY_CONSTANT . "my_file.php" ); // Warning. +require_once( custom_function( 'test_file.php' ) ); // Warning. +require '../my_file.php'; // Error. +include_once("http://www.google.com/bad_file.php"); // Error. + +// WordPressVIPMinimum.Files.IncludingNonPHPFile +require_once __DIR__ . "/my_file.svg"; // Error. + +// WordPressVIPMinimum.Functions.CheckReturnValue +$my_theme_options = get_option( 'my_theme', false ); +if ( array_key_exists( 'key', $my_theme_options ) ) { } // Error. +echo 'My term link'; // Error. + +// WordPressVIPMinimum.Functions.DynamicCalls +$my_notokay_func = 'extract'; +$my_notokay_func(); // Error. +// WordPressVIPMinimum.Functions.RestrictedFunctions +wp_cache_get_multi(); // Error. +opcache_reset(); // Error. +opcache_invalidate( 'test_script.php' ); // Error. +opcache_compile_file( $test_script ); // Error. +opcache_​is_​script_​cached( 'test_script.php' ); // Error. +opcache_​get_​status(); // Error. +opcache_​get_​configuration(); // Error. +get_super_admins(); // Error. +wpcom_vip_irc(); // Error. flush_rewrite_rules(); // Error. -global $wp_rewrite; $wp_rewrite->flush_rules(); // Error. +attachment_url_to_postid( $url ); // Error. +dbDelta(); // Error. +switch_to_blog( $blogid ); // Error. +get_page_by_title( $page_title ); // Error. +url_to_postid( $url ); // Error. +\add_role(); // Error. +get_user_meta(); // Error. +update_user_meta(); // Error. +delete_user_meta(); // Error. +add_user_meta(); // Error. +term_exists(); // Error. +count_user_posts(); // Error. +wp_old_slug_redirect(); // Error. +get_adjacent_post(); // Error. +get_previous_post(); // Error. +get_previous_post_link(); // Error. +get_next_post(); // Error. +get_next_post_link(); // Error. +get_intermediate_image_sizes(); // Error. +wp_is_mobile(); // Error. +session_abort(); // Error. +session_cache_expire(); // Error. +session_cache_limiter(); // Error. +session_commit(); // Error. +session_create_id(); // Error. +session_decode(); // Error. +session_destroy(); // Error. +session_encode(); // Error. +session_gc(); // Error. +session_get_cookie_params(); // Error. +session_id(); // Error. +session_is_registered(); // Error. +session_module_name(); // Error. +session_name(); // Error. +session_regenerate_id(); // Error. +session_register_shutdown(); // Error. +session_register(); // Error. +session_reset(); // Error. +session_save_path(); // Error. +session_set_cookie_params(); // Error. +session_set_save_handler(); // Error. +session_start(); // Error. +session_status(); // Error. +session_unregister(); // Error. +session_unset(); // Error. +session_write_close(); // Error. +delete(); // Error. +file_put_contents( $file, $text, FILE_APPEND ); // Error. +while ( $count > $loop ) { + if ( flock( $fp, LOCK_EX ) ) { // Error. + fwrite( $fp, $text ); // Error. + } +} +fputcsv(); // Error. +fputs(); // Error. +ftruncate(); // Error. +is_writable(); // Error. +is_writeable(); // Error. +link(); // Error. +rename(); // Error. +symlink(); // Error. +tempnam(); // Error. +touch(); // Error. +unlink(); // Error. +mkdir(); // Error. +rmdir(); // Error. +chgrp(); // Error. +chown(); // Error. +chmod(); // Error. +lchgrp(); // Error. +lchown(); // Error. +add_site_option( 'foo', $bar ); // Error. +update_site_option( $bar, $foo, true ); // Error. +delete_site_option( $foo ); // Error. +wp_mail(); // Warning. +mail(); // Warning. +is_multi_author(); // Warning. +the_sub_field( 'field' ); // Warning. +the_field( 'field' ); // Warning. +wp_remote_get( $url ); // Warning. +setcookie( 'cookie[three]', 'cookiethree' ); // Warning. +get_posts(); // Warning. +wp_get_recent_posts(); // Warning. +$wp_random_testing = create_function( '$a, $b', 'return ( $b / $a ); '); // Warning. +wpcom_vip_get_term_link(); // Warning. +wpcom_vip_get_term_by(); // Warning. +wpcom_vip_get_category_by_slug(); // Warning. -// WordPress.CodeAnalysis.AssignmentInCondition. -if ( $a = 1 ) {} // Warning. - -add_option( 'taxonomy_rating_' . $obj->term_id ); // Warning. +// WordPressVIPMinimum.Functions.StripTagsSniff +strip_tags( 'Testing' ); // Warning. +strip_tags( 'Test', $html ); // Warning. + +// WordPressVIPMinimum.Hooks.AlwaysReturnInFilter +function bad_example_function_thing() { // Error. + if ( 1 === 0 ) { + if ( 1 === 1 ) { + return 'ahoj'; + } else { + return 'hello'; + } + } +} +add_filter( 'bad_example_function_filter', 'bad_example_function_thing' ); +add_filter( 'another_bad_example_closure', function() { // Error. + return; +} ); -//wpcom_vip_load_plugin( 'disqus' ); // Warning. +// WordPressVIPMinimum.Hooks.PreGetPosts +add_action( 'pre_get_posts', function( $wp_query ) { + if ( ! $wp_query->is_search() ) { + $wp_query->set( 'cat', '-5' ); // Warning. + } +} ); -echo ""; // Error. +// WordPressVIPMinimum.Hooks.RestrictedHooks +add_filter( 'upload_mimes', 'bad_example_function' ); // Warning. +add_action( 'http_request_timeout', 'bad_example_function' ); // Warning. +add_filter('http_request_args', 'bad_example_function' ); // Warning. +add_action( 'do_robotstxt', 'my_do_robotstxt'); // Warning. +add_filter( 'robots_txt', function() { // Warning. + return 'test'; +} ); -$hello = true === isset( $_GET['utm_medium'] ) ? true : false; // Warning. +// WordPressVIPMinimum.Performance.BatcacheWhitelistedParams +// phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotValidated +$test = sanitize_text_field( $_GET["utm_medium"] ); // Warning. -wp_safe_redirect( 'https.//vip.wordpress.com' ); // Error. +// WordPressVIPMinimum.Performance.CacheValueOverride +$bad_wp_users = wp_cache_get( md5( self::CACHE_KEY . '_wp_users'), self::CACHE_GROUP ); +$bad_wp_users = false; // Error. -is_multi_author(); // Warning. +// WordPressVIPMinimum.Performance.FetchingRemoteData +$external_resource = file_get_contents( 'https://example.com' ); // Warning. -include( 'non-php-file.svg' ); // Error. Including non-php file. +// WordPressVIPMinimum.Performance.LowExpiryCacheTime +wp_cache_set( 'test', $data, $group, 100 ); // Warning. +wp_cache_add( 123, $data, null, 1.5 * MINUTE_IN_SECONDS ); // Warning. +wp_cache_replace( 'test', $data, $group, 2*MINUTE_IN_SECONDS ); // Warning. -echo file_get_contents( 'non-php-file.svg' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Preferred way of including SVG/CSS file. +// WordPressVIPMinimum.Performance.NoPaging +$args = array( + 'nopaging' => true, // Error. +); +_query_posts( 'nopaging=true' ); // Error. -// phpcs:set WordPressVIPMinimum.VIP.CronInterval min_interval 600 -add_filter( 'cron_schedules', 'my_add_weekly' ); // Error. 6 min. -// phpcs:set WordPressVIPMinimum.VIP.CronInterval min_interval 900 +// WordPressVIPMinimum.Performance.OrderByRand +$args = array( + "orderby" => "RAND", // Error. +); +$query_args['orderby'] = 'rand'; // Error. -thisisasyntaxerror! // Error. +// WordPressVIPMinimum.Performance.RegexpCompare +$query_args = array( + 'posts_per_page' => 1, + 'post_status' => 'draft', + 'meta_compare' => 'REGEXP', // Error. +); +$query_args = [ + 'post_status' => 'publish', + 'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query + [ + 'compare' => 'REGEXP', // Error. + ] + ] +]; -// WordPressVIPMinimum.Functions.RestrictedFunctions.site_option_add_site_option -add_site_option( 'foo', $bar ); // Error. +// WordPressVIPMinimum.Performance.RemoteRequestTimeout +wp_remote_post( $this->endpoint, array( + 'method' => 'POST', + 'timeout' => 45, // Error. + 'httpversion' => '1.1', + 'blocking' => false, + 'body' => wp_json_encode( $this->logs, JSON_UNESCAPED_SLASHES ), + ) +); -// WordPressVIPMinimum.Functions.RestrictedFunctions.site_option_update_site_option -update_site_option( $bar, $foo, true ); // Error. +// WordPressVIPMinimum.Performance.TaxonomyMetaInOptions +get_option( "taxonomy_rating_$obj->term_id" ); // Warning. +update_option( 'taxonomy_rating_' . $category_id ); // Warning. -// WordPressVIPMinimum.Functions.RestrictedFunctions.site_option_delete_site_option -delete_site_option( $foo ); // Error. +// WordPressVIPMinimum.Performance.WPQueryParams +$query_args = array( + 'post__not_in' => $posts_not_in, // Warning. + 'suppress_filters' => true, // Error. +); // WordPressVIPMinimum.Security.EscapingVoidReturnFunctions.Found esc_js( _deprecated_argument() ); // Error. @@ -195,13 +472,111 @@ esc_js( _deprecated_file() ); // Error. esc_js( _deprecated_function() ); // Error. esc_js( _deprecated_hook() ); // Error. esc_js( _doing_it_wrong() ); // Error. -esc_html( _e( 'foo', 'bar' ) ); // Error. -esc_html( _ex( 'foo', 'bar' ) ); // Error. -esc_attr( printf( 'foo', [] ) ); // Error. -esc_attr( trigger_error( 'foo' ) ); // Error (+ warning due to trigger_error() call). +esc_html( printf( 'foo', [] ) ); // Error. esc_attr( user_error( 'foo', '' ) ); // Error. esc_attr( vprintf( 'foo', [] ) ); // Error. esc_attr( wp_die( 'foo' ) ); // Error. esc_attr( wp_dropdown_pages() ); // Error. -?> +// WordPressVIPMinimum.Security.ExitAfterRedirect +function redirect_test() { + wp_safe_redirect( 'https.//vip.wordpress.com' ); // Error. +} +wp_redirect( 'https://vip.wordpress.com' ); // Error. + +// WordPressVIPMinimum.Security.PHPFilterFunctions +filter_input( INPUT_GET, 'foo' ); // Warning. +filter_input( INPUT_GET, "foo", FILTER_UNSAFE_RAW ); // Warning. +filter_var( $url, FILTER_DEFAULT ); // Warning. +filter_var_array( $array ); // Warning. +filter_input_array( $array ); // Warning. + +// WordPressVIPMinimum.Security.Mustache +echo '{{{data}}}'; // Warning. +?> + + '; // Error. +echo ''; // Error. + +// WordPressVIPMinimum.Security.StaticStrreplace +str_replace( 'foo', array( 'bar', 'foo' ), 'foobar' ); // Error. + +// WordPressVIPMinimum.Security.Underscorejs +echo ""; + +// WordPressVIPMinimum.Security.Vuejs +?>
+

+
+#wpadminbar { + visibility: hidden; /* Error. */ + display: none; /* Error. */ + opacity: 0; /* Error. */ +} +'; +echo ''; // Error. +?> users"; // Error. +$x = foo( sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated -- Warning. +foo( $_SESSION['bar'] ); // Error. + +// WordPressVIPMinimum.Variables.ServerVariables +// phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotValidated,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized +$test = $_SERVER['PHP_AUTH_PW']; // Error. +bar( $_SERVER['HTTP_X_IP_TRAIL'] ); // Error. +$_SERVER['HTTP_X_FORWARDED_FOR']; // Error. +$_SERVER["REMOTE_ADDR"]; // Error. +// phpcs:enable WordPress.Security.ValidatedSanitizedInput.InputNotValidated,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + + +// WordPressVIPMinimum.Variables.VariableAnalysis +function foo() { + $a = 'Hello'; + $c = compact( $a, $b ); // Warning x 2. +} + +// WordPressVIPMinimum.VersionControl.MergeConflict +function is_prime( $n ) { + if ( 2 === $n ) { + } +//phpcs:ignore Generic.PHP.Syntax.PHPSyntax +======= // Error. + if ( $n % 2 === 0 ) { + } +} + +// Squiz.WhiteSpace.SuperfluousWhitespace +// Error. ?> + + + + diff --git a/WordPressVIPMinimum/ruleset-test.php b/WordPressVIPMinimum/ruleset-test.php index 85912cfe..424a46db 100644 --- a/WordPressVIPMinimum/ruleset-test.php +++ b/WordPressVIPMinimum/ruleset-test.php @@ -16,83 +16,282 @@ $expected = [ 'errors' => [ 4 => 1, - 8 => 1, - 15 => 1, - 18 => 1, - 23 => 1, - 39 => 1, - 42 => 1, - 47 => 1, - 48 => 1, - 52 => 1, - 53 => 1, - 60 => 1, - 75 => 1, - 79 => 1, + 7 => 1, + 11 => 1, + 16 => 1, + 17 => 1, + 21 => 1, + 27 => 2, + 35 => 1, + 45 => 1, + 54 => 1, + 73 => 1, 88 => 1, - 92 => 1, - 96 => 1, 104 => 1, 110 => 1, + 117 => 1, 118 => 1, - 121 => 1, - 123 => 1, - 125 => 1, - 127 => 1, - 151 => 1, + 124 => 1, + 130 => 1, + 147 => 1, + 150 => 1, 153 => 1, - 155 => 1, - 164 => 1, + 156 => 1, + 159 => 1, + 162 => 1, + 165 => 1, 168 => 1, - 172 => 1, + 171 => 1, + 174 => 1, + 177 => 1, 180 => 1, 183 => 1, + 196 => 1, + 199 => 1, + 219 => 1, + 234 => 1, + 245 => 1, + 250 => 1, + 255 => 1, + 256 => 1, + 259 => 1, + 263 => 1, + 264 => 1, + 268 => 1, + 271 => 1, + 272 => 1, + 273 => 1, + 274 => 1, + 275 => 1, + 276 => 1, + 277 => 1, + 278 => 1, + 279 => 1, + 280 => 1, + 281 => 1, + 282 => 1, + 283 => 1, + 284 => 1, + 285 => 1, + 286 => 1, + 287 => 1, + 288 => 1, + 289 => 1, + 290 => 1, + 291 => 1, + 292 => 1, + 293 => 1, + 294 => 1, + 295 => 1, + 296 => 1, + 297 => 1, + 298 => 1, + 299 => 1, + 300 => 1, + 301 => 1, + 302 => 1, + 303 => 1, + 304 => 1, + 305 => 1, + 306 => 1, + 307 => 1, + 308 => 1, + 309 => 1, + 310 => 1, + 311 => 1, + 312 => 1, + 313 => 1, + 314 => 1, + 315 => 1, + 316 => 1, + 317 => 1, + 318 => 1, + 319 => 1, + 320 => 1, + 321 => 1, + 322 => 1, + 323 => 1, + 324 => 1, + 325 => 1, + 326 => 1, + 327 => 1, + 328 => 1, + 329 => 1, + 331 => 1, + 332 => 1, + 335 => 1, + 336 => 1, + 337 => 1, + 338 => 1, + 339 => 1, + 340 => 1, + 341 => 1, + 342 => 1, + 343 => 1, + 344 => 1, + 345 => 1, + 346 => 1, + 347 => 1, + 348 => 1, + 349 => 1, + 350 => 1, + 351 => 1, + 352 => 1, + 353 => 1, + 354 => 1, + 355 => 1, + 375 => 1, + 385 => 1, + 411 => 1, + 423 => 1, + 425 => 1, + 429 => 1, + 431 => 1, + 437 => 1, + 443 => 1, + 451 => 1, + 465 => 1, + 469 => 1, + 470 => 1, + 471 => 1, + 472 => 1, + 473 => 1, + 474 => 1, + 475 => 1, + 476 => 1, + 477 => 1, + 478 => 1, + 479 => 1, + 483 => 1, + 485 => 1, + 510 => 1, + 511 => 1, + 514 => 1, + 529 => 1, + 530 => 1, + 533 => 1, + 534 => 1, + 535 => 1, + 538 => 1, + 541 => 1, + 542 => 1, + 543 => 1, + 548 => 1, + 550 => 1, + 554 => 1, + 555 => 1, + 556 => 1, + 557 => 1, + 572 => 1, + 578 => 1, + ], + 'warnings' => [ + 32 => 1, + 39 => 1, + 41 => 1, + 42 => 1, + 60 => 2, + 64 => 1, + 67 => 1, + 68 => 1, + 69 => 1, + 76 => 1, + 80 => 1, + 84 => 1, + 98 => 1, + 126 => 1, + 138 => 1, + 139 => 1, + 140 => 1, + 141 => 1, + 142 => 1, + 143 => 1, + 144 => 1, 186 => 1, + 187 => 1, + 188 => 1, 189 => 1, + 190 => 1, + 191 => 1, 192 => 1, 193 => 1, - 194 => 1, - 195 => 1, - 196 => 1, - 197 => 1, - 198 => 1, - 199 => 1, - 200 => 1, - 201 => 1, 202 => 1, 203 => 1, 204 => 1, 205 => 1, - ], - 'warnings' => [ - 18 => 1, - 22 => 1, - 23 => 1, - 27 => 1, - 35 => 1, - 43 => 1, - 44 => 1, - 64 => 1, - 69 => 1, - 84 => 1, - 96 => 1, - 102 => 1, - 103 => 1, - 129 => 1, - 131 => 1, - 133 => 1, - 147 => 1, - 149 => 1, - 158 => 1, - 160 => 1, - 162 => 1, - 166 => 1, - 170 => 1, - 177 => 1, - 201 => 1, + 206 => 1, + 207 => 1, + 208 => 1, + 209 => 1, + 210 => 1, + 211 => 1, + 212 => 1, + 213 => 1, + 214 => 1, + 215 => 1, + 216 => 1, + 224 => 2, + 239 => 1, + 242 => 1, + 248 => 1, + 253 => 1, + 254 => 1, + 356 => 1, + 357 => 1, + 358 => 1, + 359 => 1, + 360 => 1, + 361 => 1, + 362 => 1, + 363 => 1, + 364 => 1, + 365 => 1, + 366 => 1, + 367 => 1, + 368 => 1, + 371 => 1, + 372 => 1, + 392 => 1, + 397 => 1, + 398 => 1, + 399 => 1, + 400 => 1, + 401 => 1, + 407 => 1, + 414 => 1, + 417 => 1, + 418 => 1, + 419 => 1, + 459 => 1, + 460 => 1, + 464 => 1, + 488 => 1, + 489 => 1, + 490 => 1, + 491 => 1, + 492 => 1, + 495 => 1, + 498 => 1, + 505 => 1, + 519 => 1, + 525 => 1, + 549 => 1, + 564 => 2, ], 'messages' => [ - 123 => [ + 130 => [ + '`eval()` is a security risk, please refrain from using it.', + ], + 202 => [ + 'Using cURL functions is highly discouraged within VIP context. Please see: https://lobby.vip.wordpress.com/wordpress-com-documentation/fetching-remote-data/.', + ], + 203 => [ + 'Using cURL functions is highly discouraged within VIP context. Please see: https://lobby.vip.wordpress.com/wordpress-com-documentation/fetching-remote-data/.', + ], + 204 => [ + 'Using cURL functions is highly discouraged within VIP context. Please see: https://lobby.vip.wordpress.com/wordpress-com-documentation/fetching-remote-data/.', + ], + 219 => [ '`get_children()` performs a no-LIMIT query by default, make sure to set a reasonable `posts_per_page`. `get_children()` will do a -1 query by default, a maximum of 100 should be used.', ], ], @@ -103,8 +302,7 @@ // Run the tests! $test = new RulesetTest( 'WordPressVIPMinimum', $expected ); if ( $test->passes() ) { - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped - printf( 'All WordPressVIPMinimum tests passed!' . PHP_EOL ); + printf( 'All WordPressVIPMinimum tests passed!' . PHP_EOL ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped exit( 0 ); } diff --git a/WordPressVIPMinimum/ruleset.xml b/WordPressVIPMinimum/ruleset.xml index 81057650..59fe372a 100644 --- a/WordPressVIPMinimum/ruleset.xml +++ b/WordPressVIPMinimum/ruleset.xml @@ -38,7 +38,7 @@ - + @@ -59,10 +59,9 @@ - error - `eval()` is a security risk so not allowed. + `eval()` is a security risk, please refrain from using it. @@ -73,10 +72,10 @@ - + error - + error @@ -116,12 +115,12 @@ - + - + error @@ -135,15 +134,27 @@ + + + + + + - - Using cURL functions is highly discouraged within VIP context. Check (Fetching Remote Data) on VIP Documentation. + + Using cURL functions is highly discouraged within VIP context. Please see: https://lobby.vip.wordpress.com/wordpress-com-documentation/fetching-remote-data/. - - `%s()` is highly discouraged, please use `vip_safe_wp_remote_get()` instead. + + Using cURL functions is highly discouraged within VIP context. Please see: https://lobby.vip.wordpress.com/wordpress-com-documentation/fetching-remote-data/. + + + Using cURL functions is highly discouraged within VIP context. Please see: https://lobby.vip.wordpress.com/wordpress-com-documentation/fetching-remote-data/. + + + Using cURL functions is highly discouraged within VIP context. Please see: https://lobby.vip.wordpress.com/wordpress-com-documentation/fetching-remote-data/. @@ -157,14 +168,4 @@ - - - - 0 - - - - 0 - -