Chris@17: Chris@17: * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) Chris@17: * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence Chris@17: */ Chris@17: Chris@17: namespace PHP_CodeSniffer\Sniffs; Chris@17: Chris@17: use PHP_CodeSniffer\Files\File; Chris@17: Chris@17: interface Sniff Chris@17: { Chris@17: Chris@17: Chris@17: /** Chris@17: * Registers the tokens that this sniff wants to listen for. Chris@17: * Chris@17: * An example return value for a sniff that wants to listen for whitespace Chris@17: * and any comments would be: Chris@17: * Chris@17: * Chris@17: * return array( Chris@17: * T_WHITESPACE, Chris@17: * T_DOC_COMMENT, Chris@17: * T_COMMENT, Chris@17: * ); Chris@17: * Chris@17: * Chris@18: * @return mixed[] Chris@17: * @see Tokens.php Chris@17: */ Chris@17: public function register(); Chris@17: Chris@17: Chris@17: /** Chris@17: * Called when one of the token types that this sniff is listening for Chris@17: * is found. Chris@17: * Chris@17: * The stackPtr variable indicates where in the stack the token was found. Chris@17: * A sniff can acquire information this token, along with all the other Chris@17: * tokens within the stack by first acquiring the token stack: Chris@17: * Chris@17: * Chris@17: * $tokens = $phpcsFile->getTokens(); Chris@17: * echo 'Encountered a '.$tokens[$stackPtr]['type'].' token'; Chris@17: * echo 'token information: '; Chris@17: * print_r($tokens[$stackPtr]); Chris@17: * Chris@17: * Chris@17: * If the sniff discovers an anomaly in the code, they can raise an error Chris@17: * by calling addError() on the \PHP_CodeSniffer\Files\File object, specifying an error Chris@17: * message and the position of the offending token: Chris@17: * Chris@17: * Chris@17: * $phpcsFile->addError('Encountered an error', $stackPtr); Chris@17: * Chris@17: * Chris@17: * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where the Chris@17: * token was found. Chris@17: * @param int $stackPtr The position in the PHP_CodeSniffer Chris@17: * file's token stack where the token Chris@17: * was found. Chris@17: * Chris@17: * @return void|int Optionally returns a stack pointer. The sniff will not be Chris@17: * called again on the current file until the returned stack Chris@17: * pointer is reached. Return (count($tokens) + 1) to skip Chris@17: * the rest of the file. Chris@17: */ Chris@17: public function process(File $phpcsFile, $stackPtr); Chris@17: Chris@17: Chris@17: }//end interface