annotate vendor/squizlabs/php_codesniffer/src/Sniffs/Sniff.php @ 5:12f9dff5fda9 tip

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