Skip to content

Commit 5610c58

Browse files
committed
Adjusting Warning and Error names in Sniffs in order to make namespaced tests working
1 parent f53549c commit 5610c58

21 files changed

+20
-81
lines changed

WordPressVIPMinimum/Sniffs/Actions/PreGetPostsSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,10 @@ private function processFunctionBody( $stackPtr, $variableName ) {
249249
}
250250
} elseif ( $this->isInsideIfConditonal( $wpQueryVarUsed ) ) {
251251
if ( ! $this->isParentConditionalCheckingMainQuery( $wpQueryVarUsed ) ) {
252-
$this->_phpcsFile->addWarning( 'Main WP_Query is being modified without $query->is_main_query() check. Needs manual inspection.', $wpQueryVarUsed, 'WordPressVIPMinimum.Actions.PreGetPosts' );
252+
$this->_phpcsFile->addWarning( 'Main WP_Query is being modified without $query->is_main_query() check. Needs manual inspection.', $wpQueryVarUsed, 'PreGetPosts' );
253253
}
254254
} elseif ( $this->isWPQueryMethodCall( $wpQueryVarUsed, 'set' ) ) {
255-
$this->_phpcsFile->addWarning( 'Main WP_Query is being modified without $query->is_main_query() check. Needs manual inspection.', $wpQueryVarUsed, 'WordPressVIPMinimum.Actions.PreGetPosts' );
255+
$this->_phpcsFile->addWarning( 'Main WP_Query is being modified without $query->is_main_query() check. Needs manual inspection.', $wpQueryVarUsed, 'PreGetPosts' );
256256
}
257257
$findStart = $wpQueryVarUsed + 1;
258258
}

WordPressVIPMinimum/Sniffs/Cache/CacheValueOverrideSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function process( File $phpcsFile, $stackPtr ) {
9797
$valueAfterEqualSign = $phpcsFile->findNext( Tokens::$emptyTokens, ($rightAfterNextVariableOccurence + 1), null, true, null, true );
9898

9999
if ( T_FALSE === $tokens[ $valueAfterEqualSign ]['code'] ) {
100-
$phpcsFile->addError( sprintf( 'Obtained cached value in %s is being overriden. Disabling caching?', $variableName ), $nextVariableOccurrence, 'WordPressVIPMinimum.Cache.CacheValueOverride' );
100+
$phpcsFile->addError( sprintf( 'Obtained cached value in %s is being overriden. Disabling caching?', $variableName ), $nextVariableOccurrence, 'CacheValueOverride' );
101101
}
102102

103103
} //end Process()

WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ private function addError( $parentClassName, $methodName, $currentMethodSignatur
303303

304304
$parentSignature = sprintf( '%s::%s(%s)', $parentClassName, $methodName, implode( ', ', $this->generateParamList( $parentMethodSignature ) ) );
305305

306-
$phpcsFile->addError( sprintf( 'Declaration of %s should be compatible with %s', $currentSignature, $parentSignature ), $stackPtr, 'WordPressVIPMinimum.Classes.DeclarationCompatibility' );
306+
$phpcsFile->addError( sprintf( 'Declaration of %s should be compatible with %s', $currentSignature, $parentSignature ), $stackPtr, 'DeclarationCompatibility' );
307307
}//end addError()
308308

309309
/**

WordPressVIPMinimum/Sniffs/Constants/ConstantRestrictionsSniff.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function process( File $phpcsFile, $stackPtr ) {
6363
}
6464

6565
if ( T_STRING === $tokens[ $stackPtr ]['code'] ) {
66-
$phpcsFile->addWarning( sprintf( 'Code is touching the %s constant. Make sure it\'s used appropriately.', $constantName ), $stackPtr, 'WordPressVIPMinimum.Constants.ConstantRestrictions' );
66+
$phpcsFile->addWarning( sprintf( 'Code is touching the %s constant. Make sure it\'s used appropriately.', $constantName ), $stackPtr, 'ConstantRestrictions' );
6767
return;
6868
}
6969

@@ -91,9 +91,9 @@ public function process( File $phpcsFile, $stackPtr ) {
9191

9292
if ( true === in_array( $tokens[ $previous ]['code'], Tokens::$functionNameTokens, true ) ) {
9393
if ( 'define' === $tokens[ $previous ]['content'] ) {
94-
$phpcsFile->addError( sprintf( 'The definition of %s constant is prohibited. Please use a different name.', $constantName ), $previous, 'WordPressVIPMinimum.Constants.ConstantRestrictions' );
94+
$phpcsFile->addError( sprintf( 'The definition of %s constant is prohibited. Please use a different name.', $constantName ), $previous, 'ConstantRestrictions' );
9595
} else {
96-
$phpcsFile->addWarning( sprintf( 'Code is touching the %s constant. Make sure it\'s used appropriately.', $constantName ), $previous, 'WordPressVIPMinimum.Constants.ConstantRestrictions' );
96+
$phpcsFile->addWarning( sprintf( 'Code is touching the %s constant. Make sure it\'s used appropriately.', $constantName ), $previous, 'ConstantRestrictions' );
9797
}
9898
}
9999
}

WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function process( File $phpcsFile, $stackPtr ) {
100100
}
101101

102102
if ( T_VARIABLE === $tokens[ $nextToken ]['code'] ) {
103-
$phpcsFile->addWarning( sprintf( 'File inclusion using variable (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'WordPressVIPMinimum.Files.IncludingFile' );
103+
$phpcsFile->addWarning( sprintf( 'File inclusion using variable (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'IncludingFile' );
104104
return;
105105
}
106106

@@ -124,12 +124,12 @@ public function process( File $phpcsFile, $stackPtr ) {
124124

125125
if ( 1 === preg_match( '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $tokens[ $nextToken ]['content'] ) ) {
126126
// The construct is using custom constant, which needs manula inspection.
127-
$phpcsFile->addWarning( sprintf( 'File inclusion using custom constant (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'WordPressVIPMinimum.Files.IncludingFile' );
127+
$phpcsFile->addWarning( sprintf( 'File inclusion using custom constant (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'IncludingFile' );
128128
return;
129129
}
130130

131131
if ( 0 === strpos( $tokens[ $nextToken ]['content'], '$' ) ) {
132-
$phpcsFile->addWarning( sprintf( 'File inclusion using variable (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'WordPressVIPMinimum.Files.IncludingFile' );
132+
$phpcsFile->addWarning( sprintf( 'File inclusion using variable (%s). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'IncludingFile' );
133133
return;
134134
}
135135

@@ -140,14 +140,14 @@ public function process( File $phpcsFile, $stackPtr ) {
140140

141141
$nextNextToken = $phpcsFile->findNext( Tokens::$emptyTokens, ($nextToken + 1), null, true, null, true );
142142
if ( T_OPEN_PARENTHESIS === $tokens[ $nextNextToken ]['code'] ) {
143-
$phpcsFile->addWarning( sprintf( 'File inclusion using custom function ( %s() ). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'WordPressVIPMinimum.Files.IncludingFile' );
143+
$phpcsFile->addWarning( sprintf( 'File inclusion using custom function ( %s() ). Probably needs manual inspection.', $tokens[ $nextToken ]['content'] ), $nextToken, 'IncludingFile' );
144144
return;
145145
}
146146

147-
$phpcsFile->addError( 'Absolute include path must be used. Use get_template_directory, get_stylesheet_directory or plugin_dir_path.', $nextToken, 'WordPressVIPMinimum.Files.IncludingFile' );
147+
$phpcsFile->addError( 'Absolute include path must be used. Use get_template_directory, get_stylesheet_directory or plugin_dir_path.', $nextToken, 'IncludingFile' );
148148
return;
149149
} else {
150-
$phpcsFile->addError( 'Absolute include path must be used. Use get_template_directory, get_stylesheet_directory or plugin_dir_path.', $nextToken, 'WordPressVIPMinimum.Files.IncludingFile' );
150+
$phpcsFile->addError( 'Absolute include path must be used. Use get_template_directory, get_stylesheet_directory or plugin_dir_path.', $nextToken, 'IncludingFile' );
151151
return;
152152
}// End if().
153153

WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function findDirectFunctionCalls( $stackPtr ) {
190190
$startNext = $openBracket + 1;
191191
while ( $next = $phpcsFile->findNext( Tokens::$functionNameTokens, $startNext, $closeBracket, false, null, true ) ) {
192192
if ( true === in_array( $tokens[ $next ]['content'], $this->catch[ $functionName ], true ) ) {
193-
$phpcsFile->addError( sprintf( "%s's return type must be checked before calling %s using that value", $tokens[ $next ]['content'], $functionName ), $next, 'WordPressVIPMinimum.Functions.CheckReturnValue' );
193+
$phpcsFile->addError( sprintf( "%s's return type must be checked before calling %s using that value", $tokens[ $next ]['content'], $functionName ), $next, 'CheckReturnValue' );
194194
}
195195
$startNext = $next + 1;
196196
}
@@ -298,7 +298,7 @@ public function findNonCheckedVariables( $stackPtr ) {
298298
if ( true === in_array( $tokens[ $nextFunctionCallWithVariable ]['code'], array_merge( Tokens::$functionNameTokens, $notFunctionsCallee ), true )
299299
&& $tokens[ $nextFunctionCallWithVariable ]['content'] === $callee
300300
) {
301-
$phpcsFile->addError( sprintf( 'Type of %s must be checked before calling %s using that variable', $variableName, $callee ), $nextFunctionCallWithVariable, 'WordPressVIPMinimum.Functions.CheckReturnValue' );
301+
$phpcsFile->addError( sprintf( 'Type of %s must be checked before calling %s using that variable', $variableName, $callee ), $nextFunctionCallWithVariable, 'CheckReturnValue' );
302302
return;
303303
}
304304

@@ -307,7 +307,7 @@ public function findNonCheckedVariables( $stackPtr ) {
307307
if ( true === in_array( $tokens[ $next ]['code'], Tokens::$functionNameTokens, true )
308308
&& $tokens[ $next ]['content'] === $callee
309309
) {
310-
$phpcsFile->addError( sprintf( 'Type of %s must be checked before calling %s using that variable', $variableName, $callee ), $next, 'WordPressVIPMinimum.Functions.CheckReturnValue' );
310+
$phpcsFile->addError( sprintf( 'Type of %s must be checked before calling %s using that variable', $variableName, $callee ), $next, 'CheckReturnValue' );
311311
return;
312312
}
313313
}

WordPressVIPMinimum/Sniffs/VIP/ErrorControlSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function process( File $phpcsFile, $stackPtr ) {
4040

4141
$tokens = $phpcsFile->getTokens();
4242

43-
$phpcsFile->addError( sprintf( 'The code shouldn\'t use error control operators (%s). The call should be wrapped in appropriate checks.', $tokens[ $stackPtr ]['content'] ), $stackPtr, 'WordPressVIPMinimum.VIP.ErrorControl' );
43+
$phpcsFile->addError( sprintf( 'The code shouldn\'t use error control operators (%s). The call should be wrapped in appropriate checks.', $tokens[ $stackPtr ]['content'] ), $stackPtr, 'ErrorControl' );
4444
}
4545

4646
}

WordPressVIPMinimum/Sniffs/VIP/FlushRewriteRulesSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function process( File $phpcsFile, $stackPtr ) {
8989
return;
9090
}
9191

92-
$phpcsFile->addError( sprintf( '%s should not be used in any normal circumstances in the theme code.', $tokens[ $stackPtr ]['content'] ), $stackPtr, 'WordPressVIPMinimum.VIP.FlushRewriteRules' );
92+
$phpcsFile->addError( sprintf( '%s should not be used in any normal circumstances in the theme code.', $tokens[ $stackPtr ]['content'] ), $stackPtr, 'FlushRewriteRules' );
9393
}
9494

9595
}

WordPressVIPMinimum/Sniffs/VIP/StaticStrreplaceSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ public function process( File $phpcsFile, $stackPtr ) {
8282

8383
}
8484

85-
$phpcsFile->addError( sprintf( 'This code pattern is often used to run a very dangerous shell programs on your server. The code in these files needs to be reviewed, and possibly cleaned.', $tokens[ $stackPtr ]['content'] ), $stackPtr, 'WordPressVIPMinimum.VIP.StaticStrreplace' );
85+
$phpcsFile->addError( sprintf( 'This code pattern is often used to run a very dangerous shell programs on your server. The code in these files needs to be reviewed, and possibly cleaned.', $tokens[ $stackPtr ]['content'] ), $stackPtr, 'StaticStrreplace' );
8686
}//end process()
8787
}

WordPressVIPMinimum/Tests/Actions/PreGetPostsUnitTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,12 @@
99

1010
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
1111

12-
// Cross version compatibility for PHPCS 2.x and 3.x.
13-
if ( ! class_exists( '\AbstractSniffUnitTest' ) ) {
14-
class_alias( '\PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest', '\AbstractSniffUnitTest' );
15-
}
16-
1712
/**
1813
* Unit test class for the PreGetPosts sniff.
1914
*
2015
* @package VIPCS\WordPressVIPMinimum
2116
*/
22-
class WordPressVIPMinimum_Tests_Actions_PreGetPostsUnitTest extends AbstractSniffUnitTest {
17+
class PreGetPostsUnitTest extends AbstractSniffUnitTest {
2318

2419
/**
2520
* Returns the lines where errors should occur.

0 commit comments

Comments
 (0)