Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * Squiz_Sniffs_WhiteSpace_SemicolonSpacingSniff.
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
13
 * @version   CVS: $Id: SemicolonSpacingSniff.php 265197 2008-08-21 04:32:35Z squiz $
14
 * @link      http://pear.php.net/package/PHP_CodeSniffer
15
 */
16
 
17
/**
18
 * Squiz_Sniffs_WhiteSpace_SemicolonSpacingSniff.
19
 *
20
 * Ensure there is no whitespace before a semicolon.
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.1
29
 * @link      http://pear.php.net/package/PHP_CodeSniffer
30
 */
31
class Squiz_Sniffs_WhiteSpace_SemicolonSpacingSniff 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
                                  );
43
 
44
    /**
45
     * Returns an array of tokens this test wants to listen for.
46
     *
47
     * @return array
48
     */
49
    public function register()
50
    {
51
        return array(T_SEMICOLON);
52
 
53
    }//end register()
54
 
55
 
56
    /**
57
     * Processes this test, when one of its tokens is encountered.
58
     *
59
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
60
     * @param int                  $stackPtr  The position of the current token
61
     *                                        in the stack passed in $tokens.
62
     *
63
     * @return void
64
     */
65
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
66
    {
67
        $tokens = $phpcsFile->getTokens();
68
 
69
        $prevType = $tokens[($stackPtr - 1)]['code'];
70
        if (in_array($prevType, PHP_CodeSniffer_Tokens::$emptyTokens) === true) {
71
            $nonSpace = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 2), null, true);
72
            $expected = $tokens[$nonSpace]['content'].';';
73
            $found    = $phpcsFile->getTokensAsString($nonSpace, ($stackPtr - $nonSpace)).';';
74
            $error    = "Space found before semicolon; expected \"$expected\" but found \"$found\"";
75
            $phpcsFile->addError($error, $stackPtr);
76
        }
77
 
78
    }//end process()
79
 
80
 
81
}//end class
82
 
83
?>