From cc96a0d2c6dc8c0da25600ad5ba732fedf30b33c Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Fri, 6 Jul 2018 20:17:10 +0100 Subject: [PATCH] Deprecated the VIP FileSystemWritesDisallow Sniff --- WordPress-VIP/ruleset.xml | 5 +++ .../VIP/FileSystemWritesDisallowSniff.php | 44 +++++++++++++++++++ .../VIP/FileSystemWritesDisallowUnitTest.php | 4 +- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/WordPress-VIP/ruleset.xml b/WordPress-VIP/ruleset.xml index 9abc37f7e4..60ae87d6ec 100644 --- a/WordPress-VIP/ruleset.xml +++ b/WordPress-VIP/ruleset.xml @@ -211,6 +211,11 @@ 0 + + + 0 + + 0 diff --git a/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php b/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php index 0f90ac760e..863ca9269e 100644 --- a/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php +++ b/WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php @@ -32,6 +32,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 +115,35 @@ public function getGroups() { return $groups; } + /** + * This sniff is active, but it's deprecated, handle the deprecation notices + * + * @deprecated 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/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, + ); } }