Skip to content

Commit

Permalink
Fixes for the VIP Sniff deprecations based on Juliettes review
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjn committed Jul 9, 2018
1 parent e62e6cc commit f1bbf24
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 106 deletions.
5 changes: 3 additions & 2 deletions WordPress-VIP/ruleset.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0"?>
<ruleset name="WordPress VIP">
<!-- Use the official VIP rulesets instead, these can be found at https://github.com/Automattic/VIP-Coding-Standards -->
<description>Deprecated WordPress.com VIP Coding Standards, use the official VIP coding standards instead</description>

<autoload>./../WordPress/PHPCSAliases.php</autoload>
Expand Down Expand Up @@ -220,12 +221,12 @@
<rule ref="WordPress.VIP.FileSystemWritesDisallow.DeprecatedSniff">
<severity>0</severity>
</rule>

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

<!-- Prevent deprecation notice when the sniff is not explicitely included. -->
<rule ref="WordPress.VIP.RestrictedFunctions.DeprecatedSniff">
<severity>0</severity>
Expand Down
22 changes: 8 additions & 14 deletions WordPress/Sniffs/VIP/AdminBarRemovalSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@
*/
class AdminBarRemovalSniff extends AbstractFunctionParameterSniff {

/**
* 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.
Expand Down Expand Up @@ -94,15 +87,15 @@ class AdminBarRemovalSniff extends AbstractFunctionParameterSniff {
*/
protected $target_css_properties = array(
'visibility' => array(
'type' => '!=',
'type' => '!=',
'value' => 'hidden',
),
'display' => array(
'type' => '!=',
'type' => '!=',
'value' => 'none',
),
'opacity' => array(
'type' => '>',
'type' => '>',
'value' => 0.3,
),
);
Expand Down Expand Up @@ -190,7 +183,7 @@ public function register() {
}

/**
* Processes this test, when one of its tokens is encountered.
* Process the token and handle the deprecation notices.
*
* @param int $stackPtr The position of the current token in the stack.
*
Expand All @@ -203,15 +196,16 @@ public function process_token( $stackPtr ) {

if ( false === $this->thrown['DeprecatedSniff'] ) {
$this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning(
'The "WordPress.VIP.AdminBarRemovalSniff" sniff has been deprecated. Please update your custom ruleset.',
'The "WordPress.VIP.AdminBarRemoval" sniff has been deprecated. Please update your custom ruleset.',
0,
'DeprecatedSniff'
);
}

if ( false === $this->thrown['FoundPropertyForDeprecatedSniff'] ) {
if ( ( $this->remove_only === false ) &&
false === $this->thrown['FoundPropertyForDeprecatedSniff'] ) {
$this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning(
'The "WordPress.VIP.AdminBarRemovalSniff" sniff has been deprecated. Please update your custom ruleset.',
'The "WordPress.VIP.AdminBarRemoval" sniff has been deprecated. Please update your custom ruleset.',
0,
'FoundPropertyForDeprecatedSniff'
);
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Sniffs/VIP/CronIntervalSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CronIntervalSniff extends \WordPress\Sniffs\WP\CronIntervalSniff {
);

/**
* Don't use.
* Process the token and handle the deprecation notices.
*
* @deprecated 1.0.0
*
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Sniffs/VIP/DirectDatabaseQuerySniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class DirectDatabaseQuerySniff extends \WordPress\Sniffs\DB\DirectDatabaseQueryS
);

/**
* Don't use.
* Process the token and handle the deprecation notices.
*
* @deprecated 1.0.0
*
Expand Down
8 changes: 4 additions & 4 deletions WordPress/Sniffs/VIP/FileSystemWritesDisallowSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function getGroups() {
}

/**
* This sniff is active, but it's deprecated, handle the deprecation notices
* Process the token and handle the deprecation notices.
*
* @since 1.0.0 Added to allow for throwing the deprecation notices.
*
Expand All @@ -130,17 +130,17 @@ public function getGroups() {
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.',
'The "WordPress.VIP.FileSystemWritesDisallow" sniff has been deprecated. Please update your custom ruleset.',
0,
'DeprecatedSniff'
);
}

if ( ! empty( $this->exclude )
if ( ( ! empty( $this->exclude ) || !empty( $this->error ) )
&& false === $this->thrown['FoundPropertyForDeprecatedSniff']
) {
$this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning(
'The "WordPress.VIP.FileSystemWritesDisallowSniff" sniff has been deprecated. Please update your custom ruleset.',
'The "WordPress.VIP.FileSystemWritesDisallow" sniff has been deprecated. Please update your custom ruleset.',
0,
'FoundPropertyForDeprecatedSniff'
);
Expand Down
6 changes: 3 additions & 3 deletions WordPress/Sniffs/VIP/OrderByRandSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function getGroups() {
}

/**
* This sniff is active, but it's deprecated, handle the deprecation notices
* Process the token and handle the deprecation notices.
*
* @since 1.0.0 Added to allow for throwing the deprecation notices.
*
Expand All @@ -74,7 +74,7 @@ public function getGroups() {
public function process_token( $stackPtr ) {
if ( false === $this->thrown['DeprecatedSniff'] ) {
$this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning(
'The "WordPress.VIP.OrderByRandSniff" sniff has been deprecated. Please update your custom ruleset.',
'The "WordPress.VIP.OrderByRand" sniff has been deprecated. Please update your custom ruleset.',
0,
'DeprecatedSniff'
);
Expand All @@ -84,7 +84,7 @@ public function process_token( $stackPtr ) {
&& false === $this->thrown['FoundPropertyForDeprecatedSniff']
) {
$this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning(
'The "WordPress.VIP.OrderByRandSniff" sniff has been deprecated. Please update your custom ruleset.',
'The "WordPress.VIP.OrderByRand" sniff has been deprecated. Please update your custom ruleset.',
0,
'FoundPropertyForDeprecatedSniff'
);
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Sniffs/VIP/PluginMenuSlugSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class PluginMenuSlugSniff extends \WordPress\Sniffs\Security\PluginMenuSlugSniff
);

/**
* Don't use.
* Process the token and handle the deprecation notices.
*
* @deprecated 1.0.0
*
Expand Down
13 changes: 3 additions & 10 deletions WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@
*/
class RestrictedFunctionsSniff extends AbstractFunctionRestrictionsSniff {

/**
* 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.
Expand Down Expand Up @@ -249,7 +242,7 @@ public function getGroups() {
}

/**
* This sniff is active, but it's deprecated, handle the deprecation notices
* Process the token and handle the deprecation notices.
*
* @since 1.0.0 Added to allow for throwing the deprecation notices.
*
Expand All @@ -260,7 +253,7 @@ public function getGroups() {
public function process_token( $stackPtr ) {
if ( false === $this->thrown['DeprecatedSniff'] ) {
$this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning(
'The "WordPress.VIP.RestrictedFunctionsSniff" sniff has been deprecated. Please update your custom ruleset.',
'The "WordPress.VIP.RestrictedFunctions" sniff has been deprecated. Please update your custom ruleset.',
0,
'DeprecatedSniff'
);
Expand All @@ -270,7 +263,7 @@ public function process_token( $stackPtr ) {
&& false === $this->thrown['FoundPropertyForDeprecatedSniff']
) {
$this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning(
'The "WordPress.VIP.RestrictedFunctionsSniff" sniff has been deprecated. Please update your custom ruleset.',
'The "WordPress.VIP.RestrictedFunctions" sniff has been deprecated. Please update your custom ruleset.',
0,
'FoundPropertyForDeprecatedSniff'
);
Expand Down
13 changes: 3 additions & 10 deletions WordPress/Sniffs/VIP/RestrictedVariablesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@
*/
class RestrictedVariablesSniff extends AbstractVariableRestrictionsSniff {

/**
* 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.
Expand Down Expand Up @@ -89,7 +82,7 @@ public function getGroups() {
}

/**
* This sniff is active, but it's deprecated, handle the deprecation notices
* Process the token and handle the deprecation notices.
*
* @since 1.0.0 Added to allow for throwing the deprecation notices.
*
Expand All @@ -100,7 +93,7 @@ public function getGroups() {
public function process_token( $stackPtr ) {
if ( false === $this->thrown['DeprecatedSniff'] ) {
$this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning(
'The "WordPress.VIP.RestrictedVariablesSniff" sniff has been deprecated. Please update your custom ruleset.',
'The "WordPress.VIP.RestrictedVariables" sniff has been deprecated. Please update your custom ruleset.',
0,
'DeprecatedSniff'
);
Expand All @@ -110,7 +103,7 @@ public function process_token( $stackPtr ) {
&& false === $this->thrown['FoundPropertyForDeprecatedSniff']
) {
$this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning(
'The "WordPress.VIP.RestrictedVariablesSniff" sniff has been deprecated. Please update your custom ruleset.',
'The "WordPress.VIP.RestrictedVariables" sniff has been deprecated. Please update your custom ruleset.',
0,
'FoundPropertyForDeprecatedSniff'
);
Expand Down
13 changes: 3 additions & 10 deletions WordPress/Sniffs/VIP/SessionFunctionsUsageSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@
*/
class SessionFunctionsUsageSniff extends AbstractFunctionRestrictionsSniff {

/**
* 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.
Expand Down Expand Up @@ -100,7 +93,7 @@ public function getGroups() {


/**
* This sniff is active, but it's deprecated, handle the deprecation notices
* Process the token and handle the deprecation notices.
*
* @since 1.0.0 Added to allow for throwing the deprecation notices.
*
Expand All @@ -111,7 +104,7 @@ public function getGroups() {
public function process_token( $stackPtr ) {
if ( false === $this->thrown['DeprecatedSniff'] ) {
$this->thrown['DeprecatedSniff'] = $this->phpcsFile->addWarning(
'The "WordPress.VIP.SessionFunctionsUsageSniff" sniff has been deprecated. Please update your custom ruleset.',
'The "WordPress.VIP.SessionFunctionsUsage" sniff has been deprecated. Please update your custom ruleset.',
0,
'DeprecatedSniff'
);
Expand All @@ -121,7 +114,7 @@ public function process_token( $stackPtr ) {
&& false === $this->thrown['FoundPropertyForDeprecatedSniff']
) {
$this->thrown['FoundPropertyForDeprecatedSniff'] = $this->phpcsFile->addWarning(
'The "WordPress.VIP.SessionFunctionsUsageSniff" sniff has been deprecated. Please update your custom ruleset.',
'The "WordPress.VIP.SessionFunctionsUsage" sniff has been deprecated. Please update your custom ruleset.',
0,
'FoundPropertyForDeprecatedSniff'
);
Expand Down
22 changes: 2 additions & 20 deletions WordPress/Sniffs/VIP/SessionVariableUsageSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@
*/
class SessionVariableUsageSniff 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.
Expand All @@ -47,7 +40,6 @@ class SessionVariableUsageSniff extends Sniff {
*/
private $thrown = array(
'DeprecatedSniff' => false,
'FoundPropertyForDeprecatedSniff' => false,
);

/**
Expand All @@ -62,7 +54,7 @@ public function register() {
}

/**
* Processes this test, when one of its tokens is encountered.
* Process the token and handle the deprecation notices.
*
* @param int $stackPtr The position of the current token in the stack.
*
Expand All @@ -71,22 +63,12 @@ public function register() {
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.',
'The "WordPress.VIP.SessionVariableUsage" 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'
);
}

if ( '$_SESSION' === $this->tokens[ $stackPtr ]['content'] ) {
$this->phpcsFile->addError(
'Usage of $_SESSION variable is prohibited.',
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Sniffs/VIP/SlowDBQuerySniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SlowDBQuerySniff extends \WordPress\Sniffs\DB\SlowDBQuerySniff {
);

/**
* Don't use.
* Process the token and handle the deprecation notices.
*
* @deprecated 1.0.0
*
Expand Down
Loading

0 comments on commit f1bbf24

Please sign in to comment.