Skip to content

Commit d129e9b

Browse files
rodrigoprimojrfnl
authored andcommitted
Generic/UpperCaseConstantName: remove special case for double-colon
In early versions of this sniff, constant names were checked not only when defined, but also when used. At that time, code was added to handle the dynamic retrieval of class constants in calls to `constant()` by checking if the constant name contained a double-colon (see squizlabs/PHP_CodeSniffer@610b0cc and https://pear.php.net/bugs/bug.php?id=18670). If so, the sniff would enforce upper case only for the substring after the double-colon. Later, another commit removed support for constant usage (squizlabs/PHP_CodeSniffer@4af13118b1fedd89faadd78b9bc and https://pear.php.net/bugs/bug.php?id=20090). It seems to me that the code that is removed in this commit, should have been removed when support for constant usage was removed. The removed code is only triggered when a constant is defined using `define()`. As far as I can tell, over time, PHP changed how it behaves when a double-colon is passed as part of the first parameter of `define()`. However, never in a way that justifies special treatment in the context of this sniff (https://3v4l.org/erZcK). At least not since PHP 5.0 (I'm assuming it is not needed to check PHP 4).
1 parent 0ac027f commit d129e9b

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,7 @@ public function process(File $phpcsFile, $stackPtr)
115115
}
116116

117117
$constName = $tokens[$constPtr]['content'];
118-
119-
// Check for constants like self::CONSTANT.
120-
$prefix = '';
121-
$splitPos = strpos($constName, '::');
122-
if ($splitPos !== false) {
123-
$prefix = substr($constName, 0, ($splitPos + 2));
124-
$constName = substr($constName, ($splitPos + 2));
125-
}
118+
$prefix = '';
126119

127120
// Strip namespace from constant like /foo/bar/CONSTANT.
128121
$splitPos = strrpos($constName, '\\');

0 commit comments

Comments
 (0)