3
* Squiz_Sniffs_CSS_ClassDefinitionClosingBraceSpaceSniff.
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
16
* Squiz_Sniffs_CSS_ClassDefinitionClosingBraceSpaceSniff.
18
* Ensure there is a single blank line after the closing brace of a class definition.
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
28
class Squiz_Sniffs_CSS_ClassDefinitionClosingBraceSpaceSniff implements PHP_CodeSniffer_Sniff
32
* A list of tokenizers this sniff supports.
36
public $supportedTokenizers = array('CSS');
40
* Returns the token types that this sniff is interested in.
44
public function register()
46
return array(T_CLOSE_CURLY_BRACKET);
52
* Processes the tokens that this sniff is interested in.
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.
60
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
62
$tokens = $phpcsFile->getTokens();
64
$next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
65
if ($next === false) {
69
if ($tokens[$next]['code'] !== T_CLOSE_TAG) {
70
$found = (($tokens[$next]['line'] - $tokens[$stackPtr]['line']) - 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);
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,
84
$tokens[$stackPtr]['bracket_opener']
86
if ($found !== false) {
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';
95
$phpcsFile->addError($error, $stackPtr, 'SpacingBeforeClose', $data);