Skip to content

Commit 56b6785

Browse files
rodrigoprimojrfnl
authored andcommitted
Generic/CamelCapsFunctionName: improve inline documentation
* This sniff only listens to `T_FUNCTION`. It does not listen to `T_FN` or `T_CLOSURE`. So the inline code comments were incorrect. The if conditions are still valid to bail early when live coding, but they do not ever apply to closures or arrow functions (anymore - it was possible in the past though). * The inline comments regarding leading underscores was inaccurate as the code removes all leading underscores, not just the first.
1 parent 0f5680a commit 56b6785

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
113113

114114
$methodName = $phpcsFile->getDeclarationName($stackPtr);
115115
if ($methodName === null) {
116-
// Ignore closures.
116+
// Live coding or parse error. Bow out.
117117
return;
118118
}
119119

@@ -150,7 +150,7 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
150150
return;
151151
}
152152

153-
// Ignore first underscore in methods prefixed with "_".
153+
// Ignore leading underscores in the method name.
154154
$methodName = ltrim($methodName, '_');
155155

156156
$methodProps = $phpcsFile->getMethodProperties($stackPtr);
@@ -189,7 +189,7 @@ protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
189189
{
190190
$functionName = $phpcsFile->getDeclarationName($stackPtr);
191191
if ($functionName === null) {
192-
// Ignore closures.
192+
// Live coding or parse error. Bow out.
193193
return;
194194
}
195195

@@ -206,7 +206,7 @@ protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
206206
$phpcsFile->addError($error, $stackPtr, 'FunctionDoubleUnderscore', $errorData);
207207
}
208208

209-
// Ignore first underscore in functions prefixed with "_".
209+
// Ignore leading underscores in the method name.
210210
$functionName = ltrim($functionName, '_');
211211

212212
if (Common::isCamelCaps($functionName, false, true, $this->strict) === false) {

0 commit comments

Comments
 (0)