annotate vendor/squizlabs/php_codesniffer/src/Sniffs/Sniff.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@17 1 <?php
Chris@17 2 /**
Chris@17 3 * Represents a PHP_CodeSniffer sniff for sniffing coding standards.
Chris@17 4 *
Chris@17 5 * A sniff registers what token types it wishes to listen for, then, when
Chris@17 6 * PHP_CodeSniffer encounters that token, the sniff is invoked and passed
Chris@17 7 * information about where the token was found in the stack, and the
Chris@17 8 * PHP_CodeSniffer file in which the token was found.
Chris@17 9 *
Chris@17 10 * @author Greg Sherwood <gsherwood@squiz.net>
Chris@17 11 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
Chris@17 12 * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
Chris@17 13 */
Chris@17 14
Chris@17 15 namespace PHP_CodeSniffer\Sniffs;
Chris@17 16
Chris@17 17 use PHP_CodeSniffer\Files\File;
Chris@17 18
Chris@17 19 interface Sniff
Chris@17 20 {
Chris@17 21
Chris@17 22
Chris@17 23 /**
Chris@17 24 * Registers the tokens that this sniff wants to listen for.
Chris@17 25 *
Chris@17 26 * An example return value for a sniff that wants to listen for whitespace
Chris@17 27 * and any comments would be:
Chris@17 28 *
Chris@17 29 * <code>
Chris@17 30 * return array(
Chris@17 31 * T_WHITESPACE,
Chris@17 32 * T_DOC_COMMENT,
Chris@17 33 * T_COMMENT,
Chris@17 34 * );
Chris@17 35 * </code>
Chris@17 36 *
Chris@18 37 * @return mixed[]
Chris@17 38 * @see Tokens.php
Chris@17 39 */
Chris@17 40 public function register();
Chris@17 41
Chris@17 42
Chris@17 43 /**
Chris@17 44 * Called when one of the token types that this sniff is listening for
Chris@17 45 * is found.
Chris@17 46 *
Chris@17 47 * The stackPtr variable indicates where in the stack the token was found.
Chris@17 48 * A sniff can acquire information this token, along with all the other
Chris@17 49 * tokens within the stack by first acquiring the token stack:
Chris@17 50 *
Chris@17 51 * <code>
Chris@17 52 * $tokens = $phpcsFile->getTokens();
Chris@17 53 * echo 'Encountered a '.$tokens[$stackPtr]['type'].' token';
Chris@17 54 * echo 'token information: ';
Chris@17 55 * print_r($tokens[$stackPtr]);
Chris@17 56 * </code>
Chris@17 57 *
Chris@17 58 * If the sniff discovers an anomaly in the code, they can raise an error
Chris@17 59 * by calling addError() on the \PHP_CodeSniffer\Files\File object, specifying an error
Chris@17 60 * message and the position of the offending token:
Chris@17 61 *
Chris@17 62 * <code>
Chris@17 63 * $phpcsFile->addError('Encountered an error', $stackPtr);
Chris@17 64 * </code>
Chris@17 65 *
Chris@17 66 * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where the
Chris@17 67 * token was found.
Chris@17 68 * @param int $stackPtr The position in the PHP_CodeSniffer
Chris@17 69 * file's token stack where the token
Chris@17 70 * was found.
Chris@17 71 *
Chris@17 72 * @return void|int Optionally returns a stack pointer. The sniff will not be
Chris@17 73 * called again on the current file until the returned stack
Chris@17 74 * pointer is reached. Return (count($tokens) + 1) to skip
Chris@17 75 * the rest of the file.
Chris@17 76 */
Chris@17 77 public function process(File $phpcsFile, $stackPtr);
Chris@17 78
Chris@17 79
Chris@17 80 }//end interface