AbstractScopeSniff.php
Allows tests that extend this class to listen for tokens within a particular scope.
Below is a test that listens to methods that exist only within classes:
class ClassScopeTest extends PHP_CodeSniffer_Standards_AbstractScopeSniff
{
public function __construct()
{
parent::__construct(array(T_CLASS), array(T_FUNCTION));
}
protected function processTokenWithinScope(\PHP_CodeSniffer\Files\File $phpcsFile, int $stackPtr, int $currScope)
{
$className = $phpcsFile->getDeclarationName($currScope);
$phpcsFile->addWarning('encountered a method within class '.$className, $stackPtr, 'MethodFound');
}
}