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_CSS_ColonSpacingSniff.
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: ClassDefinitionOpeningBraceSpaceSniff.php 268066 2008-10-31 05:36:54Z squiz $
13
 * @link      http://pear.php.net/package/PHP_CodeSniffer
14
 */
15
 
16
/**
17
 * Squiz_Sniffs_CSS_ClassDefinitionOpeningBraceSpaceSniff.
18
 *
19
 * Ensure there is a single space before the opening brace in a class definition
20
 * and the content starts on the next line.
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_CSS_ClassDefinitionOpeningBraceSpaceSniff implements PHP_CodeSniffer_Sniff
31
{
32
 
33
    /**
34
     * A list of tokenizers this sniff supports.
35
     *
36
     * @var array
37
     */
38
    public $supportedTokenizers = array('CSS');
39
 
40
 
41
    /**
42
     * Returns the token types that this sniff is interested in.
43
     *
44
     * @return array(int)
45
     */
46
    public function register()
47
    {
48
        return array(T_OPEN_CURLY_BRACKET);
49
 
50
    }//end register()
51
 
52
 
53
    /**
54
     * Processes the tokens that this sniff is interested in.
55
     *
56
     * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
57
     * @param int                  $stackPtr  The position in the stack where
58
     *                                        the token was found.
59
     *
60
     * @return void
61
     */
62
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
63
    {
64
        $tokens = $phpcsFile->getTokens();
65
 
66
        if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE) {
67
            $error = 'Expected 1 space before opening brace of class definition; 0 found';
68
            $phpcsFile->addError($error, $stackPtr);
69
        } else {
70
            $content = $tokens[($stackPtr - 1)]['content'];
71
            if ($content !== ' ') {
72
                $length = strlen($content);
73
                if ($length === 1) {
74
                    $length = 'tab';
75
                }
76
 
77
                $error = "Expected 1 space before opening brace of class definition; $length found";
78
                $phpcsFile->addError($error, $stackPtr);
79
            }
80
        }//end if
81
 
82
        $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
83
        if ($next !== false && $tokens[$next]['line'] !== ($tokens[$stackPtr]['line'] + 1)) {
84
            $num   = ($tokens[$next]['line'] - $tokens[$stackPtr]['line'] - 1);
85
            $error = "Expected 0 blank lines after opening brace of class definition; $num found";
86
            $phpcsFile->addError($error, $stackPtr);
87
        }
88
 
89
    }//end process()
90
 
91
 
92
}//end class
93
 
94
?>