~ubuntu-branches/ubuntu/wily/php-codesniffer/wily

« back to all changes in this revision

Viewing changes to PHP_CodeSniffer-1.5.0RC2/CodeSniffer/Standards/Squiz/Sniffs/CSS/ClassDefinitionClosingBraceSpaceSniff.php

  • Committer: Package Import Robot
  • Author(s): David Prévot
  • Date: 2014-07-21 14:42:41 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20140721144241-g4orlcuk4jzn9mhs
Tags: 1.5.3-1
* Team upload
* Focus on stable release
* Update copyright
* Bump standards version to 3.9.5
* Update Homepage
* Use ${phppear:…} instead of hardcoding them
* Run tests in dh_auto_test
* Update patch with gbp pq
* Simplify configuration installation
* Edit package.xml to move script
* Add DEP-8 tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/**
3
 
 * Squiz_Sniffs_CSS_ClassDefinitionClosingBraceSpaceSniff.
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
 
 * Squiz_Sniffs_CSS_ClassDefinitionClosingBraceSpaceSniff.
17
 
 *
18
 
 * Ensure there is a single blank line after the closing brace of a class definition.
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 Squiz_Sniffs_CSS_ClassDefinitionClosingBraceSpaceSniff implements PHP_CodeSniffer_Sniff
29
 
{
30
 
 
31
 
    /**
32
 
     * A list of tokenizers this sniff supports.
33
 
     *
34
 
     * @var array
35
 
     */
36
 
    public $supportedTokenizers = array('CSS');
37
 
 
38
 
 
39
 
    /**
40
 
     * Returns the token types that this sniff is interested in.
41
 
     *
42
 
     * @return array(int)
43
 
     */
44
 
    public function register()
45
 
    {
46
 
        return array(T_CLOSE_CURLY_BRACKET);
47
 
 
48
 
    }//end register()
49
 
 
50
 
 
51
 
    /**
52
 
     * Processes the tokens that this sniff is interested in.
53
 
     *
54
 
     * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
55
 
     * @param int                  $stackPtr  The position in the stack where
56
 
     *                                        the token was found.
57
 
     *
58
 
     * @return void
59
 
     */
60
 
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
61
 
    {
62
 
        $tokens = $phpcsFile->getTokens();
63
 
 
64
 
        $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
65
 
        if ($next === false) {
66
 
            return;
67
 
        }
68
 
 
69
 
        if ($tokens[$next]['code'] !== T_CLOSE_TAG) {
70
 
            $found = (($tokens[$next]['line'] - $tokens[$stackPtr]['line']) - 1);
71
 
            if ($found !== 1) {
72
 
                $error = 'Expected one blank line after closing brace of class definition; %s found';
73
 
                $data  = array($found);
74
 
                $phpcsFile->addError($error, $stackPtr, 'SpacingAfterClose', $data);
75
 
            }
76
 
        }
77
 
 
78
 
        // Ignore nested style definitions from here on. The spacing before the closing brace
79
 
        // (a single blank line) will be enforced by the above check, which ensures there is a
80
 
        // blank line after the last nested class.
81
 
        $found = $phpcsFile->findPrevious(
82
 
            T_CLOSE_CURLY_BRACKET,
83
 
            ($stackPtr - 1),
84
 
            $tokens[$stackPtr]['bracket_opener']
85
 
        );
86
 
        if ($found !== false) {
87
 
            return;
88
 
        }
89
 
 
90
 
        $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
91
 
        if ($prev !== false && $tokens[$prev]['line'] !== ($tokens[$stackPtr]['line'] - 1)) {
92
 
            $num   = ($tokens[$stackPtr]['line'] - $tokens[$prev]['line'] - 1);
93
 
            $error = 'Expected 0 blank lines before closing brace of class definition; %s found';
94
 
            $data  = array($num);
95
 
            $phpcsFile->addError($error, $stackPtr, 'SpacingBeforeClose', $data);
96
 
        }
97
 
 
98
 
    }//end process()
99
 
 
100
 
 
101
 
}//end class
102
 
 
103
 
?>