3
* Generic_Sniffs_WhiteSpace_DisallowSpaceIndentSniff.
8
* @package PHP_CodeSniffer
9
* @author Greg Sherwood <gsherwood@squiz.net>
10
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
11
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
12
* @link http://pear.php.net/package/PHP_CodeSniffer
16
* Generic_Sniffs_WhiteSpace_DisallowSpaceIndentSniff.
18
* Throws errors if tabs are used for indentation.
21
* @package PHP_CodeSniffer
22
* @author Greg Sherwood <gsherwood@squiz.net>
23
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
24
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
25
* @version Release: 1.5.0RC2
26
* @link http://pear.php.net/package/PHP_CodeSniffer
28
class Generic_Sniffs_WhiteSpace_DisallowSpaceIndentSniff implements PHP_CodeSniffer_Sniff
32
* A list of tokenizers this sniff supports.
36
public $supportedTokenizers = array(
44
* Returns an array of tokens this test wants to listen for.
48
public function register()
50
return array(T_WHITESPACE);
56
* Processes this test, when one of its tokens is encountered.
58
* @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document.
59
* @param int $stackPtr The position of the current token in
60
* the stack passed in $tokens.
64
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
66
$tokens = $phpcsFile->getTokens();
68
// Make sure this is whitespace used for indentation.
69
$line = $tokens[$stackPtr]['line'];
70
if ($stackPtr > 0 && $tokens[($stackPtr - 1)]['line'] === $line) {
74
if (strpos($tokens[$stackPtr]['content'], ' ') !== false) {
75
// Space are considered ok if they are proceeded by tabs and not followed
76
// by tabs, as is the case with standard docblock comments.
77
$error = 'Tabs must be used to indent lines; spaces are not allowed';
78
$phpcsFile->addError($error, $stackPtr, 'TabsUsed');