Skip to content

Commit

Permalink
deprecated the Admin Bar Removal Sniff
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjn committed Jul 6, 2018
1 parent c1736c2 commit 5fb6bb5
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
5 changes: 5 additions & 0 deletions WordPress-VIP/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@
#############################################################################
-->

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

<!-- Prevent deprecation notice when the sniff is not explicitely included. -->
<rule ref="WordPress.VIP.DirectDatabaseQuery.DeprecatedSniff">
<severity>0</severity>
Expand Down
41 changes: 41 additions & 0 deletions WordPress/Sniffs/VIP/AdminBarRemovalSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,32 @@
* - Added the $remove_only property.
* - Now also sniffs for manipulation of the admin bar visibility through CSS.
* @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 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.
*
* @since 1.0.0
*
* @var array
*/
private $thrown = array(
'DeprecatedSniff' => false,
'FoundPropertyForDeprecatedSniff' => false,
);

/**
* A list of tokenizers this sniff supports.
*
Expand Down Expand Up @@ -171,11 +194,29 @@ public function register() {
*
* @param int $stackPtr The position of the current token in the stack.
*
* @deprecated 1.0.0 Adjusted to allow for throwing the deprecation notices.
*
* @return int|void Integer stack pointer to skip forward or void to continue
* normal file processing.
*/
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.',
0,
'DeprecatedSniff'
);
}

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

$file_name = $this->phpcsFile->getFileName();
$file_extension = substr( strrchr( $file_name, '.' ), 1 );

Expand Down
21 changes: 19 additions & 2 deletions WordPress/Tests/VIP/AdminBarRemovalUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,27 @@ public function getErrorList( $testFile = '' ) {
/**
* Returns the lines where warnings should occur.
*
* @param string $testFile The name of the file being tested.
* @return array <int line number> => <int number of warnings>
*/
public function getWarningList() {
return array();
public function getWarningList( $testFile = '' ) {
switch ( $testFile ) {
case 'AdminBarRemovalUnitTest.css':
return array(
1 => 2,
);

case 'AdminBarRemovalUnitTest.css':
return array(
1 => 1,
);

default:
return array();
}
return array(
1 => 2
);
}

}

0 comments on commit 5fb6bb5

Please sign in to comment.