Skip to content

Commit

Permalink
Deprecated the VIP sniff SuperGlobalInputUsageSniff
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjn committed Jul 6, 2018
1 parent fab4210 commit 79170a3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions WordPress-VIP/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@
<severity>0</severity>
</rule>

<!-- Prevent deprecation notice when the sniff is not explicitely included. -->
<rule ref="WordPress.VIP.SuperGlobalInputUsageSniff.DeprecatedSniff">
<severity>0</severity>
</rule>

<!-- Prevent deprecation notice when the sniff is not explicitely included. -->
<rule ref="WordPress.VIP.TimezoneChange.DeprecatedSniff">
<severity>0</severity>
Expand Down
41 changes: 41 additions & 0 deletions WordPress/Sniffs/VIP/SuperGlobalInputUsageSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions WordPress/Tests/VIP/SuperGlobalInputUsageUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function getErrorList() {
*/
public function getWarningList() {
return array(
1 => 1,
3 => 1,
13 => 1,
15 => 1,
Expand Down

0 comments on commit 79170a3

Please sign in to comment.