Skip to content

Commit 387f0b5

Browse files
committed
Update ignore code duplication
1 parent 85d7477 commit 387f0b5

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

HM/Sniffs/ExtraSniffCode.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace HM\Sniffs;
44

5+
use PHP_CodeSniffer\Files\File as PhpcsFile;
56
use PHP_CodeSniffer\Util;
67

78
trait ExtraSniffCode {
@@ -11,13 +12,14 @@ trait ExtraSniffCode {
1112
* This allows overriding an existing sniff and retaining the existing
1213
* ignore statements.
1314
*
15+
* @param PhpcsFile $file File being checked.
1416
* @param string $legacy Legacy sniff code
1517
*/
16-
protected function duplicate_ignores( $legacy ) {
18+
protected function duplicate_ignores( PhpcsFile $file, $legacy ) {
1719
$expression = sprintf( '/^%s(\..+)?$/', preg_quote( $legacy ) );
1820
$base_code = Util\Common::getSniffCode( get_class( $this ) );
1921

20-
foreach ( $this->phpcsFile->tokenizer->ignoredLines as $line => $ignored ) {
22+
foreach ( $file->tokenizer->ignoredLines as $line => $ignored ) {
2123
$additional = [];
2224

2325
if ( empty( $ignored ) ) {
@@ -38,7 +40,7 @@ protected function duplicate_ignores( $legacy ) {
3840
}
3941

4042
if ( ! empty( $additional ) ) {
41-
$this->phpcsFile->tokenizer->ignoredLines[ $line ] = array_merge( $ignored, $additional );
43+
$file->tokenizer->ignoredLines[ $line ] = array_merge( $ignored, $additional );
4244
}
4345
}
4446

HM/Sniffs/Security/EscapeOutputSniff.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ public function __construct() {
5656
}
5757

5858
/**
59-
* Override init to duplicate any ignores.
59+
* Override process to duplicate any ignores.
6060
*
61-
* @param PhpcsFile $phpcsFile
61+
* @param PhpcsFile $file
62+
* @param int $stackPtr
6263
*/
63-
protected function init( PhpcsFile $phpcsFile ) {
64-
parent::init( $phpcsFile );
65-
66-
$this->duplicate_ignores( 'WordPress.Security.EscapeOutput' );
64+
public function process( PhpcsFile $file, $stackPtr ) {
65+
$this->duplicate_ignores( $file, 'WordPress.Security.EscapeOutput' );
66+
return parent::process( $file, $stackPtr );
6767
}
6868
}

HM/Sniffs/Security/NonceVerificationSniff.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ class NonceVerificationSniff extends WPCSNonceVerificationSniff {
2727
public $allowQueryVariables = false;
2828

2929
/**
30-
* Override init to override config and duplicate any ignores.
30+
* Override process to override config and duplicate any ignores.
3131
*
3232
* @param PhpcsFile $phpcsFile
33+
* @param int $stackPtr
3334
*/
34-
public function init( PhpcsFile $file ) {
35-
parent::init( $file );
36-
35+
public function process( PhpcsFile $file, $stackPtr ) {
3736
if ( $this->allowQueryVariables ) {
3837
unset( $this->superglobals[ '$_GET' ] );
3938
}
4039

41-
$this->duplicate_ignores( 'WordPress.Security.NonceVerification' );
40+
$this->duplicate_ignores( $file, 'WordPress.Security.NonceVerification' );
41+
return parent::process( $file, $stackPtr );
4242
}
4343
}

HM/Sniffs/Security/ValidatedSanitizedInputSniff.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ class ValidatedSanitizedInputSniff extends WPCSValidatedSanitizedInputSniff {
3636
];
3737

3838
/**
39-
* Override init to duplicate any ignores.
39+
* Override process to duplicate any ignores.
4040
*
4141
* @param PhpcsFile $phpcsFile
42+
* @param int $stackPtr
4243
*/
43-
protected function init( PhpcsFile $phpcsFile ) {
44-
parent::init( $phpcsFile );
45-
46-
$this->duplicate_ignores( 'WordPress.Security.ValidatedSanitizedInput' );
44+
public function process( PhpcsFile $file, $stackPtr ) {
45+
$this->duplicate_ignores( $file, 'WordPress.Security.ValidatedSanitizedInput' );
46+
return parent::process( $file, $stackPtr );
4747
}
4848

4949
/**

0 commit comments

Comments
 (0)