DisallowSpaceIndentSniff   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A process() 0 15 4
1
<?php
2
/**
3
 * CodeIgniter_Sniffs_WhiteSpace_DisallowSpaceIndentSniff.
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PHP_CodeSniffer
9
 * @author    Thomas Ernest <[email protected]>
10
 * @copyright 2011 Thomas ERNEST
11
 * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
12
 * @link      http://pear.php.net/package/PHP_CodeSniffer
13
 */
14
15
/**
16
 * CodeIgniter_Sniffs_WhiteSpace_DisallowSpaceIndentSniff.
17
 *
18
 * Ensures the use of tabs for indentation.
19
 *
20
 * @category  PHP
21
 * @package   PHP_CodeSniffer
22
 * @author    Thomas Ernest <[email protected]>
23
 * @copyright 2011 Thomas ERNEST
24
 * @license   http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
25
 * @link      http://pear.php.net/package/PHP_CodeSniffer
26
 */
27
28
namespace CodeIgniter\Sniffs\WhiteSpace;
29
30
use PHP_CodeSniffer\Sniffs\Sniff;
31
use PHP_CodeSniffer\Files\File;
32
33
class DisallowSpaceIndentSniff implements Sniff
34
{
35
36
    /**
37
     * A list of tokenizers this sniff supports.
38
     *
39
     * @var array
40
     */
41
    public $supportedTokenizers = array(
42
                                   'PHP',
43
                                   'JS',
44
                                   'CSS',
45
                                  );
46
47
48
    /**
49
     * Returns an array of tokens this test wants to listen for.
50
     *
51
     * @return array
52
     */
53
    public function register()
54
    {
55
        return array(T_WHITESPACE);
56
    }//end register()
57
58
59
    /**
60
     * Processes this test, when one of its tokens is encountered.
61
     *
62
     * @param File $phpcsFile All the tokens found in the document.
63
     * @param int                  $stackPtr  The position of the current token
64
     *                                        in the stack passed in $tokens.
65
     *
66
     * @return void
67
     */
68
    public function process(File $phpcsFile, $stackPtr)
69
    {
70
        $tokens = $phpcsFile->getTokens();
71
72
        // Make sure this is whitespace used for indentation.
73
        $line = $tokens[$stackPtr]['line'];
74
        if ($stackPtr > 0 && $tokens[($stackPtr - 1)]['line'] === $line) {
75
            return;
76
        }
77
78
        if (strpos($tokens[$stackPtr]['content'], " ") !== false) {
79
            $error = 'Tabs must be used to indent lines; spaces are not allowed for code indentation';
80
            $phpcsFile->addError($error, $stackPtr, 'SpacesUsedForIndentation');
81
        }
82
    }//end process()
83
84
85
}//end class
86
87
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
88