~ubuntu-branches/ubuntu/trusty/php-codesniffer/trusty

« back to all changes in this revision

Viewing changes to PHP_CodeSniffer-1.5.0RC2/CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php

  • Committer: Package Import Robot
  • Author(s): Thomas Goirand
  • Date: 2013-07-12 15:16:25 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20130712151625-4autdc0twzbueha9
Tags: 1.5.0~rc2-1
* New upstream release.
* Refreshed patch.
* Standards-Version is now 3.9.4.
* Canonical VCS URLs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Generic_Sniffs_WhiteSpace_DisallowSpaceIndentSniff.
 
4
 *
 
5
 * PHP version 5
 
6
 *
 
7
 * @category  PHP
 
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
 
13
 */
 
14
 
 
15
/**
 
16
 * Generic_Sniffs_WhiteSpace_DisallowSpaceIndentSniff.
 
17
 *
 
18
 * Throws errors if tabs are used for indentation.
 
19
 *
 
20
 * @category  PHP
 
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
 
27
 */
 
28
class Generic_Sniffs_WhiteSpace_DisallowSpaceIndentSniff implements PHP_CodeSniffer_Sniff
 
29
{
 
30
 
 
31
    /**
 
32
     * A list of tokenizers this sniff supports.
 
33
     *
 
34
     * @var array
 
35
     */
 
36
    public $supportedTokenizers = array(
 
37
                                   'PHP',
 
38
                                   'JS',
 
39
                                   'CSS',
 
40
                                  );
 
41
 
 
42
 
 
43
    /**
 
44
     * Returns an array of tokens this test wants to listen for.
 
45
     *
 
46
     * @return array
 
47
     */
 
48
    public function register()
 
49
    {
 
50
        return array(T_WHITESPACE);
 
51
 
 
52
    }//end register()
 
53
 
 
54
 
 
55
    /**
 
56
     * Processes this test, when one of its tokens is encountered.
 
57
     *
 
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.
 
61
     *
 
62
     * @return void
 
63
     */
 
64
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
 
65
    {
 
66
        $tokens = $phpcsFile->getTokens();
 
67
 
 
68
        // Make sure this is whitespace used for indentation.
 
69
        $line = $tokens[$stackPtr]['line'];
 
70
        if ($stackPtr > 0 && $tokens[($stackPtr - 1)]['line'] === $line) {
 
71
            return;
 
72
        }
 
73
 
 
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');
 
79
        }
 
80
 
 
81
    }//end process()
 
82
 
 
83
 
 
84
}//end class
 
85
 
 
86
?>