Subversion Repositories Applications.framework

Rev

Rev 5 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5 aurelien 1
<?php
2
/**
3
 * Generic_Sniffs_WhiteSpace_DisallowTabIndentSniff.
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: DisallowTabIndentSniff.php 34 2009-04-09 07:34:39Z aurelien $
5 aurelien 14
 * @link      http://pear.php.net/package/PHP_CodeSniffer
15
 */
16
 
17
/**
18
 * Generic_Sniffs_WhiteSpace_DisallowTabIndentSniff.
19
 *
20
 * Throws errors if tabs are used for indentation.
21
 *
22
 * @category  PHP
23
 * @package   PHP_CodeSniffer
24
 * @author    Greg Sherwood <gsherwood@squiz.net>
25
 * @author    Marc McIntyre <mmcintyre@squiz.net>
26
 * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
27
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
28
 * @version   Release: 1.2.0RC1
29
 * @link      http://pear.php.net/package/PHP_CodeSniffer
30
 */
31
class Generic_Sniffs_WhiteSpace_DisallowTabIndentSniff implements PHP_CodeSniffer_Sniff
32
{
33
 
34
    /**
35
     * A list of tokenizers this sniff supports.
36
     *
37
     * @var array
38
     */
39
    public $supportedTokenizers = array(
40
                                   'PHP',
41
                                   'JS',
42
                                   'CSS',
43
                                  );
44
 
45
 
46
    /**
47
     * Returns an array of tokens this test wants to listen for.
48
     *
49
     * @return array
50
     */
51
    public function register()
52
    {
53
        return array(T_WHITESPACE);
54
 
55
    }//end register()
56
 
57
 
58
    /**
59
     * Processes this test, when one of its tokens is encountered.
60
     *
61
     * @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document.
62
     * @param int                  $stackPtr  The position of the current token in
63
     *                                        the stack passed in $tokens.
64
     *
65
     * @return void
66
     */
67
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
68
    {
69
        $tokens = $phpcsFile->getTokens();
70
 
71
        // Make sure this is whitespace used for indentation.
72
        $line = $tokens[$stackPtr]['line'];
73
        if ($stackPtr > 0 && $tokens[($stackPtr - 1)]['line'] === $line) {
74
            return;
75
        }
76
 
77
        if (strpos($tokens[$stackPtr]['content'], "\t") !== false) {
78
            $error = 'Spaces must be used to indent lines; tabs are not allowed';
79
            $phpcsFile->addError($error, $stackPtr);
80
        }
81
 
82
    }//end process()
83
 
84
 
85
}//end class
86
 
87
?>