public function Drupal_Sniffs_CSS_ClassDefinitionClosingBraceSpaceSniff::process in Coder 7.2
Processes the tokens that this sniff is interested in.
Parameters
PHP_CodeSniffer_File $phpcsFile The file where the token was found.:
int $stackPtr The position in the stack where: the token was found.
Return value
void
File
- coder_sniffer/
Drupal/ Sniffs/ CSS/ ClassDefinitionClosingBraceSpaceSniff.php, line 53
Class
- Drupal_Sniffs_CSS_ClassDefinitionClosingBraceSpaceSniff
- Ensure that there is exactly one new line before a class closing brace. Copied from Squiz_Sniffs_CSS_ClassDefinitionClosingBraceSpaceSniff because of a bug: https://pear.php.net/bugs/bug.php?id=19283
Code
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile
->getTokens();
// Do not check nested style definitions as, for example, in @media style rules.
$start = $tokens[$stackPtr]['bracket_opener'];
$nested = $phpcsFile
->findPrevious(T_CLOSE_CURLY_BRACKET, $stackPtr - 1, $start);
if ($nested !== false) {
return;
}
$prev = $phpcsFile
->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr - 1, null, true);
if ($prev !== false && $tokens[$prev]['line'] !== $tokens[$stackPtr]['line'] - 1) {
$error = 'Expected exactly one new line before closing brace of class definition';
$phpcsFile
->addError($error, $stackPtr, 'SpacingBeforeClose');
}
}