Skip to content

Commit 2e68850

Browse files
rodrigoprimojrfnl
authored andcommitted
Generic/UpperCaseConstantName: findNext() may return false
This commit takes into account that `findNext()` may return `false` and properly handles this case in the modified `if` condition. There were no issues without this extra check, as when `$constPtr` is `false`, `$tokens[$constPrt]` evaluates to the first token in the stack and the first token can never be `T_CONSTANT_ENCAPSED_STRING`, so the sniff would bail early anyway.
1 parent 17b9164 commit 2e68850

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

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

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

111111
// The next non-empty token must be the constant name.
112112
$constPtr = $phpcsFile->findNext(Tokens::$emptyTokens, ($openBracket + 1), null, true);
113-
if ($tokens[$constPtr]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
113+
if ($constPtr === false || $tokens[$constPtr]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
114114
return;
115115
}
116116

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// Intentional parse error (missing constant name).
4+
// This should be the only test in this file.
5+
// Testing that the sniff is *not* triggered.
6+
7+
define(

0 commit comments

Comments
 (0)