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