From fa0e10aae39b5226894ef1e22c7be549b048bc4a Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 10 Apr 2020 01:41:42 +0200 Subject: [PATCH 1/5] PHPCSHelper: deprecate the class and all the methods in it As everything here is now contained within PHPCSUtils, including updated and/or improved versions of some of these. --- WordPress/PHPCSHelper.php | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/WordPress/PHPCSHelper.php b/WordPress/PHPCSHelper.php index 1599a97a1b..9260e55df1 100644 --- a/WordPress/PHPCSHelper.php +++ b/WordPress/PHPCSHelper.php @@ -11,6 +11,7 @@ use PHP_CodeSniffer\Config; use PHP_CodeSniffer\Files\File; +use PHPCSUtils\BackCompat\Helper; /** * PHPCSHelper @@ -22,7 +23,8 @@ * * @package WPCS\WordPressCodingStandards * - * @since 0.13.0 + * @since 0.13.0 + * @deprecated 3.0.0 Use {@see PHPCSUtils\BackCompat\Helper} instead. */ class PHPCSHelper { @@ -34,7 +36,7 @@ class PHPCSHelper { * @return string */ public static function get_version() { - return Config::VERSION; + return Helper::getVersion(); } /** @@ -42,7 +44,8 @@ public static function get_version() { * * PHPCS cross-version compatibility helper. * - * @since 0.13.0 + * @since 0.13.0 + * @deprecated 3.0.0 * * @param string $key The name of the config value. * @param string|null $value The value to set. If null, the config entry @@ -51,59 +54,49 @@ public static function get_version() { * This will not write the config data to the config file. */ public static function set_config_data( $key, $value, $temp = false ) { - Config::setConfigData( $key, $value, $temp ); + Helper::setConfigData( $key, $value, $temp ); } /** * Get the value of a single PHPCS config key. * - * @since 0.13.0 + * @since 0.13.0 + * @deprecated 3.0.0 * * @param string $key The name of the config value. * * @return string|null */ public static function get_config_data( $key ) { - return Config::getConfigData( $key ); + return Helper::getConfigData( $key ); } /** * Get the tab width as passed to PHPCS from the command-line or the ruleset. * - * @since 0.13.0 + * @since 0.13.0 + * @deprecated 3.0.0 * * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being processed. * * @return int Tab width. Defaults to 4. */ public static function get_tab_width( File $phpcsFile ) { - $tab_width = 4; - - if ( isset( $phpcsFile->config->tabWidth ) && $phpcsFile->config->tabWidth > 0 ) { - $tab_width = $phpcsFile->config->tabWidth; - } - - return $tab_width; + return Helper::getTabWidth( $phpcsFile ); } /** * Check whether the `--ignore-annotations` option has been used. * - * @since 0.13.0 + * @since 0.13.0 + * @deprecated 3.0.0 * * @param \PHP_CodeSniffer\Files\File $phpcsFile Optional. The current file being processed. * * @return bool True if annotations should be ignored, false otherwise. */ public static function ignore_annotations( File $phpcsFile = null ) { - if ( isset( $phpcsFile, $phpcsFile->config->annotations ) ) { - return ! $phpcsFile->config->annotations; - } else { - $annotations = Config::getConfigData( 'annotations' ); - if ( isset( $annotations ) ) { - return ! $annotations; - } - } + return Helper::ignoreAnnotations( $phpcsFile ); } } From b4203e43de97bd657025aa912fd27fdd57b1a7e1 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 10 Apr 2020 02:29:58 +0200 Subject: [PATCH 2/5] PHPCSHelper::get_version(): remove call to the function This function call is no longer needed now support for PHPCS < 3.5.0 has been dropped. --- WordPress/Tests/PHP/TypeCastsUnitTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/WordPress/Tests/PHP/TypeCastsUnitTest.php b/WordPress/Tests/PHP/TypeCastsUnitTest.php index 9349f1b838..72f581446c 100644 --- a/WordPress/Tests/PHP/TypeCastsUnitTest.php +++ b/WordPress/Tests/PHP/TypeCastsUnitTest.php @@ -10,7 +10,6 @@ namespace WordPressCS\WordPress\Tests\PHP; use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; -use WordPressCS\WordPress\PHPCSHelper; /** * Unit test class for the TypeCasts sniff. @@ -44,7 +43,7 @@ public function getWarningList() { return array( 14 => 1, 15 => 1, - 16 => ( version_compare( PHPCSHelper::get_version(), '3.4.0', '<' ) === true ? 0 : 1 ), + 16 => 1, 17 => 1, 28 => 1, 29 => 1, From 52c15bd05b6f4feaecd8ea8c06e2b37cf13ac89c Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 10 Apr 2020 01:49:16 +0200 Subject: [PATCH 3/5] PHPCSHelper::get_config_data(): switch over to the PHPCSUtils version --- WordPress/Sniff.php | 4 ++-- WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php | 4 ++-- WordPress/Sniffs/WP/I18nSniff.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index aea262ef23..db1732ba2e 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -12,7 +12,7 @@ use PHP_CodeSniffer\Sniffs\Sniff as PHPCS_Sniff; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Util\Tokens; -use WordPressCS\WordPress\PHPCSHelper; +use PHPCSUtils\BackCompat\Helper; /** * Represents a PHP_CodeSniffer sniff for sniffing WordPress coding standards. @@ -1141,7 +1141,7 @@ protected function get_last_ptr_on_line( $stackPtr ) { * @since 0.14.0 */ protected function get_wp_version_from_cl() { - $cl_supported_version = trim( PHPCSHelper::get_config_data( 'minimum_supported_wp_version' ) ); + $cl_supported_version = trim( Helper::getConfigData( 'minimum_supported_wp_version' ) ); if ( ! empty( $cl_supported_version ) && filter_var( $cl_supported_version, \FILTER_VALIDATE_FLOAT ) !== false ) { diff --git a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php index 13c1437657..46b3bfd582 100644 --- a/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php +++ b/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php @@ -10,8 +10,8 @@ namespace WordPressCS\WordPress\Sniffs\NamingConventions; use WordPressCS\WordPress\AbstractFunctionParameterSniff; -use WordPressCS\WordPress\PHPCSHelper; use PHP_CodeSniffer\Util\Tokens; +use PHPCSUtils\BackCompat\Helper; /** * Verify that everything defined in the global namespace is prefixed with a theme/plugin specific prefix. @@ -265,7 +265,7 @@ public function getGroups() { public function process_token( $stackPtr ) { // Allow overruling the prefixes set in a ruleset via the command line. - $cl_prefixes = trim( PHPCSHelper::get_config_data( 'prefixes' ) ); + $cl_prefixes = trim( Helper::getConfigData( 'prefixes' ) ); if ( ! empty( $cl_prefixes ) ) { $this->prefixes = array_filter( array_map( 'trim', explode( ',', $cl_prefixes ) ) ); } diff --git a/WordPress/Sniffs/WP/I18nSniff.php b/WordPress/Sniffs/WP/I18nSniff.php index d229cb5e9a..1e4cd9c396 100644 --- a/WordPress/Sniffs/WP/I18nSniff.php +++ b/WordPress/Sniffs/WP/I18nSniff.php @@ -10,8 +10,8 @@ namespace WordPressCS\WordPress\Sniffs\WP; use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff; -use WordPressCS\WordPress\PHPCSHelper; use PHP_CodeSniffer\Util\Tokens; +use PHPCSUtils\BackCompat\Helper; /** * Makes sure WP internationalization functions are used properly. @@ -191,7 +191,7 @@ public function process_token( $stack_ptr ) { $this->text_domain_is_default = false; // Allow overruling the text_domain set in a ruleset via the command line. - $cl_text_domain = trim( PHPCSHelper::get_config_data( 'text_domain' ) ); + $cl_text_domain = trim( Helper::getConfigData( 'text_domain' ) ); if ( ! empty( $cl_text_domain ) ) { $this->text_domain = array_filter( array_map( 'trim', explode( ',', $cl_text_domain ) ) ); } From 3549ec2bb8428945ece6d9f0ed3a4118f3ac4f75 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 10 Apr 2020 01:51:38 +0200 Subject: [PATCH 4/5] PHPCSHelper::get_tab_width(): switch over to the PHPCSUtils version --- WordPress/Sniffs/Arrays/ArrayIndentationSniff.php | 4 ++-- WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php b/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php index c0b5dcf573..d388e85321 100644 --- a/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php +++ b/WordPress/Sniffs/Arrays/ArrayIndentationSniff.php @@ -10,8 +10,8 @@ namespace WordPressCS\WordPress\Sniffs\Arrays; use WordPressCS\WordPress\Sniff; -use WordPressCS\WordPress\PHPCSHelper; use PHP_CodeSniffer\Util\Tokens; +use PHPCSUtils\BackCompat\Helper; /** * Enforces WordPress array indentation for multi-line arrays. @@ -90,7 +90,7 @@ public function register() { */ public function process_token( $stackPtr ) { if ( ! isset( $this->tab_width ) ) { - $this->tab_width = PHPCSHelper::get_tab_width( $this->phpcsFile ); + $this->tab_width = Helper::getTabWidth( $this->phpcsFile ); } if ( \T_OPEN_SHORT_ARRAY === $this->tokens[ $stackPtr ]['code'] diff --git a/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php b/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php index f5e822bdc3..1d2d0e8afd 100644 --- a/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php +++ b/WordPress/Sniffs/WhiteSpace/PrecisionAlignmentSniff.php @@ -10,8 +10,8 @@ namespace WordPressCS\WordPress\Sniffs\WhiteSpace; use WordPressCS\WordPress\Sniff; -use WordPressCS\WordPress\PHPCSHelper; use PHP_CodeSniffer\Util\Tokens; +use PHPCSUtils\BackCompat\Helper; /** * Warn on line indentation ending with spaces for precision alignment. @@ -90,7 +90,7 @@ public function register() { */ public function process_token( $stackPtr ) { if ( ! isset( $this->tab_width ) ) { - $this->tab_width = PHPCSHelper::get_tab_width( $this->phpcsFile ); + $this->tab_width = Helper::getTabWidth( $this->phpcsFile ); } // Handle any custom ignore tokens received from a ruleset. From b868652e45bf4caea3719ba9b826da264187f424 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 10 Apr 2020 01:54:16 +0200 Subject: [PATCH 5/5] Remove the PHPCSHelper.php file All of the methods contained herein are now provided via PHPCSUtils and all code has been switched over to use the PHPCSUtils versions of the methods instead. --- WordPress/PHPCSHelper.php | 102 -------------------------------------- 1 file changed, 102 deletions(-) delete mode 100644 WordPress/PHPCSHelper.php diff --git a/WordPress/PHPCSHelper.php b/WordPress/PHPCSHelper.php deleted file mode 100644 index 9260e55df1..0000000000 --- a/WordPress/PHPCSHelper.php +++ /dev/null @@ -1,102 +0,0 @@ -