Skip to content

Commit 66837c3

Browse files
rodrigoprimojrfnl
authored andcommitted
Generic/UpperCaseConstantName: fix attributes false positive
This commit fixes false positives in the sniff when handling attributes called `define`. Before this change the sniff was not taking into account that `define` is a valid name for an attribute, and it would incorrectly handle these cases as calls to the `define()` function.
1 parent fb13110 commit 66837c3

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ public function process(File $phpcsFile, $stackPtr)
9696
return;
9797
}
9898

99+
// Make sure this is not an attribute.
100+
if (empty($tokens[$stackPtr]['nested_attributes']) === false) {
101+
return;
102+
}
103+
99104
// If the next non-whitespace token after this token
100105
// is not an opening parenthesis then it is not a function call.
101106
$openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,12 @@ $foo?->
5858
define('bar');
5959

6060
const DEFINE = 'value';
61+
62+
#[Define('some param')]
63+
class MyClass {}
64+
65+
#[
66+
AttributeA,
67+
define('some param')
68+
]
69+
class MyClass {}

0 commit comments

Comments
 (0)