From b76edcc222317036793c456b04c63bfd35139f67 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 28 Jul 2025 14:26:31 +0200 Subject: [PATCH] Hard-deprecate the WordPressVIPMinimum.Functions.DynamicCalls sniff Removing the sniff needs to wait for a new major, as it would be a breaking change, however, in the mean time, we can: * Exclude the sniff from both rulesets. This will prevent PHP_CodeSniffer from throwing deprecation notices about the sniff. * Deprecate the sniff itself, in case users of the VIP-Coding-Standards would be explicitly including the sniff from within their own ruleset. Part of 517 --- WordPress-VIP-Go/ruleset-test.inc | 6 ++-- WordPress-VIP-Go/ruleset-test.php | 1 - WordPress-VIP-Go/ruleset.xml | 1 + .../Sniffs/Functions/DynamicCallsSniff.php | 30 ++++++++++++++++++- WordPressVIPMinimum/ruleset-test.inc | 6 ++-- WordPressVIPMinimum/ruleset-test.php | 1 - WordPressVIPMinimum/ruleset.xml | 5 ++++ 7 files changed, 41 insertions(+), 9 deletions(-) diff --git a/WordPress-VIP-Go/ruleset-test.inc b/WordPress-VIP-Go/ruleset-test.inc index bd7e3de6..c4ec4eeb 100644 --- a/WordPress-VIP-Go/ruleset-test.inc +++ b/WordPress-VIP-Go/ruleset-test.inc @@ -341,9 +341,9 @@ $my_theme_options = get_option( 'my_theme', false ); if ( array_key_exists( 'key', $my_theme_options ) ) { } // Error. echo 'My term link'; // Error. -// WordPressVIPMinimum.Functions.DynamicCalls -$my_notokay_func = 'extract'; -$my_notokay_func(); // Error. + + + // WordPressVIPMinimum.Functions.RestrictedFunctions diff --git a/WordPress-VIP-Go/ruleset-test.php b/WordPress-VIP-Go/ruleset-test.php index d8701db4..83cb5514 100644 --- a/WordPress-VIP-Go/ruleset-test.php +++ b/WordPress-VIP-Go/ruleset-test.php @@ -36,7 +36,6 @@ 337 => 1, 341 => 1, 342 => 1, - 346 => 1, 350 => 1, 351 => 1, 352 => 1, diff --git a/WordPress-VIP-Go/ruleset.xml b/WordPress-VIP-Go/ruleset.xml index e3272707..c7eddcf5 100644 --- a/WordPress-VIP-Go/ruleset.xml +++ b/WordPress-VIP-Go/ruleset.xml @@ -6,6 +6,7 @@ + diff --git a/WordPressVIPMinimum/Sniffs/Functions/DynamicCallsSniff.php b/WordPressVIPMinimum/Sniffs/Functions/DynamicCallsSniff.php index 2236d44c..3f19977a 100644 --- a/WordPressVIPMinimum/Sniffs/Functions/DynamicCallsSniff.php +++ b/WordPressVIPMinimum/Sniffs/Functions/DynamicCallsSniff.php @@ -9,6 +9,7 @@ namespace WordPressVIPMinimum\Sniffs\Functions; +use PHP_CodeSniffer\Sniffs\DeprecatedSniff; use PHP_CodeSniffer\Util\Tokens; use PHPCSUtils\Utils\TextStrings; use WordPressVIPMinimum\Sniffs\Sniff; @@ -26,7 +27,7 @@ * * @link http://php.net/manual/en/migration71.incompatible.php */ -class DynamicCallsSniff extends Sniff { +class DynamicCallsSniff extends Sniff implements DeprecatedSniff { /** * Functions that should not be called dynamically. @@ -194,4 +195,31 @@ private function find_dynamic_calls( $stackPtr ) { $data = [ $this->variables_arr[ $this->tokens[ $stackPtr ]['content'] ] ]; $this->phpcsFile->addError( $message, $stackPtr, 'DynamicCalls', $data ); } + + /** + * Provide the version number in which the sniff was deprecated. + * + * @return string + */ + public function getDeprecationVersion() { + return 'VIP-Coding-Standard v3.1.0'; + } + + /** + * Provide the version number in which the sniff will be removed. + * + * @return string + */ + public function getRemovalVersion() { + return 'VIP-Coding-Standard v4.0.0'; + } + + /** + * Provide a custom message to display with the deprecation. + * + * @return string + */ + public function getDeprecationMessage() { + return ''; + } } diff --git a/WordPressVIPMinimum/ruleset-test.inc b/WordPressVIPMinimum/ruleset-test.inc index a20a8494..3a104038 100644 --- a/WordPressVIPMinimum/ruleset-test.inc +++ b/WordPressVIPMinimum/ruleset-test.inc @@ -303,9 +303,9 @@ $my_theme_options = get_option( 'my_theme', false ); if ( array_key_exists( 'key', $my_theme_options ) ) { } // Error. echo 'My term link'; // Error. -// WordPressVIPMinimum.Functions.DynamicCalls -$my_notokay_func = 'extract'; -$my_notokay_func(); // Error. + + + // WordPressVIPMinimum.Functions.RestrictedFunctions diff --git a/WordPressVIPMinimum/ruleset-test.php b/WordPressVIPMinimum/ruleset-test.php index e78ae6a7..4fc80840 100644 --- a/WordPressVIPMinimum/ruleset-test.php +++ b/WordPressVIPMinimum/ruleset-test.php @@ -81,7 +81,6 @@ 299 => 1, 303 => 1, 304 => 1, - 308 => 1, 312 => 1, 313 => 1, 314 => 1, diff --git a/WordPressVIPMinimum/ruleset.xml b/WordPressVIPMinimum/ruleset.xml index f5bdb847..50379d8d 100644 --- a/WordPressVIPMinimum/ruleset.xml +++ b/WordPressVIPMinimum/ruleset.xml @@ -18,6 +18,11 @@ rule in which to place the exclusion, so this will have to do for now. --> + + +