function CamelCapsMethodNameSniff::processTokenWithinScope
Processes the tokens within the scope.
Parameters
\PHP_CodeSniffer\Files\File $phpcsFile The file being processed.:
int $stackPtr The position where this token was: found.
int $currScope The position of the current scope.:
Return value
void
Overrides CamelCapsFunctionNameSniff::processTokenWithinScope
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Standards/ PSR1/ Sniffs/ Methods/ CamelCapsMethodNameSniff.php, line 30
Class
Namespace
PHP_CodeSniffer\Standards\PSR1\Sniffs\MethodsCode
protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope) {
$tokens = $phpcsFile->getTokens();
// Determine if this is a function which needs to be examined.
$conditions = $tokens[$stackPtr]['conditions'];
end($conditions);
$deepestScope = key($conditions);
if ($deepestScope !== $currScope) {
return;
}
$methodName = $phpcsFile->getDeclarationName($stackPtr);
if ($methodName === null) {
// Ignore closures.
return;
}
// Ignore magic methods.
if (preg_match('|^__[^_]|', $methodName) !== 0) {
$magicPart = strtolower(substr($methodName, 2));
if (isset($this->magicMethods[$magicPart]) === true || isset($this->methodsDoubleUnderscore[$magicPart]) === true) {
return;
}
}
$testName = ltrim($methodName, '_');
if ($testName !== '' && Common::isCamelCaps($testName, false, true, false) === false) {
$error = 'Method name "%s" is not in camel caps format';
$className = $phpcsFile->getDeclarationName($currScope);
if (isset($className) === false) {
$className = '[Anonymous Class]';
}
$errorData = [
$className . '::' . $methodName,
];
$phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData);
$phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'no');
}
else {
$phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes');
}
}