Skip to content

Commit fb13110

Browse files
rodrigoprimojrfnl
authored andcommitted
Generic/UpperCaseConstantName: false positives when constant name is "DEFINE"
This commit fixes false positives when the sniff encounters a constant named "DEFINE". When looking for calls to `define()`, the code was checking only if there was a non-empty token after `define`. Instead, it should check if the next non-empty token after `define` is `T_OPEN_PARENTHESIS`.
1 parent 67ae154 commit fb13110

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/Standards/Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function process(File $phpcsFile, $stackPtr)
9999
// If the next non-whitespace token after this token
100100
// is not an opening parenthesis then it is not a function call.
101101
$openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
102-
if ($openBracket === false) {
102+
if ($openBracket === false || $tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
103103
return;
104104
}
105105

src/Standards/Generic/Tests/NamingConventions/UpperCaseConstantNameUnitTest.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,5 @@ $foo-> /* comment */ define('bar');
5656
$foo?->
5757
// phpcs:ignore Stnd.Cat.SniffName -- for reasons.
5858
define('bar');
59+
60+
const DEFINE = 'value';

0 commit comments

Comments
 (0)