Skip to content

Commit fe50ba7

Browse files
rodrigoprimojrfnl
authored andcommitted
Generic/UpperCaseConstantName: fix false positive for class instantiation
This commit fixes a false positive that would trigger an error when this sniff encountered the instantiation of a class named `Define`.
1 parent 6080303 commit fe50ba7

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@ public function process(File $phpcsFile, $stackPtr)
8787
return;
8888
}
8989

90-
// Make sure this is not a method call.
90+
// Make sure this is not a method call or class instantiation.
9191
$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
9292
if ($tokens[$prev]['code'] === T_OBJECT_OPERATOR
9393
|| $tokens[$prev]['code'] === T_DOUBLE_COLON
9494
|| $tokens[$prev]['code'] === T_NULLSAFE_OBJECT_OPERATOR
95+
|| $tokens[$prev]['code'] === T_NEW
9596
) {
9697
return;
9798
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,5 @@ class MyClass {
8787
}
8888

8989
$a = ($cond) ? DEFINE : SOMETHING_ELSE;
90+
91+
$object = new Define('value');

0 commit comments

Comments
 (0)