Skip to content

Commit b76edcc

Browse files
committed
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
1 parent e9d9698 commit b76edcc

File tree

7 files changed

+41
-9
lines changed

7 files changed

+41
-9
lines changed

WordPress-VIP-Go/ruleset-test.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,9 @@ $my_theme_options = get_option( 'my_theme', false );
341341
if ( array_key_exists( 'key', $my_theme_options ) ) { } // Error.
342342
echo '<a href="' . esc_url( get_term_link( $var ) ) . '">My term link</a>'; // Error.
343343

344-
// WordPressVIPMinimum.Functions.DynamicCalls
345-
$my_notokay_func = 'extract';
346-
$my_notokay_func(); // Error.
344+
345+
346+
347347

348348
// WordPressVIPMinimum.Functions.RestrictedFunctions
349349

WordPress-VIP-Go/ruleset-test.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
337 => 1,
3737
341 => 1,
3838
342 => 1,
39-
346 => 1,
4039
350 => 1,
4140
351 => 1,
4241
352 => 1,

WordPress-VIP-Go/ruleset.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<!-- Include the base VIP Minimum ruleset -->
77
<rule ref="WordPressVIPMinimum">
88
<exclude name="WordPressVIPMinimum.JS"/>
9+
<exclude name="WordPressVIPMinimum.Functions.DynamicCalls"/>
910
</rule>
1011

1112
<!-- Things that may be incompatible with the VIP Go infrastructure and needs a dev to review -->

WordPressVIPMinimum/Sniffs/Functions/DynamicCallsSniff.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace WordPressVIPMinimum\Sniffs\Functions;
1111

12+
use PHP_CodeSniffer\Sniffs\DeprecatedSniff;
1213
use PHP_CodeSniffer\Util\Tokens;
1314
use PHPCSUtils\Utils\TextStrings;
1415
use WordPressVIPMinimum\Sniffs\Sniff;
@@ -26,7 +27,7 @@
2627
*
2728
* @link http://php.net/manual/en/migration71.incompatible.php
2829
*/
29-
class DynamicCallsSniff extends Sniff {
30+
class DynamicCallsSniff extends Sniff implements DeprecatedSniff {
3031

3132
/**
3233
* Functions that should not be called dynamically.
@@ -194,4 +195,31 @@ private function find_dynamic_calls( $stackPtr ) {
194195
$data = [ $this->variables_arr[ $this->tokens[ $stackPtr ]['content'] ] ];
195196
$this->phpcsFile->addError( $message, $stackPtr, 'DynamicCalls', $data );
196197
}
198+
199+
/**
200+
* Provide the version number in which the sniff was deprecated.
201+
*
202+
* @return string
203+
*/
204+
public function getDeprecationVersion() {
205+
return 'VIP-Coding-Standard v3.1.0';
206+
}
207+
208+
/**
209+
* Provide the version number in which the sniff will be removed.
210+
*
211+
* @return string
212+
*/
213+
public function getRemovalVersion() {
214+
return 'VIP-Coding-Standard v4.0.0';
215+
}
216+
217+
/**
218+
* Provide a custom message to display with the deprecation.
219+
*
220+
* @return string
221+
*/
222+
public function getDeprecationMessage() {
223+
return '';
224+
}
197225
}

WordPressVIPMinimum/ruleset-test.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,9 @@ $my_theme_options = get_option( 'my_theme', false );
303303
if ( array_key_exists( 'key', $my_theme_options ) ) { } // Error.
304304
echo '<a href="' . esc_url( get_term_link( $var ) ) . '">My term link</a>'; // Error.
305305

306-
// WordPressVIPMinimum.Functions.DynamicCalls
307-
$my_notokay_func = 'extract';
308-
$my_notokay_func(); // Error.
306+
307+
308+
309309

310310
// WordPressVIPMinimum.Functions.RestrictedFunctions
311311

WordPressVIPMinimum/ruleset-test.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
299 => 1,
8282
303 => 1,
8383
304 => 1,
84-
308 => 1,
8584
312 => 1,
8685
313 => 1,
8786
314 => 1,

WordPressVIPMinimum/ruleset.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
rule in which to place the exclusion, so this will have to do for now.
1919
-->
2020
<exclude name="WordPressVIPMinimum.JS"/>
21+
22+
<!--
23+
Exclude other deprecated sniffs.
24+
-->
25+
<exclude name="WordPressVIPMinimum.Functions.DynamicCalls"/>
2126
</rule>
2227

2328
<rule ref="Generic.PHP.Syntax"/>

0 commit comments

Comments
 (0)