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