From 0a9b8c97c5ef0219d5863898a0519ac68caf1dee Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 1 May 2019 01:20:58 +0200 Subject: [PATCH] CS: minor updates * Minor ruleset updates: - Use PHPCS 3.x `basepath` directive. - Update the whitelisted "one OO object per file" sniff name. Sniff was swopped out in WPCS 2.0. - Whitelist underscore prefixed method names as renaming those now would break BC. * Minor updates in the main TGMPA file: - Update the inline whitelist comments from WPCS native to PHPCS native style. The WPCS native whitelist comments were deprecated in WPCS 2.0.0. --- class-tgm-plugin-activation.php | 30 +++++++++++++++++++----------- phpcs.xml.dist | 10 +++++++--- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/class-tgm-plugin-activation.php b/class-tgm-plugin-activation.php index 5cd628fb..6ae71d3c 100755 --- a/class-tgm-plugin-activation.php +++ b/class-tgm-plugin-activation.php @@ -294,6 +294,7 @@ public function __construct() { * (Inside this class context, the __set() method if not used as there is direct access.) */ public function __set( $name, $value ) { + // phpcs:ignore Squiz.PHP.NonExecutableCode.ReturnNotRequired -- See explanation above. return; } @@ -654,8 +655,11 @@ public function admin_init() { wp_enqueue_style( 'plugin-install' ); global $tab, $body_id; - $body_id = 'plugin-information'; // WPCS: override ok, prefix ok. - $tab = 'plugin-information'; // WPCS: override ok. + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- WP requirement. + $body_id = 'plugin-information'; + + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Overriding the WP global is the point. + $tab = 'plugin-information'; install_plugin_information(); @@ -1081,7 +1085,8 @@ protected function activate_single_plugin( $file_path, $slug, $automatic = false if ( ! $automatic ) { // Make sure message doesn't display again if bulk activation is performed // immediately after a single activation. - if ( ! isset( $_POST['action'] ) ) { // WPCS: CSRF OK. + // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Not using the superglobal. + if ( ! isset( $_POST['action'] ) ) { echo '

', esc_html( $this->strings['activated_successfully'] ), ' ', esc_html( $this->plugins[ $slug ]['name'] ), '.

'; } } else { @@ -1102,7 +1107,8 @@ protected function activate_single_plugin( $file_path, $slug, $automatic = false if ( ! $automatic ) { // Make sure message doesn't display again if bulk activation is performed // immediately after a single activation. - if ( ! isset( $_POST['action'] ) ) { // WPCS: CSRF OK. + // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Not using the superglobal. + if ( ! isset( $_POST['action'] ) ) { echo '

', sprintf( esc_html( $this->strings['plugin_needs_higher_version'] ), @@ -1405,7 +1411,7 @@ public function register( $plugin ) { 'force_activation' => false, // Boolean. 'force_deactivation' => false, // Boolean. 'external_url' => '', // String. - 'is_callable' => '', // String|Array. + 'is_callable' => '', // String or array. ); // Prepare the received data. @@ -1762,10 +1768,10 @@ protected function is_core_update_page() { if ( 'update-core' === $screen->base ) { // Core update screen. return true; - } elseif ( 'plugins' === $screen->base && ! empty( $_POST['action'] ) ) { // WPCS: CSRF ok. + } elseif ( 'plugins' === $screen->base && ! empty( $_POST['action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing // Plugins bulk update screen. return true; - } elseif ( 'update' === $screen->base && ! empty( $_POST['action'] ) ) { // WPCS: CSRF ok. + } elseif ( 'update' === $screen->base && ! empty( $_POST['action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing // Individual updates (ajax call). return true; } @@ -3092,9 +3098,10 @@ public function process_bulk_actions() { $last_plugin = array_pop( $plugin_names ); // Pop off last name to prep for readability. $imploded = empty( $plugin_names ) ? $last_plugin : ( implode( ', ', $plugin_names ) . ' ' . esc_html_x( 'and', 'plugin A *and* plugin B', 'tgmpa' ) . ' ' . $last_plugin ); - printf( // WPCS: xss ok. + printf( '

%1$s %2$s.

', esc_html( _n( 'The following plugin was activated successfully:', 'The following plugins were activated successfully:', $count, 'tgmpa' ) ), + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Pre-escaped via wrap_in_strong() method above. $imploded ); @@ -3459,7 +3466,8 @@ public function bulk_install( $plugins, $args = array() ) { * @type array $packages Array of plugin, theme, or core packages to update. * } */ - do_action( // WPCS: prefix OK. + do_action( + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Using WP core hook. 'upgrader_process_complete', $this, array( @@ -3874,7 +3882,7 @@ public static function validate_bool( $value ) { * @return bool */ protected static function emulate_filter_bool( $value ) { - // @codingStandardsIgnoreStart + // phpcs:disable WordPress.Arrays.ArrayDeclarationSpacing.ArrayItemNoNewLine static $true = array( '1', 'true', 'True', 'TRUE', @@ -3889,7 +3897,7 @@ protected static function emulate_filter_bool( $value ) { 'no', 'No', 'NO', 'off', 'Off', 'OFF', ); - // @codingStandardsIgnoreEnd + // phpcs:enable if ( is_bool( $value ) ) { return $value; diff --git a/phpcs.xml.dist b/phpcs.xml.dist index e6efba61..af87cf0c 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -7,15 +7,19 @@ + - + - + + + + @@ -36,7 +40,7 @@