From 5585804d27ed7a6caacede1bdd03d0abe01a20f3 Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Fri, 6 Jul 2018 20:17:10 +0100 Subject: [PATCH 01/19] Deprecated the VIP FileSystemWritesDisallow Sniff and the Admin Bar Removal Sniff --- WordPress-VIP/ruleset.xml | 10 ++++ WordPress/Sniffs/VIP/AdminBarRemovalSniff.php | 47 +++++++++++++++++-- .../VIP/FileSystemWritesDisallowSniff.php | 47 +++++++++++++++++++ .../Tests/VIP/AdminBarRemovalUnitTest.php | 21 ++++++++- .../VIP/FileSystemWritesDisallowUnitTest.php | 4 +- 5 files changed, 123 insertions(+), 6 deletions(-) diff --git a/WordPress-VIP/ruleset.xml b/WordPress-VIP/ruleset.xml index 9abc37f7e4..cb6e95d45e 100644 --- a/WordPress-VIP/ruleset.xml +++ b/WordPress-VIP/ruleset.xml @@ -131,6 +131,11 @@ ############################################################################# --> + + + 0 + + 0 @@ -211,6 +216,11 @@ 0 + + + 0 + + 0 diff --git a/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php b/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php index 1aa69d770a..3f473bb3c4 100644 --- a/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php +++ b/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php @@ -24,9 +24,32 @@ * - Added the $remove_only property. * - Now also sniffs for manipulation of the admin bar visibility through CSS. * @since 0.13.0 Class name changed: this class is now namespaced. + * + * @deprecated 1.0.0 This sniff has been deprecated. + * This file remains for now to prevent BC breaks. */ class AdminBarRemovalSniff extends AbstractFunctionParameterSniff { + /** + * If true, an error will be thrown; otherwise a warning. + * + * @var bool + */ + public $error = true; + + /** + * Keep track of whether the warnings have been thrown to prevent + * the messages being thrown for every token triggering the sniff. + * + * @since 1.0.0 + * + * @var array + */ + private $thrown = array( + 'DeprecatedSniff' => false, + 'FoundPropertyForDeprecatedSniff' => false, + ); + /** * A list of tokenizers this sniff supports. * @@ -71,15 +94,15 @@ class AdminBarRemovalSniff extends AbstractFunctionParameterSniff { */ protected $target_css_properties = array( 'visibility' => array( - 'type' => '!=', + 'type' => '!=', 'value' => 'hidden', ), 'display' => array( - 'type' => '!=', + 'type' => '!=', 'value' => 'none', ), 'opacity' => array( - 'type' => '>', + 'type' => '>', 'value' => 0.3, ), ); @@ -169,6 +192,8 @@ public function register() { /** * Processes this test, when one of its tokens is encountered. * + * @since 1.0.0 Adjusted to allow for throwing the deprecation notices. + * * @param int $stackPtr The position of the current token in the stack. * * @return int|void Integer stack pointer to skip forward or void to continue @@ -176,6 +201,22 @@ public function register() { */ public function process_token( $stackPtr ) { + if ( false === $this->thrown['DeprecatedSniff'] ) { + $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( + 'The "WordPress.VIP.AdminBarRemovalSniff" sniff has been deprecated. Please update your custom ruleset.', + 0, + 'DeprecatedSniff' + ); + } + + if ( false === $this->thrown['FoundPropertyForDeprecatedSniff'] ) { + $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( + 'The "WordPress.VIP.AdminBarRemovalSniff" sniff has been deprecated. Please update your custom ruleset.', + 0, + 'FoundPropertyForDeprecatedSniff' + ); + } + $file_name = $this->phpcsFile->getFileName(); $file_extension = substr( strrchr( $file_name, '.' ), 1 ); diff --git a/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php b/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php index 0f90ac760e..59d9c658df 100644 --- a/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php +++ b/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php @@ -22,6 +22,9 @@ * @since 0.11.0 Extends the WordPress_AbstractFunctionRestrictionsSniff instead of the * Generic_Sniffs_PHP_ForbiddenFunctionsSniff. * @since 0.13.0 Class name changed: this class is now namespaced. + * + * @deprecated 1.0.0 This sniff has been deprecated. + * This file remains for now to prevent BC breaks. */ class FileSystemWritesDisallowSniff extends AbstractFunctionRestrictionsSniff { @@ -32,6 +35,19 @@ class FileSystemWritesDisallowSniff extends AbstractFunctionRestrictionsSniff { */ public $error = true; + /** + * Keep track of whether the warnings have been thrown to prevent + * the messages being thrown for every token triggering the sniff. + * + * @since 1.0.0 + * + * @var array + */ + private $thrown = array( + 'DeprecatedSniff' => false, + 'FoundPropertyForDeprecatedSniff' => false, + ); + /** * Groups of functions to restrict. * @@ -102,4 +118,35 @@ public function getGroups() { return $groups; } + /** + * This sniff is active, but it's deprecated, handle the deprecation notices + * + * @since 1.0.0 Added to allow for throwing the deprecation notices. + * + * @param int $stackPtr The position of the current token in the stack. + * + * @return void|int + */ + public function process_token( $stackPtr ) { + if ( false === $this->thrown['DeprecatedSniff'] ) { + $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( + 'The "WordPress.VIP.FileSystemWritesDisallowSniff" sniff has been deprecated. Please update your custom ruleset.', + 0, + 'DeprecatedSniff' + ); + } + + if ( ! empty( $this->exclude ) + && false === $this->thrown['FoundPropertyForDeprecatedSniff'] + ) { + $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( + 'The "WordPress.VIP.FileSystemWritesDisallowSniff" sniff has been deprecated. Please update your custom ruleset.', + 0, + 'FoundPropertyForDeprecatedSniff' + ); + } + + return parent::process_token( $stackPtr ); + } + } diff --git a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php b/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php index deecfb25b1..71b37db2dd 100644 --- a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php +++ b/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php @@ -85,10 +85,27 @@ public function getErrorList( $testFile = '' ) { /** * Returns the lines where warnings should occur. * + * @param string $testFile The name of the file being tested. * @return array => */ - public function getWarningList() { - return array(); + public function getWarningList( $testFile = '' ) { + switch ( $testFile ) { + case 'AdminBarRemovalUnitTest.css': + return array( + 1 => 2, + ); + + case 'AdminBarRemovalUnitTest.css': + return array( + 1 => 1, + ); + + default: + return array(); + } + return array( + 1 => 2 + ); } } diff --git a/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php b/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php index a55561c53f..16c6731249 100644 --- a/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php +++ b/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php @@ -60,7 +60,9 @@ public function getErrorList() { * @return array => */ public function getWarningList() { - return array(); + return array( + 1 => 1, + ); } } From 4ae86918708fbcf8e7cc37efaa74df4565d2ba6f Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Fri, 6 Jul 2018 21:22:14 +0100 Subject: [PATCH 02/19] deprecate the VIP Order By Rand sniff --- WordPress-VIP/ruleset.xml | 5 ++ WordPress/Sniffs/VIP/OrderByRandSniff.php | 54 +++++++++++++++++++++ WordPress/Tests/VIP/OrderByRandUnitTest.php | 4 +- 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/WordPress-VIP/ruleset.xml b/WordPress-VIP/ruleset.xml index cb6e95d45e..1dc3f776d6 100644 --- a/WordPress-VIP/ruleset.xml +++ b/WordPress-VIP/ruleset.xml @@ -220,6 +220,11 @@ 0 + + + + 0 + diff --git a/WordPress/Sniffs/VIP/OrderByRandSniff.php b/WordPress/Sniffs/VIP/OrderByRandSniff.php index bfcf46cde4..4c915c89cd 100644 --- a/WordPress/Sniffs/VIP/OrderByRandSniff.php +++ b/WordPress/Sniffs/VIP/OrderByRandSniff.php @@ -20,9 +20,32 @@ * * @since 0.9.0 * @since 0.13.0 Class name changed: this class is now namespaced. + * + * @deprecated 1.0.0 This sniff has been deprecated. + * This file remains for now to prevent BC breaks. */ class OrderByRandSniff extends AbstractArrayAssignmentRestrictionsSniff { + /** + * If true, an error will be thrown; otherwise a warning. + * + * @var bool + */ + public $error = true; + + /** + * Keep track of whether the warnings have been thrown to prevent + * the messages being thrown for every token triggering the sniff. + * + * @since 1.0.0 + * + * @var array + */ + private $thrown = array( + 'DeprecatedSniff' => false, + 'FoundPropertyForDeprecatedSniff' => false, + ); + /** * Groups of variables to restrict. * @@ -39,6 +62,37 @@ public function getGroups() { ); } + /** + * This sniff is active, but it's deprecated, handle the deprecation notices + * + * @since 1.0.0 Added to allow for throwing the deprecation notices. + * + * @param int $stackPtr The position of the current token in the stack. + * + * @return void|int + */ + public function process_token( $stackPtr ) { + if ( false === $this->thrown['DeprecatedSniff'] ) { + $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( + 'The "WordPress.VIP.OrderByRandSniff" sniff has been deprecated. Please update your custom ruleset.', + 0, + 'DeprecatedSniff' + ); + } + + if ( ! empty( $this->exclude ) + && false === $this->thrown['FoundPropertyForDeprecatedSniff'] + ) { + $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( + 'The "WordPress.VIP.OrderByRandSniff" sniff has been deprecated. Please update your custom ruleset.', + 0, + 'FoundPropertyForDeprecatedSniff' + ); + } + + return parent::process_token( $stackPtr ); + } + /** * Callback to process each confirmed key, to check value * This must be extended to add the logic to check assignment value diff --git a/WordPress/Tests/VIP/OrderByRandUnitTest.php b/WordPress/Tests/VIP/OrderByRandUnitTest.php index db32349105..617a24992a 100644 --- a/WordPress/Tests/VIP/OrderByRandUnitTest.php +++ b/WordPress/Tests/VIP/OrderByRandUnitTest.php @@ -42,7 +42,9 @@ public function getErrorList() { * @return array => */ public function getWarningList() { - return array(); + return array( + 1 => 1 + ); } } From ea7493bf89d5ee80f5aa7cc3c52dfd7616ea90a4 Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Fri, 6 Jul 2018 21:35:13 +0100 Subject: [PATCH 03/19] Deprecated the VIP RestrictedFunctions Sniff --- WordPress-VIP/ruleset.xml | 5 ++ .../Sniffs/VIP/RestrictedFunctionsSniff.php | 54 +++++++++++++++++++ .../Tests/VIP/RestrictedFunctionsUnitTest.php | 1 + 3 files changed, 60 insertions(+) diff --git a/WordPress-VIP/ruleset.xml b/WordPress-VIP/ruleset.xml index 1dc3f776d6..ce65c78e7e 100644 --- a/WordPress-VIP/ruleset.xml +++ b/WordPress-VIP/ruleset.xml @@ -225,6 +225,11 @@ 0 + + + + 0 + diff --git a/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php b/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php index de783903e4..cb98bb4319 100644 --- a/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php +++ b/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php @@ -29,9 +29,32 @@ * WordPress_Sniffs_WP_AlternativeFunctionsSniff. * The check for `eval()` now defers to the upstream Squiz.PHP.Eval sniff. * @since 0.13.0 Class name changed: this class is now namespaced. + * + * @deprecated 1.0.0 This sniff has been deprecated. + * This file remains for now to prevent BC breaks. */ class RestrictedFunctionsSniff extends AbstractFunctionRestrictionsSniff { + /** + * If true, an error will be thrown; otherwise a warning. + * + * @var bool + */ + public $error = true; + + /** + * Keep track of whether the warnings have been thrown to prevent + * the messages being thrown for every token triggering the sniff. + * + * @since 1.0.0 + * + * @var array + */ + private $thrown = array( + 'DeprecatedSniff' => false, + 'FoundPropertyForDeprecatedSniff' => false, + ); + /** * Groups of functions to restrict. * @@ -225,4 +248,35 @@ public function getGroups() { ); } + /** + * This sniff is active, but it's deprecated, handle the deprecation notices + * + * @since 1.0.0 Added to allow for throwing the deprecation notices. + * + * @param int $stackPtr The position of the current token in the stack. + * + * @return void|int + */ + public function process_token( $stackPtr ) { + if ( false === $this->thrown['DeprecatedSniff'] ) { + $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( + 'The "WordPress.VIP.RestrictedFunctionsSniff" sniff has been deprecated. Please update your custom ruleset.', + 0, + 'DeprecatedSniff' + ); + } + + if ( ! empty( $this->exclude ) + && false === $this->thrown['FoundPropertyForDeprecatedSniff'] + ) { + $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( + 'The "WordPress.VIP.RestrictedFunctionsSniff" sniff has been deprecated. Please update your custom ruleset.', + 0, + 'FoundPropertyForDeprecatedSniff' + ); + } + + return parent::process_token( $stackPtr ); + } + } diff --git a/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php b/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php index 12d49961ef..96499c3c12 100644 --- a/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php +++ b/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php @@ -63,6 +63,7 @@ public function getErrorList() { */ public function getWarningList() { return array( + 1 => 1, 5 => 1, 7 => 1, 9 => 1, From df07c460d65be627c6fb2e61445ec930ce7532b9 Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Fri, 6 Jul 2018 21:47:19 +0100 Subject: [PATCH 04/19] deprecated the VIP sniff RestrictedVariables --- WordPress-VIP/ruleset.xml | 5 ++ .../Sniffs/VIP/RestrictedVariablesSniff.php | 54 +++++++++++++++++++ .../Tests/VIP/RestrictedVariablesUnitTest.php | 1 + 3 files changed, 60 insertions(+) diff --git a/WordPress-VIP/ruleset.xml b/WordPress-VIP/ruleset.xml index ce65c78e7e..cb5a828885 100644 --- a/WordPress-VIP/ruleset.xml +++ b/WordPress-VIP/ruleset.xml @@ -231,6 +231,11 @@ 0 + + + 0 + + 0 diff --git a/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php b/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php index f5cc06e643..81ddb3d587 100644 --- a/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php +++ b/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php @@ -20,9 +20,32 @@ * * @since 0.3.0 * @since 0.13.0 Class name changed: this class is now namespaced. + * + * @deprecated 1.0.0 This sniff has been deprecated. + * This file remains for now to prevent BC breaks. */ class RestrictedVariablesSniff extends AbstractVariableRestrictionsSniff { + /** + * If true, an error will be thrown; otherwise a warning. + * + * @var bool + */ + public $error = true; + + /** + * Keep track of whether the warnings have been thrown to prevent + * the messages being thrown for every token triggering the sniff. + * + * @since 1.0.0 + * + * @var array + */ + private $thrown = array( + 'DeprecatedSniff' => false, + 'FoundPropertyForDeprecatedSniff' => false, + ); + /** * Groups of variables to restrict. * @@ -65,4 +88,35 @@ public function getGroups() { ); } + /** + * This sniff is active, but it's deprecated, handle the deprecation notices + * + * @since 1.0.0 Added to allow for throwing the deprecation notices. + * + * @param int $stackPtr The position of the current token in the stack. + * + * @return void|int + */ + public function process_token( $stackPtr ) { + if ( false === $this->thrown['DeprecatedSniff'] ) { + $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( + 'The "WordPress.VIP.RestrictedVariablesSniff" sniff has been deprecated. Please update your custom ruleset.', + 0, + 'DeprecatedSniff' + ); + } + + if ( ! empty( $this->exclude ) + && false === $this->thrown['FoundPropertyForDeprecatedSniff'] + ) { + $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( + 'The "WordPress.VIP.RestrictedVariablesSniff" sniff has been deprecated. Please update your custom ruleset.', + 0, + 'FoundPropertyForDeprecatedSniff' + ); + } + + return parent::process_token( $stackPtr ); + } + } diff --git a/WordPress/Tests/VIP/RestrictedVariablesUnitTest.php b/WordPress/Tests/VIP/RestrictedVariablesUnitTest.php index 5b5a0527ab..9b89379be6 100644 --- a/WordPress/Tests/VIP/RestrictedVariablesUnitTest.php +++ b/WordPress/Tests/VIP/RestrictedVariablesUnitTest.php @@ -43,6 +43,7 @@ public function getErrorList() { */ public function getWarningList() { return array( + 1 => 1, 13 => 1, 14 => 1, 17 => 1, From 907fd882509af2ae7e481a894156f757ad639f70 Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Fri, 6 Jul 2018 21:50:12 +0100 Subject: [PATCH 05/19] deprecates the VIP SessionFunctionsUsage sniff --- WordPress-VIP/ruleset.xml | 5 ++ .../Sniffs/VIP/SessionFunctionsUsageSniff.php | 55 +++++++++++++++++++ .../VIP/SessionFunctionsUsageUnitTest.php | 4 +- 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/WordPress-VIP/ruleset.xml b/WordPress-VIP/ruleset.xml index cb5a828885..145cc901ce 100644 --- a/WordPress-VIP/ruleset.xml +++ b/WordPress-VIP/ruleset.xml @@ -236,6 +236,11 @@ 0 + + + 0 + + 0 diff --git a/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php b/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php index 3eaf1ff0e4..0cc777cd8f 100644 --- a/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php +++ b/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php @@ -22,9 +22,32 @@ * @since 0.11.0 Extends the WordPress_AbstractFunctionRestrictionsSniff instead of the * Generic_Sniffs_PHP_ForbiddenFunctionsSniff. * @since 0.13.0 Class name changed: this class is now namespaced. + * + * @deprecated 1.0.0 This sniff has been deprecated. + * This file remains for now to prevent BC breaks. */ class SessionFunctionsUsageSniff extends AbstractFunctionRestrictionsSniff { + /** + * If true, an error will be thrown; otherwise a warning. + * + * @var bool + */ + public $error = true; + + /** + * Keep track of whether the warnings have been thrown to prevent + * the messages being thrown for every token triggering the sniff. + * + * @since 1.0.0 + * + * @var array + */ + private $thrown = array( + 'DeprecatedSniff' => false, + 'FoundPropertyForDeprecatedSniff' => false, + ); + /** * Groups of functions to restrict. * @@ -75,4 +98,36 @@ public function getGroups() { ); } + + /** + * This sniff is active, but it's deprecated, handle the deprecation notices + * + * @since 1.0.0 Added to allow for throwing the deprecation notices. + * + * @param int $stackPtr The position of the current token in the stack. + * + * @return void|int + */ + public function process_token( $stackPtr ) { + if ( false === $this->thrown['DeprecatedSniff'] ) { + $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( + 'The "WordPress.VIP.SessionFunctionsUsageSniff" sniff has been deprecated. Please update your custom ruleset.', + 0, + 'DeprecatedSniff' + ); + } + + if ( ! empty( $this->exclude ) + && false === $this->thrown['FoundPropertyForDeprecatedSniff'] + ) { + $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( + 'The "WordPress.VIP.SessionFunctionsUsageSniff" sniff has been deprecated. Please update your custom ruleset.', + 0, + 'FoundPropertyForDeprecatedSniff' + ); + } + + return parent::process_token( $stackPtr ); + } + } diff --git a/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.php b/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.php index 4fdbf76202..f9baaa552c 100644 --- a/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.php +++ b/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.php @@ -36,7 +36,9 @@ public function getErrorList() { * @return array => */ public function getWarningList() { - return array(); + return array( + 1 => 1, + ); } } From d1272dda6c5480e61dc42eaf8968e57285a007df Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Fri, 6 Jul 2018 21:58:48 +0100 Subject: [PATCH 06/19] Deprecated the VIP SessionVariableUsageSniff sniff --- WordPress-VIP/ruleset.xml | 5 +++ .../Sniffs/VIP/SessionVariableUsageSniff.php | 41 +++++++++++++++++++ .../VIP/SessionVariableUsageUnitTest.php | 4 +- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/WordPress-VIP/ruleset.xml b/WordPress-VIP/ruleset.xml index 145cc901ce..a8b28f137d 100644 --- a/WordPress-VIP/ruleset.xml +++ b/WordPress-VIP/ruleset.xml @@ -241,6 +241,11 @@ 0 + + + 0 + + 0 diff --git a/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php b/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php index 9c2f695910..42e22f5b5f 100644 --- a/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php +++ b/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php @@ -24,9 +24,32 @@ * which it didn't use. * @since 0.12.0 This class now extends WordPress_Sniff. * @since 0.13.0 Class name changed: this class is now namespaced. + * + * @deprecated 1.0.0 This sniff has been deprecated. + * This file remains for now to prevent BC breaks. */ class SessionVariableUsageSniff extends Sniff { + /** + * If true, an error will be thrown; otherwise a warning. + * + * @var bool + */ + public $error = true; + + /** + * Keep track of whether the warnings have been thrown to prevent + * the messages being thrown for every token triggering the sniff. + * + * @since 1.0.0 + * + * @var array + */ + private $thrown = array( + 'DeprecatedSniff' => false, + 'FoundPropertyForDeprecatedSniff' => false, + ); + /** * Returns an array of tokens this test wants to listen for. * @@ -46,6 +69,24 @@ public function register() { * @return void */ public function process_token( $stackPtr ) { + if ( false === $this->thrown['DeprecatedSniff'] ) { + $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( + 'The "WordPress.VIP.SessionVariableUsageSniff" sniff has been deprecated. Please update your custom ruleset.', + 0, + 'DeprecatedSniff' + ); + } + + if ( ! empty( $this->exclude ) + && false === $this->thrown['FoundPropertyForDeprecatedSniff'] + ) { + $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( + 'The "WordPress.VIP.SessionVariableUsageSniff" sniff has been deprecated. Please update your custom ruleset.', + 0, + 'FoundPropertyForDeprecatedSniff' + ); + } + if ( '$_SESSION' === $this->tokens[ $stackPtr ]['content'] ) { $this->phpcsFile->addError( 'Usage of $_SESSION variable is prohibited.', diff --git a/WordPress/Tests/VIP/SessionVariableUsageUnitTest.php b/WordPress/Tests/VIP/SessionVariableUsageUnitTest.php index ccc1e2c79d..3813f32efd 100644 --- a/WordPress/Tests/VIP/SessionVariableUsageUnitTest.php +++ b/WordPress/Tests/VIP/SessionVariableUsageUnitTest.php @@ -39,7 +39,9 @@ public function getErrorList() { * @return array => */ public function getWarningList() { - return array(); + return array( + 1 => 1, + ); } } From 7106b30c620f10f7c6a8bc9d600c7e886fbcefbb Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Fri, 6 Jul 2018 22:01:57 +0100 Subject: [PATCH 07/19] Deprecated the VIP sniff SuperGlobalInputUsageSniff --- WordPress-VIP/ruleset.xml | 5 +++ .../Sniffs/VIP/SuperGlobalInputUsageSniff.php | 41 +++++++++++++++++++ .../VIP/SuperGlobalInputUsageUnitTest.php | 1 + 3 files changed, 47 insertions(+) diff --git a/WordPress-VIP/ruleset.xml b/WordPress-VIP/ruleset.xml index a8b28f137d..cb310cf756 100644 --- a/WordPress-VIP/ruleset.xml +++ b/WordPress-VIP/ruleset.xml @@ -246,6 +246,11 @@ 0 + + + 0 + + 0 diff --git a/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php b/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php index e540717379..e6516e51bd 100644 --- a/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php +++ b/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php @@ -21,9 +21,32 @@ * @since 0.3.0 * @since 0.4.0 This class now extends WordPress_Sniff. * @since 0.13.0 Class name changed: this class is now namespaced. + * + * @deprecated 1.0.0 This sniff has been deprecated. + * This file remains for now to prevent BC breaks. */ class SuperGlobalInputUsageSniff extends Sniff { + /** + * If true, an error will be thrown; otherwise a warning. + * + * @var bool + */ + public $error = true; + + /** + * Keep track of whether the warnings have been thrown to prevent + * the messages being thrown for every token triggering the sniff. + * + * @since 1.0.0 + * + * @var array + */ + private $thrown = array( + 'DeprecatedSniff' => false, + 'FoundPropertyForDeprecatedSniff' => false, + ); + /** * Returns an array of tokens this test wants to listen for. * @@ -43,6 +66,24 @@ public function register() { * @return void */ public function process_token( $stackPtr ) { + if ( false === $this->thrown['DeprecatedSniff'] ) { + $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( + 'The "WordPress.VIP.SessionVariableUsageSniff" sniff has been deprecated. Please update your custom ruleset.', + 0, + 'DeprecatedSniff' + ); + } + + if ( ! empty( $this->exclude ) + && false === $this->thrown['FoundPropertyForDeprecatedSniff'] + ) { + $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( + 'The "WordPress.VIP.SessionVariableUsageSniff" sniff has been deprecated. Please update your custom ruleset.', + 0, + 'FoundPropertyForDeprecatedSniff' + ); + } + // Check for global input variable. if ( ! in_array( $this->tokens[ $stackPtr ]['content'], $this->input_superglobals, true ) ) { return; diff --git a/WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.php b/WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.php index 59280601c4..3af0f6226d 100644 --- a/WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.php +++ b/WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.php @@ -37,6 +37,7 @@ public function getErrorList() { */ public function getWarningList() { return array( + 1 => 1, 3 => 1, 13 => 1, 15 => 1, From 42d1ef0634a23064ec262a182289c5023a1a4cdd Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Sat, 7 Jul 2018 15:17:03 +0100 Subject: [PATCH 08/19] resolve PHPCBF formatting issues by adding commars and removing trailing whitespace --- WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php | 2 +- WordPress/Sniffs/VIP/OrderByRandSniff.php | 2 +- WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php | 2 +- WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php | 2 +- WordPress/Sniffs/VIP/SessionVariableUsageSniff.php | 2 +- WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php | 2 +- WordPress/Tests/VIP/AdminBarRemovalUnitTest.php | 4 ++-- WordPress/Tests/VIP/OrderByRandUnitTest.php | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php b/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php index 59d9c658df..e59882ac3a 100644 --- a/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php +++ b/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php @@ -22,7 +22,7 @@ * @since 0.11.0 Extends the WordPress_AbstractFunctionRestrictionsSniff instead of the * Generic_Sniffs_PHP_ForbiddenFunctionsSniff. * @since 0.13.0 Class name changed: this class is now namespaced. - * + * * @deprecated 1.0.0 This sniff has been deprecated. * This file remains for now to prevent BC breaks. */ diff --git a/WordPress/Sniffs/VIP/OrderByRandSniff.php b/WordPress/Sniffs/VIP/OrderByRandSniff.php index 4c915c89cd..d4fecb1b1b 100644 --- a/WordPress/Sniffs/VIP/OrderByRandSniff.php +++ b/WordPress/Sniffs/VIP/OrderByRandSniff.php @@ -20,7 +20,7 @@ * * @since 0.9.0 * @since 0.13.0 Class name changed: this class is now namespaced. - * + * * @deprecated 1.0.0 This sniff has been deprecated. * This file remains for now to prevent BC breaks. */ diff --git a/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php b/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php index cb98bb4319..ee4bbedcb5 100644 --- a/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php +++ b/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php @@ -29,7 +29,7 @@ * WordPress_Sniffs_WP_AlternativeFunctionsSniff. * The check for `eval()` now defers to the upstream Squiz.PHP.Eval sniff. * @since 0.13.0 Class name changed: this class is now namespaced. - * + * * @deprecated 1.0.0 This sniff has been deprecated. * This file remains for now to prevent BC breaks. */ diff --git a/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php b/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php index 0cc777cd8f..eb74493ac9 100644 --- a/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php +++ b/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php @@ -98,7 +98,7 @@ public function getGroups() { ); } - + /** * This sniff is active, but it's deprecated, handle the deprecation notices * diff --git a/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php b/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php index 42e22f5b5f..468d64c150 100644 --- a/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php +++ b/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php @@ -86,7 +86,7 @@ public function process_token( $stackPtr ) { 'FoundPropertyForDeprecatedSniff' ); } - + if ( '$_SESSION' === $this->tokens[ $stackPtr ]['content'] ) { $this->phpcsFile->addError( 'Usage of $_SESSION variable is prohibited.', diff --git a/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php b/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php index e6516e51bd..bb1f5b890d 100644 --- a/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php +++ b/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php @@ -83,7 +83,7 @@ public function process_token( $stackPtr ) { 'FoundPropertyForDeprecatedSniff' ); } - + // Check for global input variable. if ( ! in_array( $this->tokens[ $stackPtr ]['content'], $this->input_superglobals, true ) ) { return; diff --git a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php b/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php index 71b37db2dd..7f6acdf059 100644 --- a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php +++ b/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php @@ -97,14 +97,14 @@ public function getWarningList( $testFile = '' ) { case 'AdminBarRemovalUnitTest.css': return array( - 1 => 1, + 1 => 1, ); default: return array(); } return array( - 1 => 2 + 1 => 2, ); } diff --git a/WordPress/Tests/VIP/OrderByRandUnitTest.php b/WordPress/Tests/VIP/OrderByRandUnitTest.php index 617a24992a..4652e67839 100644 --- a/WordPress/Tests/VIP/OrderByRandUnitTest.php +++ b/WordPress/Tests/VIP/OrderByRandUnitTest.php @@ -43,7 +43,7 @@ public function getErrorList() { */ public function getWarningList() { return array( - 1 => 1 + 1 => 1, ); } From cafaf2a00980824eb81fdf8499f786d3b8bccc9a Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Sat, 7 Jul 2018 17:19:40 +0100 Subject: [PATCH 09/19] update the VIP rulesets description to indicate that it's deprecated, and fix deprecation silencers --- WordPress-VIP/ruleset.xml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/WordPress-VIP/ruleset.xml b/WordPress-VIP/ruleset.xml index cb310cf756..cd19323859 100644 --- a/WordPress-VIP/ruleset.xml +++ b/WordPress-VIP/ruleset.xml @@ -1,6 +1,6 @@ - WordPress.com VIP Coding Standards + Deprecated WordPress.com VIP Coding Standards, use the official VIP coding standards instead ./../WordPress/PHPCSAliases.php @@ -132,7 +132,7 @@ --> - + 0 @@ -222,32 +222,32 @@ - + 0 - + 0 - + 0 - + 0 - + 0 - + 0 From 95581c0ede59021e78ad076c98f27d66995394db Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Sun, 8 Jul 2018 15:42:00 +0100 Subject: [PATCH 10/19] Fixes for the VIP Sniff deprecations based on Juliettes review --- WordPress-VIP/ruleset.xml | 5 +++-- WordPress/Sniffs/VIP/AdminBarRemovalSniff.php | 22 +++++++------------ WordPress/Sniffs/VIP/CronIntervalSniff.php | 2 +- .../Sniffs/VIP/DirectDatabaseQuerySniff.php | 2 +- .../VIP/FileSystemWritesDisallowSniff.php | 8 +++---- WordPress/Sniffs/VIP/OrderByRandSniff.php | 6 ++--- WordPress/Sniffs/VIP/PluginMenuSlugSniff.php | 2 +- .../Sniffs/VIP/RestrictedFunctionsSniff.php | 13 +++-------- .../Sniffs/VIP/RestrictedVariablesSniff.php | 13 +++-------- .../Sniffs/VIP/SessionFunctionsUsageSniff.php | 13 +++-------- .../Sniffs/VIP/SessionVariableUsageSniff.php | 22 ++----------------- WordPress/Sniffs/VIP/SlowDBQuerySniff.php | 2 +- .../Sniffs/VIP/SuperGlobalInputUsageSniff.php | 22 ++----------------- WordPress/Sniffs/VIP/TimezoneChangeSniff.php | 2 +- .../VIP/ValidatedSanitizedInputSniff.php | 2 +- .../Tests/VIP/AdminBarRemovalUnitTest.php | 10 +++------ 16 files changed, 40 insertions(+), 106 deletions(-) diff --git a/WordPress-VIP/ruleset.xml b/WordPress-VIP/ruleset.xml index cd19323859..1b41f03446 100644 --- a/WordPress-VIP/ruleset.xml +++ b/WordPress-VIP/ruleset.xml @@ -1,5 +1,6 @@ + Deprecated WordPress.com VIP Coding Standards, use the official VIP coding standards instead ./../WordPress/PHPCSAliases.php @@ -220,12 +221,12 @@ 0 - + 0 - + 0 diff --git a/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php b/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php index 3f473bb3c4..c6717c277e 100644 --- a/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php +++ b/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php @@ -30,13 +30,6 @@ */ class AdminBarRemovalSniff extends AbstractFunctionParameterSniff { - /** - * If true, an error will be thrown; otherwise a warning. - * - * @var bool - */ - public $error = true; - /** * Keep track of whether the warnings have been thrown to prevent * the messages being thrown for every token triggering the sniff. @@ -94,15 +87,15 @@ class AdminBarRemovalSniff extends AbstractFunctionParameterSniff { */ protected $target_css_properties = array( 'visibility' => array( - 'type' => '!=', + 'type' => '!=', 'value' => 'hidden', ), 'display' => array( - 'type' => '!=', + 'type' => '!=', 'value' => 'none', ), 'opacity' => array( - 'type' => '>', + 'type' => '>', 'value' => 0.3, ), ); @@ -190,7 +183,7 @@ public function register() { } /** - * Processes this test, when one of its tokens is encountered. + * Process the token and handle the deprecation notices. * * @since 1.0.0 Adjusted to allow for throwing the deprecation notices. * @@ -203,15 +196,16 @@ public function process_token( $stackPtr ) { if ( false === $this->thrown['DeprecatedSniff'] ) { $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.AdminBarRemovalSniff" sniff has been deprecated. Please update your custom ruleset.', + 'The "WordPress.VIP.AdminBarRemoval" sniff has been deprecated. Please update your custom ruleset.', 0, 'DeprecatedSniff' ); } - if ( false === $this->thrown['FoundPropertyForDeprecatedSniff'] ) { + if ( ( $this->remove_only === false ) && + false === $this->thrown['FoundPropertyForDeprecatedSniff'] ) { $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.AdminBarRemovalSniff" sniff has been deprecated. Please update your custom ruleset.', + 'The "WordPress.VIP.AdminBarRemoval" sniff has been deprecated. Please update your custom ruleset.', 0, 'FoundPropertyForDeprecatedSniff' ); diff --git a/WordPress/Sniffs/VIP/CronIntervalSniff.php b/WordPress/Sniffs/VIP/CronIntervalSniff.php index e989d7f461..a792a73da9 100644 --- a/WordPress/Sniffs/VIP/CronIntervalSniff.php +++ b/WordPress/Sniffs/VIP/CronIntervalSniff.php @@ -56,7 +56,7 @@ class CronIntervalSniff extends \WordPress\Sniffs\WP\CronIntervalSniff { ); /** - * Don't use. + * Process the token and handle the deprecation notices. * * @deprecated 1.0.0 * diff --git a/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php b/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php index 98d75322fa..fb834ecdbf 100644 --- a/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php +++ b/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php @@ -44,7 +44,7 @@ class DirectDatabaseQuerySniff extends \WordPress\Sniffs\DB\DirectDatabaseQueryS ); /** - * Don't use. + * Process the token and handle the deprecation notices. * * @deprecated 1.0.0 * diff --git a/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php b/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php index e59882ac3a..991c4221b9 100644 --- a/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php +++ b/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php @@ -119,7 +119,7 @@ public function getGroups() { } /** - * This sniff is active, but it's deprecated, handle the deprecation notices + * Process the token and handle the deprecation notices. * * @since 1.0.0 Added to allow for throwing the deprecation notices. * @@ -130,17 +130,17 @@ public function getGroups() { public function process_token( $stackPtr ) { if ( false === $this->thrown['DeprecatedSniff'] ) { $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.FileSystemWritesDisallowSniff" sniff has been deprecated. Please update your custom ruleset.', + 'The "WordPress.VIP.FileSystemWritesDisallow" sniff has been deprecated. Please update your custom ruleset.', 0, 'DeprecatedSniff' ); } - if ( ! empty( $this->exclude ) + if ( ( ! empty( $this->exclude ) || !empty( $this->error ) ) && false === $this->thrown['FoundPropertyForDeprecatedSniff'] ) { $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.FileSystemWritesDisallowSniff" sniff has been deprecated. Please update your custom ruleset.', + 'The "WordPress.VIP.FileSystemWritesDisallow" sniff has been deprecated. Please update your custom ruleset.', 0, 'FoundPropertyForDeprecatedSniff' ); diff --git a/WordPress/Sniffs/VIP/OrderByRandSniff.php b/WordPress/Sniffs/VIP/OrderByRandSniff.php index d4fecb1b1b..967bedce68 100644 --- a/WordPress/Sniffs/VIP/OrderByRandSniff.php +++ b/WordPress/Sniffs/VIP/OrderByRandSniff.php @@ -63,7 +63,7 @@ public function getGroups() { } /** - * This sniff is active, but it's deprecated, handle the deprecation notices + * Process the token and handle the deprecation notices. * * @since 1.0.0 Added to allow for throwing the deprecation notices. * @@ -74,7 +74,7 @@ public function getGroups() { public function process_token( $stackPtr ) { if ( false === $this->thrown['DeprecatedSniff'] ) { $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.OrderByRandSniff" sniff has been deprecated. Please update your custom ruleset.', + 'The "WordPress.VIP.OrderByRand" sniff has been deprecated. Please update your custom ruleset.', 0, 'DeprecatedSniff' ); @@ -84,7 +84,7 @@ public function process_token( $stackPtr ) { && false === $this->thrown['FoundPropertyForDeprecatedSniff'] ) { $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.OrderByRandSniff" sniff has been deprecated. Please update your custom ruleset.', + 'The "WordPress.VIP.OrderByRand" sniff has been deprecated. Please update your custom ruleset.', 0, 'FoundPropertyForDeprecatedSniff' ); diff --git a/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php b/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php index 8b73e46788..522c0d640d 100644 --- a/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php +++ b/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php @@ -40,7 +40,7 @@ class PluginMenuSlugSniff extends \WordPress\Sniffs\Security\PluginMenuSlugSniff ); /** - * Don't use. + * Process the token and handle the deprecation notices. * * @deprecated 1.0.0 * diff --git a/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php b/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php index ee4bbedcb5..3e7726621b 100644 --- a/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php +++ b/WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php @@ -35,13 +35,6 @@ */ class RestrictedFunctionsSniff extends AbstractFunctionRestrictionsSniff { - /** - * If true, an error will be thrown; otherwise a warning. - * - * @var bool - */ - public $error = true; - /** * Keep track of whether the warnings have been thrown to prevent * the messages being thrown for every token triggering the sniff. @@ -249,7 +242,7 @@ public function getGroups() { } /** - * This sniff is active, but it's deprecated, handle the deprecation notices + * Process the token and handle the deprecation notices. * * @since 1.0.0 Added to allow for throwing the deprecation notices. * @@ -260,7 +253,7 @@ public function getGroups() { public function process_token( $stackPtr ) { if ( false === $this->thrown['DeprecatedSniff'] ) { $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.RestrictedFunctionsSniff" sniff has been deprecated. Please update your custom ruleset.', + 'The "WordPress.VIP.RestrictedFunctions" sniff has been deprecated. Please update your custom ruleset.', 0, 'DeprecatedSniff' ); @@ -270,7 +263,7 @@ public function process_token( $stackPtr ) { && false === $this->thrown['FoundPropertyForDeprecatedSniff'] ) { $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.RestrictedFunctionsSniff" sniff has been deprecated. Please update your custom ruleset.', + 'The "WordPress.VIP.RestrictedFunctions" sniff has been deprecated. Please update your custom ruleset.', 0, 'FoundPropertyForDeprecatedSniff' ); diff --git a/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php b/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php index 81ddb3d587..2ac6213d8b 100644 --- a/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php +++ b/WordPress/Sniffs/VIP/RestrictedVariablesSniff.php @@ -26,13 +26,6 @@ */ class RestrictedVariablesSniff extends AbstractVariableRestrictionsSniff { - /** - * If true, an error will be thrown; otherwise a warning. - * - * @var bool - */ - public $error = true; - /** * Keep track of whether the warnings have been thrown to prevent * the messages being thrown for every token triggering the sniff. @@ -89,7 +82,7 @@ public function getGroups() { } /** - * This sniff is active, but it's deprecated, handle the deprecation notices + * Process the token and handle the deprecation notices. * * @since 1.0.0 Added to allow for throwing the deprecation notices. * @@ -100,7 +93,7 @@ public function getGroups() { public function process_token( $stackPtr ) { if ( false === $this->thrown['DeprecatedSniff'] ) { $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.RestrictedVariablesSniff" sniff has been deprecated. Please update your custom ruleset.', + 'The "WordPress.VIP.RestrictedVariables" sniff has been deprecated. Please update your custom ruleset.', 0, 'DeprecatedSniff' ); @@ -110,7 +103,7 @@ public function process_token( $stackPtr ) { && false === $this->thrown['FoundPropertyForDeprecatedSniff'] ) { $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.RestrictedVariablesSniff" sniff has been deprecated. Please update your custom ruleset.', + 'The "WordPress.VIP.RestrictedVariables" sniff has been deprecated. Please update your custom ruleset.', 0, 'FoundPropertyForDeprecatedSniff' ); diff --git a/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php b/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php index eb74493ac9..9131e65d76 100644 --- a/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php +++ b/WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php @@ -28,13 +28,6 @@ */ class SessionFunctionsUsageSniff extends AbstractFunctionRestrictionsSniff { - /** - * If true, an error will be thrown; otherwise a warning. - * - * @var bool - */ - public $error = true; - /** * Keep track of whether the warnings have been thrown to prevent * the messages being thrown for every token triggering the sniff. @@ -100,7 +93,7 @@ public function getGroups() { /** - * This sniff is active, but it's deprecated, handle the deprecation notices + * Process the token and handle the deprecation notices. * * @since 1.0.0 Added to allow for throwing the deprecation notices. * @@ -111,7 +104,7 @@ public function getGroups() { public function process_token( $stackPtr ) { if ( false === $this->thrown['DeprecatedSniff'] ) { $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.SessionFunctionsUsageSniff" sniff has been deprecated. Please update your custom ruleset.', + 'The "WordPress.VIP.SessionFunctionsUsage" sniff has been deprecated. Please update your custom ruleset.', 0, 'DeprecatedSniff' ); @@ -121,7 +114,7 @@ public function process_token( $stackPtr ) { && false === $this->thrown['FoundPropertyForDeprecatedSniff'] ) { $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.SessionFunctionsUsageSniff" sniff has been deprecated. Please update your custom ruleset.', + 'The "WordPress.VIP.SessionFunctionsUsage" sniff has been deprecated. Please update your custom ruleset.', 0, 'FoundPropertyForDeprecatedSniff' ); diff --git a/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php b/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php index 468d64c150..564341c766 100644 --- a/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php +++ b/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php @@ -30,13 +30,6 @@ */ class SessionVariableUsageSniff extends Sniff { - /** - * If true, an error will be thrown; otherwise a warning. - * - * @var bool - */ - public $error = true; - /** * Keep track of whether the warnings have been thrown to prevent * the messages being thrown for every token triggering the sniff. @@ -47,7 +40,6 @@ class SessionVariableUsageSniff extends Sniff { */ private $thrown = array( 'DeprecatedSniff' => false, - 'FoundPropertyForDeprecatedSniff' => false, ); /** @@ -62,7 +54,7 @@ public function register() { } /** - * Processes this test, when one of its tokens is encountered. + * Process the token and handle the deprecation notices. * * @param int $stackPtr The position of the current token in the stack. * @@ -71,22 +63,12 @@ public function register() { public function process_token( $stackPtr ) { if ( false === $this->thrown['DeprecatedSniff'] ) { $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.SessionVariableUsageSniff" sniff has been deprecated. Please update your custom ruleset.', + 'The "WordPress.VIP.SessionVariableUsage" sniff has been deprecated. Please update your custom ruleset.', 0, 'DeprecatedSniff' ); } - if ( ! empty( $this->exclude ) - && false === $this->thrown['FoundPropertyForDeprecatedSniff'] - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.SessionVariableUsageSniff" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - if ( '$_SESSION' === $this->tokens[ $stackPtr ]['content'] ) { $this->phpcsFile->addError( 'Usage of $_SESSION variable is prohibited.', diff --git a/WordPress/Sniffs/VIP/SlowDBQuerySniff.php b/WordPress/Sniffs/VIP/SlowDBQuerySniff.php index 123d0c033f..77f045b97c 100644 --- a/WordPress/Sniffs/VIP/SlowDBQuerySniff.php +++ b/WordPress/Sniffs/VIP/SlowDBQuerySniff.php @@ -43,7 +43,7 @@ class SlowDBQuerySniff extends \WordPress\Sniffs\DB\SlowDBQuerySniff { ); /** - * Don't use. + * Process the token and handle the deprecation notices. * * @deprecated 1.0.0 * diff --git a/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php b/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php index bb1f5b890d..f4344c0061 100644 --- a/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php +++ b/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php @@ -27,13 +27,6 @@ */ class SuperGlobalInputUsageSniff extends Sniff { - /** - * If true, an error will be thrown; otherwise a warning. - * - * @var bool - */ - public $error = true; - /** * Keep track of whether the warnings have been thrown to prevent * the messages being thrown for every token triggering the sniff. @@ -44,7 +37,6 @@ class SuperGlobalInputUsageSniff extends Sniff { */ private $thrown = array( 'DeprecatedSniff' => false, - 'FoundPropertyForDeprecatedSniff' => false, ); /** @@ -59,7 +51,7 @@ public function register() { } /** - * Processes this test, when one of its tokens is encountered. + * Process the token and handle the deprecation notices. * * @param int $stackPtr The position of the current token in the stack. * @@ -68,22 +60,12 @@ public function register() { public function process_token( $stackPtr ) { if ( false === $this->thrown['DeprecatedSniff'] ) { $this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.SessionVariableUsageSniff" sniff has been deprecated. Please update your custom ruleset.', + 'The "WordPress.VIP.SuperGlobalInputUsage" sniff has been deprecated. Please update your custom ruleset.', 0, 'DeprecatedSniff' ); } - if ( ! empty( $this->exclude ) - && false === $this->thrown['FoundPropertyForDeprecatedSniff'] - ) { - $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( - 'The "WordPress.VIP.SessionVariableUsageSniff" sniff has been deprecated. Please update your custom ruleset.', - 0, - 'FoundPropertyForDeprecatedSniff' - ); - } - // Check for global input variable. if ( ! in_array( $this->tokens[ $stackPtr ]['content'], $this->input_superglobals, true ) ) { return; diff --git a/WordPress/Sniffs/VIP/TimezoneChangeSniff.php b/WordPress/Sniffs/VIP/TimezoneChangeSniff.php index 27a73089a5..dca04cd199 100644 --- a/WordPress/Sniffs/VIP/TimezoneChangeSniff.php +++ b/WordPress/Sniffs/VIP/TimezoneChangeSniff.php @@ -42,7 +42,7 @@ class TimezoneChangeSniff extends \WordPress\Sniffs\WP\TimezoneChangeSniff { ); /** - * Don't use. + * Process the token and handle the deprecation notices. * * @deprecated 1.0.0 * diff --git a/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php b/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php index 699c00463e..672bf1a79f 100644 --- a/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php +++ b/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php @@ -42,7 +42,7 @@ class ValidatedSanitizedInputSniff extends \WordPress\Sniffs\Security\ValidatedS ); /** - * Don't use. + * Process the token and handle the deprecation notices. * * @deprecated 1.0.0 * diff --git a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php b/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php index 7f6acdf059..8913ff8938 100644 --- a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php +++ b/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php @@ -92,20 +92,16 @@ public function getWarningList( $testFile = '' ) { switch ( $testFile ) { case 'AdminBarRemovalUnitTest.css': return array( - 1 => 2, + 1 => 2, ); - case 'AdminBarRemovalUnitTest.css': + case 'AdminBarRemovalUnitTest.inc': return array( - 1 => 1, + 1 => 1, ); default: return array(); } - return array( - 1 => 2, - ); } - } From 9faef43ec4f6f501172a8edd8b28e831e896c847 Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Mon, 9 Jul 2018 19:07:00 +0100 Subject: [PATCH 11/19] Deprecated AbstractVariableRestrictionsSniff --- WordPress/AbstractVariableRestrictionsSniff.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WordPress/AbstractVariableRestrictionsSniff.php b/WordPress/AbstractVariableRestrictionsSniff.php index aadd89ba32..7b647e2644 100644 --- a/WordPress/AbstractVariableRestrictionsSniff.php +++ b/WordPress/AbstractVariableRestrictionsSniff.php @@ -22,6 +22,8 @@ * `WordPress_Sniffs_Variables_VariableRestrictionsSniff` to * `WordPress_AbstractVariableRestrictionsSniff`. * @since 0.11.0 Extends the WordPress_Sniff class. + * + * @deprecated 1.0.0 All sniffs depending on this class were deprecated */ abstract class AbstractVariableRestrictionsSniff extends Sniff { From a4db74024557cf4274e3a6f4871823423fb33bc8 Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Mon, 9 Jul 2018 19:08:53 +0100 Subject: [PATCH 12/19] deprecated the has_html_open_tag method in Sniff class --- WordPress/Sniff.php | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index 64c1bf086f..cae90ba784 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -2382,6 +2382,7 @@ public function get_declared_namespace_name( $stackPtr ) { * substring of the original string. * Defaults to `false` to distinguish between a passed * empty string and not passing the $content string. + * @deprecated 1.0.0 This method is only used by deprecated sniffs * * @return bool True if the string contains an open tag, false otherwise. */ From 4b50df59f3eac4badabc43b38ba6389f166f4e3a Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Mon, 9 Jul 2018 19:15:24 +0100 Subject: [PATCH 13/19] Remove VIP from the standard WP ruleset --- README.md | 4 +- WordPress/ruleset.xml | 100 +----------------------------------------- 2 files changed, 4 insertions(+), 100 deletions(-) diff --git a/README.md b/README.md index a4af42f1ca..506d70656e 100644 --- a/README.md +++ b/README.md @@ -133,8 +133,8 @@ You can use the following as standard names when invoking `phpcs` to select snif - `WordPress-Docs` - additional ruleset for [WordPress inline documentation standards](https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/) - `WordPress-Extra` - extended ruleset for recommended best practices, not sufficiently covered in the WordPress core coding standards - includes `WordPress-Core` - - `WordPress-VIP` - extended ruleset for [WordPress.com VIP coding requirements](https://vip.wordpress.com/documentation/code-review-what-we-look-for/) - - includes `WordPress-Core` + +**Note:** The `WordPress-VIP` ruleset, which includes `WordPress-Core`, is also currently present as a subset of `WordPress`. It was originally intended for [WordPress.com VIP coding requirements](https://vip.wordpress.com/documentation/code-review-what-we-look-for/), but this is no longer used or recommended by the WordPress.com VIP team or their clients. **This ruleset is considered to be deprecated, and will be removed in due course.** See [#1309](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1309) for more information. ### Using a custom ruleset diff --git a/WordPress/ruleset.xml b/WordPress/ruleset.xml index 38379cb846..bf3aeedfb9 100644 --- a/WordPress/ruleset.xml +++ b/WordPress/ruleset.xml @@ -3,18 +3,12 @@ WordPress Coding Standards ./PHPCSAliases.php - +G - - - - - - - + - - - 0 - - - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - 0 @@ -110,58 +66,6 @@ 0 - - - 0 - - - - - 0 - - - - - 0 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 0 - - - - - 0 - - - 0 - - - - - 0 - - - - - 0 - - 0 From ad1c0147b5b57c82f6eb2514c33d055bd8a66911 Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Mon, 9 Jul 2018 19:18:36 +0100 Subject: [PATCH 14/19] unit test fixes --- WordPress/Tests/VIP/AdminBarRemovalUnitTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php b/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php index 8913ff8938..d6b7a06516 100644 --- a/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php +++ b/WordPress/Tests/VIP/AdminBarRemovalUnitTest.php @@ -96,9 +96,7 @@ public function getWarningList( $testFile = '' ) { ); case 'AdminBarRemovalUnitTest.inc': - return array( - 1 => 1, - ); + return array(); default: return array(); From 9c1e44f094edb3c54d1bcc7106598ef362e05927 Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Mon, 9 Jul 2018 20:00:22 +0100 Subject: [PATCH 15/19] Fixes stray whitespace characters in the WP ruleset, and yoda conditions in 2 sniffs --- WordPress/Sniffs/VIP/AdminBarRemovalSniff.php | 2 +- WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php | 2 +- WordPress/Sniffs/VIP/SessionVariableUsageSniff.php | 2 +- WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php | 2 +- WordPress/ruleset.xml | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php b/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php index c6717c277e..132a8c6cd4 100644 --- a/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php +++ b/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php @@ -202,7 +202,7 @@ public function process_token( $stackPtr ) { ); } - if ( ( $this->remove_only === false ) && + if ( ( false === $this->remove_only ) && false === $this->thrown['FoundPropertyForDeprecatedSniff'] ) { $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( 'The "WordPress.VIP.AdminBarRemoval" sniff has been deprecated. Please update your custom ruleset.', diff --git a/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php b/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php index 991c4221b9..fe29f6920a 100644 --- a/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php +++ b/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php @@ -136,7 +136,7 @@ public function process_token( $stackPtr ) { ); } - if ( ( ! empty( $this->exclude ) || !empty( $this->error ) ) + if ( ( ! empty( $this->exclude ) || true !== $this->error ) && false === $this->thrown['FoundPropertyForDeprecatedSniff'] ) { $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( diff --git a/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php b/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php index 564341c766..d3b57236b0 100644 --- a/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php +++ b/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php @@ -39,7 +39,7 @@ class SessionVariableUsageSniff extends Sniff { * @var array */ private $thrown = array( - 'DeprecatedSniff' => false, + 'DeprecatedSniff' => false, ); /** diff --git a/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php b/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php index f4344c0061..8d5e18e03d 100644 --- a/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php +++ b/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php @@ -36,7 +36,7 @@ class SuperGlobalInputUsageSniff extends Sniff { * @var array */ private $thrown = array( - 'DeprecatedSniff' => false, + 'DeprecatedSniff' => false, ); /** diff --git a/WordPress/ruleset.xml b/WordPress/ruleset.xml index bf3aeedfb9..549d2cb601 100644 --- a/WordPress/ruleset.xml +++ b/WordPress/ruleset.xml @@ -8,14 +8,14 @@ G - + + -->g From e3206b73be2e275ded23f54755e8b04f7d74acb7 Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Tue, 10 Jul 2018 11:00:44 +0100 Subject: [PATCH 16/19] Apply spelling and grammar corrections to VIP deprecations --- WordPress-VIP/ruleset.xml | 28 +++++++++---------- .../AbstractVariableRestrictionsSniff.php | 2 +- WordPress/Sniff.php | 2 +- WordPress/Sniffs/VIP/AdminBarRemovalSniff.php | 2 +- WordPress/Sniffs/VIP/CronIntervalSniff.php | 2 +- .../Sniffs/VIP/DirectDatabaseQuerySniff.php | 2 +- WordPress/Sniffs/VIP/OrderByRandSniff.php | 7 ----- WordPress/Sniffs/VIP/PluginMenuSlugSniff.php | 2 +- .../Sniffs/VIP/SessionVariableUsageSniff.php | 2 +- WordPress/Sniffs/VIP/SlowDBQuerySniff.php | 2 +- .../Sniffs/VIP/SuperGlobalInputUsageSniff.php | 2 +- WordPress/Sniffs/VIP/TimezoneChangeSniff.php | 2 +- .../VIP/ValidatedSanitizedInputSniff.php | 2 +- WordPress/ruleset.xml | 6 ++-- 14 files changed, 29 insertions(+), 34 deletions(-) diff --git a/WordPress-VIP/ruleset.xml b/WordPress-VIP/ruleset.xml index 1b41f03446..84b10a76c7 100644 --- a/WordPress-VIP/ruleset.xml +++ b/WordPress-VIP/ruleset.xml @@ -132,12 +132,12 @@ ############################################################################# --> - + 0 - + 0 @@ -153,7 +153,7 @@ 0 - + 0 @@ -175,7 +175,7 @@ 0 - + 0 @@ -185,7 +185,7 @@ 0 - + 0 @@ -204,7 +204,7 @@ 0 - + 0 @@ -217,42 +217,42 @@ 0 - + 0 - + 0 - + 0 - + 0 - + 0 - + 0 - + 0 - + 0 diff --git a/WordPress/AbstractVariableRestrictionsSniff.php b/WordPress/AbstractVariableRestrictionsSniff.php index 7b647e2644..f9c561c83a 100644 --- a/WordPress/AbstractVariableRestrictionsSniff.php +++ b/WordPress/AbstractVariableRestrictionsSniff.php @@ -23,7 +23,7 @@ * `WordPress_AbstractVariableRestrictionsSniff`. * @since 0.11.0 Extends the WordPress_Sniff class. * - * @deprecated 1.0.0 All sniffs depending on this class were deprecated + * @deprecated 1.0.0 All sniffs depending on this class were deprecated. */ abstract class AbstractVariableRestrictionsSniff extends Sniff { diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index cae90ba784..8b19d1f584 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -2371,6 +2371,7 @@ public function get_declared_namespace_name( $stackPtr ) { * originally created. * @since 0.13.0 The $stackPtr parameter is now optional. Either that or the * $content parameter has to be passed. + * @deprecated 1.0.0 This method is only used by deprecated sniffs. * * @param string $tag_name The name of the HTML tag without brackets. So if * searching for ' open tag, false otherwise. */ diff --git a/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php b/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php index 132a8c6cd4..cad82e051a 100644 --- a/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php +++ b/WordPress/Sniffs/VIP/AdminBarRemovalSniff.php @@ -202,7 +202,7 @@ public function process_token( $stackPtr ) { ); } - if ( ( false === $this->remove_only ) && + if ( ( true !== $this->remove_only ) && false === $this->thrown['FoundPropertyForDeprecatedSniff'] ) { $this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning( 'The "WordPress.VIP.AdminBarRemoval" sniff has been deprecated. Please update your custom ruleset.', diff --git a/WordPress/Sniffs/VIP/CronIntervalSniff.php b/WordPress/Sniffs/VIP/CronIntervalSniff.php index a792a73da9..e989d7f461 100644 --- a/WordPress/Sniffs/VIP/CronIntervalSniff.php +++ b/WordPress/Sniffs/VIP/CronIntervalSniff.php @@ -56,7 +56,7 @@ class CronIntervalSniff extends \WordPress\Sniffs\WP\CronIntervalSniff { ); /** - * Process the token and handle the deprecation notices. + * Don't use. * * @deprecated 1.0.0 * diff --git a/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php b/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php index fb834ecdbf..98d75322fa 100644 --- a/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php +++ b/WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php @@ -44,7 +44,7 @@ class DirectDatabaseQuerySniff extends \WordPress\Sniffs\DB\DirectDatabaseQueryS ); /** - * Process the token and handle the deprecation notices. + * Don't use. * * @deprecated 1.0.0 * diff --git a/WordPress/Sniffs/VIP/OrderByRandSniff.php b/WordPress/Sniffs/VIP/OrderByRandSniff.php index 967bedce68..5a423ee55b 100644 --- a/WordPress/Sniffs/VIP/OrderByRandSniff.php +++ b/WordPress/Sniffs/VIP/OrderByRandSniff.php @@ -26,13 +26,6 @@ */ class OrderByRandSniff extends AbstractArrayAssignmentRestrictionsSniff { - /** - * If true, an error will be thrown; otherwise a warning. - * - * @var bool - */ - public $error = true; - /** * Keep track of whether the warnings have been thrown to prevent * the messages being thrown for every token triggering the sniff. diff --git a/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php b/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php index 522c0d640d..8b73e46788 100644 --- a/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php +++ b/WordPress/Sniffs/VIP/PluginMenuSlugSniff.php @@ -40,7 +40,7 @@ class PluginMenuSlugSniff extends \WordPress\Sniffs\Security\PluginMenuSlugSniff ); /** - * Process the token and handle the deprecation notices. + * Don't use. * * @deprecated 1.0.0 * diff --git a/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php b/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php index d3b57236b0..41eaf0cefc 100644 --- a/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php +++ b/WordPress/Sniffs/VIP/SessionVariableUsageSniff.php @@ -54,7 +54,7 @@ public function register() { } /** - * Process the token and handle the deprecation notices. + * Process the token and handle the deprecation notice. * * @param int $stackPtr The position of the current token in the stack. * diff --git a/WordPress/Sniffs/VIP/SlowDBQuerySniff.php b/WordPress/Sniffs/VIP/SlowDBQuerySniff.php index 77f045b97c..123d0c033f 100644 --- a/WordPress/Sniffs/VIP/SlowDBQuerySniff.php +++ b/WordPress/Sniffs/VIP/SlowDBQuerySniff.php @@ -43,7 +43,7 @@ class SlowDBQuerySniff extends \WordPress\Sniffs\DB\SlowDBQuerySniff { ); /** - * Process the token and handle the deprecation notices. + * Don't use. * * @deprecated 1.0.0 * diff --git a/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php b/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php index 8d5e18e03d..10061b632e 100644 --- a/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php +++ b/WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php @@ -51,7 +51,7 @@ public function register() { } /** - * Process the token and handle the deprecation notices. + * Process the token and handle the deprecation notice. * * @param int $stackPtr The position of the current token in the stack. * diff --git a/WordPress/Sniffs/VIP/TimezoneChangeSniff.php b/WordPress/Sniffs/VIP/TimezoneChangeSniff.php index dca04cd199..27a73089a5 100644 --- a/WordPress/Sniffs/VIP/TimezoneChangeSniff.php +++ b/WordPress/Sniffs/VIP/TimezoneChangeSniff.php @@ -42,7 +42,7 @@ class TimezoneChangeSniff extends \WordPress\Sniffs\WP\TimezoneChangeSniff { ); /** - * Process the token and handle the deprecation notices. + * Don't use. * * @deprecated 1.0.0 * diff --git a/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php b/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php index 672bf1a79f..699c00463e 100644 --- a/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php +++ b/WordPress/Sniffs/VIP/ValidatedSanitizedInputSniff.php @@ -42,7 +42,7 @@ class ValidatedSanitizedInputSniff extends \WordPress\Sniffs\Security\ValidatedS ); /** - * Process the token and handle the deprecation notices. + * Don't use. * * @deprecated 1.0.0 * diff --git a/WordPress/ruleset.xml b/WordPress/ruleset.xml index 549d2cb601..74db6f967e 100644 --- a/WordPress/ruleset.xml +++ b/WordPress/ruleset.xml @@ -3,11 +3,13 @@ WordPress Coding Standards ./PHPCSAliases.php -G + + + g + --> From 20494c4af07dc04edc35de258c9dd1a690ffc368 Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Tue, 10 Jul 2018 11:01:24 +0100 Subject: [PATCH 17/19] merges the xml comment in the VIP ruleset into the description --- WordPress-VIP/ruleset.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/WordPress-VIP/ruleset.xml b/WordPress-VIP/ruleset.xml index 84b10a76c7..9b30824f6e 100644 --- a/WordPress-VIP/ruleset.xml +++ b/WordPress-VIP/ruleset.xml @@ -1,7 +1,6 @@ - - Deprecated WordPress.com VIP Coding Standards, use the official VIP coding standards instead + Deprecated WordPress.com VIP Coding Standards, use the official VIP coding standards instead, these can be found at https://github.com/Automattic/VIP-Coding-Standards ./../WordPress/PHPCSAliases.php From 50c3471b35f13289626ae1aee5c8f6381409c991 Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Fri, 13 Jul 2018 18:14:55 +0100 Subject: [PATCH 18/19] test the exclude parameter deprecation in the deprecated VIP sniff unit tests --- WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.inc | 6 ++++++ WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php | 2 +- WordPress/Tests/VIP/OrderByRandUnitTest.inc | 5 +++++ WordPress/Tests/VIP/OrderByRandUnitTest.php | 3 ++- WordPress/Tests/VIP/RestrictedFunctionsUnitTest.inc | 5 +++++ WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php | 2 +- WordPress/Tests/VIP/RestrictedVariablesUnitTest.inc | 5 +++++ WordPress/Tests/VIP/RestrictedVariablesUnitTest.php | 2 +- WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.inc | 6 ++++++ WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.php | 2 +- WordPress/ruleset.xml | 7 ++++++- 11 files changed, 39 insertions(+), 6 deletions(-) diff --git a/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.inc b/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.inc index 4fa4f24c80..4a5c2b23e1 100644 --- a/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.inc +++ b/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.inc @@ -36,6 +36,12 @@ chmod(); lchgrp(); lchown(); +// @codingStandardsChangeSetting WordPress.VIP.FileSystemWritesDisallow exclude directory +mkdir(); + +// @codingStandardsChangeSetting WordPress.VIP.FileSystemWritesDisallow exclude false + + // Issue #956. use Fieldmanager_Link as Link; diff --git a/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php b/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php index 16c6731249..b5d30f8a56 100644 --- a/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php +++ b/WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php @@ -61,7 +61,7 @@ public function getErrorList() { */ public function getWarningList() { return array( - 1 => 1, + 1 => 2, ); } diff --git a/WordPress/Tests/VIP/OrderByRandUnitTest.inc b/WordPress/Tests/VIP/OrderByRandUnitTest.inc index c680a98a8b..0a722377df 100644 --- a/WordPress/Tests/VIP/OrderByRandUnitTest.inc +++ b/WordPress/Tests/VIP/OrderByRandUnitTest.inc @@ -11,3 +11,8 @@ _query_posts( 'orderby=rand' ); // Bad. $query_args['orderby'] = 'rand'; // Bad. $query_args['orderby'] = 'date'; // Ok. + +// @codingStandardsChangeSetting WordPress.VIP.OrderByRand exclude something +$query_args['orderby'] = 'rand'; // Bad. + +// @codingStandardsChangeSetting WordPress.VIP.OrderByRand exclude false \ No newline at end of file diff --git a/WordPress/Tests/VIP/OrderByRandUnitTest.php b/WordPress/Tests/VIP/OrderByRandUnitTest.php index 4652e67839..084eedfd33 100644 --- a/WordPress/Tests/VIP/OrderByRandUnitTest.php +++ b/WordPress/Tests/VIP/OrderByRandUnitTest.php @@ -33,6 +33,7 @@ public function getErrorList() { 6 => 1, 9 => 1, 11 => 1, + 16 => 1, ); } @@ -43,7 +44,7 @@ public function getErrorList() { */ public function getWarningList() { return array( - 1 => 1, + 1 => 2, ); } diff --git a/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.inc b/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.inc index 61298ac806..f0f06d3a1b 100644 --- a/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.inc +++ b/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.inc @@ -82,3 +82,8 @@ get_user_meta(); // Error. update_user_meta(); // Error. delete_user_meta(); // Error. add_user_meta(); // Error. + +// @codingStandardsChangeSetting WordPress.VIP.RestrictedFunctions exclude switch_to_blog +switch_to_blog( $blogid ); // Error. + +// @codingStandardsChangeSetting WordPress.VIP.RestrictedFunctions exclude false diff --git a/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php b/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php index 96499c3c12..b2cb717aba 100644 --- a/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php +++ b/WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php @@ -63,7 +63,7 @@ public function getErrorList() { */ public function getWarningList() { return array( - 1 => 1, + 1 => 2, 5 => 1, 7 => 1, 9 => 1, diff --git a/WordPress/Tests/VIP/RestrictedVariablesUnitTest.inc b/WordPress/Tests/VIP/RestrictedVariablesUnitTest.inc index 5673c5549e..b4b3a65c48 100644 --- a/WordPress/Tests/VIP/RestrictedVariablesUnitTest.inc +++ b/WordPress/Tests/VIP/RestrictedVariablesUnitTest.inc @@ -27,3 +27,8 @@ EOD; $phrase = << 1, + 1 => 2, 13 => 1, 14 => 1, 17 => 1, diff --git a/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.inc b/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.inc index 3935bcc5df..086fdab098 100644 --- a/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.inc +++ b/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.inc @@ -26,3 +26,9 @@ session_status(); session_unregister(); session_unset(); session_write_close(); + +// @codingStandardsChangeSetting WordPress.VIP.SessionFunctionsUsage exclude session +session_start(); + +// @codingStandardsChangeSetting WordPress.VIP.SessionFunctionsUsage exclude false + diff --git a/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.php b/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.php index f9baaa552c..d0a55a07c0 100644 --- a/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.php +++ b/WordPress/Tests/VIP/SessionFunctionsUsageUnitTest.php @@ -37,7 +37,7 @@ public function getErrorList() { */ public function getWarningList() { return array( - 1 => 1, + 1 => 2, ); } diff --git a/WordPress/ruleset.xml b/WordPress/ruleset.xml index 74db6f967e..4db0054249 100644 --- a/WordPress/ruleset.xml +++ b/WordPress/ruleset.xml @@ -8,7 +8,12 @@ - + + + + + + From 50c6d7790a16b27ccd0ea4b476ae874621451c95 Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Mon, 16 Jul 2018 11:59:30 +0100 Subject: [PATCH 19/19] Updated the VIP deprecation notice in the readme to read better --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 506d70656e..c85e425e21 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,9 @@ You can use the following as standard names when invoking `phpcs` to select snif - `WordPress-Extra` - extended ruleset for recommended best practices, not sufficiently covered in the WordPress core coding standards - includes `WordPress-Core` -**Note:** The `WordPress-VIP` ruleset, which includes `WordPress-Core`, is also currently present as a subset of `WordPress`. It was originally intended for [WordPress.com VIP coding requirements](https://vip.wordpress.com/documentation/code-review-what-we-look-for/), but this is no longer used or recommended by the WordPress.com VIP team or their clients. **This ruleset is considered to be deprecated, and will be removed in due course.** See [#1309](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1309) for more information. +**Notes:** This WPCS package contains the sniffs for another ruleset, `WordPress-VIP`. This ruleset was originally intended to aid with the [WordPress.com VIP coding requirements](https://vip.wordpress.com/documentation/code-review-what-we-look-for/), but this is no longer used or recommended by the WordPress.com VIP team or their clients, since they prefer to use their [official VIP coding standards](https://github.com/Automattic/VIP-Coding-Standards) ruleset instead. + +Before WPCS `1.0.0`, the WordPress-VIP ruleset was included as part of the complete `WordPress` ruleset. **As of `1.0.0` the `WordPress-VIP` ruleset is not part of the WordPress ruleset, and it is deprecated**. The remaining `WordPress-VIP` sniffs may still be referenced in custom rulesets, so to maintain some backwards compatibility, they will remain in WPCS until `2.0.0`. See [#1309](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1309) for more information. ### Using a custom ruleset