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_PropertyLabelSpacingSniff.
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PHP_CodeSniffer
9
 * @author    Greg Sherwood <gsherwood@squiz.net>
10
 * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
11
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
12
 * @version   CVS: $Id: PropertyLabelSpacingSniff.php 265262 2008-08-22 04:14:30Z squiz $
13
 * @link      http://pear.php.net/package/PHP_CodeSniffer
14
 */
15
 
16
/**
17
 * Squiz_Sniffs_WhiteSpace_PropertyLabelSpacingSniff.
18
 *
19
 * Ensures that the colon in a property or label definition has a single
20
 * space after it and no space before it.
21
 *
22
 * @category  PHP
23
 * @package   PHP_CodeSniffer
24
 * @author    Greg Sherwood <gsherwood@squiz.net>
25
 * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
26
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
27
 * @version   Release: 1.2.1
28
 * @link      http://pear.php.net/package/PHP_CodeSniffer
29
 */
30
class Squiz_Sniffs_WhiteSpace_PropertyLabelSpacingSniff implements PHP_CodeSniffer_Sniff
31
{
32
 
33
    /**
34
     * A list of tokenizers this sniff supports.
35
     *
36
     * @var array
37
     */
38
    public $supportedTokenizers = array('JS');
39
 
40
 
41
    /**
42
     * Returns an array of tokens this test wants to listen for.
43
     *
44
     * @return array
45
     */
46
    public function register()
47
    {
48
        return array(
49
                T_PROPERTY,
50
                T_LABEL,
51
               );
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
        $colon = $phpcsFile->findNext(T_COLON, ($stackPtr + 1));
70
 
71
        if ($colon !== ($stackPtr + 1)) {
72
            $error = 'There must be no space before the colon in a property/label declaration';
73
            $phpcsFile->addError($error, $stackPtr);
74
        }
75
 
76
        if ($tokens[($colon + 1)]['code'] !== T_WHITESPACE || $tokens[($colon + 1)]['content'] !== ' ') {
77
            $error = 'There must be a single space after the colon in a property/label declaration';
78
            $phpcsFile->addError($error, $stackPtr);
79
        }
80
 
81
    }//end process()
82
 
83
 
84
}//end class
85
 
86
?>