comparison vendor/squizlabs/php_codesniffer/src/Sniffs/Sniff.php @ 17:129ea1e6d783

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