/**
* Processes the tokens within the scope.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being processed.
* @param int $stackPtr The position where this token was
* found.
* @param int $currScope The position of the current scope.
*
* @return void
*/
protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
{
$methodName = $phpcsFile->getDeclarationName($stackPtr);
if ($methodName === null) {
// Ignore closures.
return;
}
$className = $phpcsFile->getDeclarationName($currScope);
$errorData = array($className . '::' . $methodName);
// Is this a magic method. IE. is prefixed with "__".
if (preg_match('|^__|', $methodName) !== 0) {
$magicPart = substr($methodName, 2);
if (in_array($magicPart, $this->magicMethods) === false) {
$error = 'Method name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
$phpcsFile->addError($error, $stackPtr, 'MethodDoubleUnderscore', $errorData);
}
return;
}
$methodProps = $phpcsFile->getMethodProperties($stackPtr);
$scope = $methodProps['scope'];
$scopeSpecified = $methodProps['scope_specified'];
// Methods should not contain underscores.
if (strpos($methodName, '_') !== false) {
if ($scopeSpecified === true) {
$error = '%s method name "%s" is not in lowerCamel format, it must not contain underscores';
$data = array(ucfirst($scope), $errorData[0]);
$phpcsFile->addError($error, $stackPtr, 'ScopeNotLowerCamel', $data);
} else {
$error = 'Method name "%s" is not in lowerCamel format, it must not contain underscores';
$phpcsFile->addError($error, $stackPtr, 'NotLowerCamel', $errorData);
}
}
}