Documentation

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');
}

}

Tags
author

Greg Sherwood gsherwood@squiz.net

copyright

2006-2023 Squiz Pty Ltd (ABN 77 084 670 600)

copyright

2023 PHPCSStandards and contributors

license

https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/HEAD/licence.txt BSD Licence

Table of Contents

Classes

AbstractScopeSniff

        
On this page

Search results