Skip to content

Commit

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

<!-- Prevent deprecation notice when the sniff is not explicitely included. -->
<rule ref="WordPress.VIP.FileSystemWritesDisallow.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
47 changes: 47 additions & 0 deletions WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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.
*
Expand Down Expand Up @@ -102,4 +118,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 );
}

}
4 changes: 3 additions & 1 deletion WordPress/Tests/VIP/FileSystemWritesDisallowUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public function getErrorList() {
* @return array <int line number> => <int number of warnings>
*/
public function getWarningList() {
return array();
return array(
1 => 1,
);
}

}

0 comments on commit c1736c2

Please sign in to comment.