You are here

public function Drupal_Sniffs_WhiteSpace_CloseBracketSpacingSniff::process in Coder 7.2

Processes this test, when one of its tokens is encountered.

Parameters

PHP_CodeSniffer_File $phpcsFile The file being scanned.:

int $stackPtr The position of the current token: in the stack passed in $tokens.

Return value

void

File

coder_sniffer/Drupal/Sniffs/WhiteSpace/CloseBracketSpacingSniff.php, line 58

Class

Drupal_Sniffs_WhiteSpace_CloseBracketSpacingSniff
Checks that there is no white space before a closing bracket, for ")" and "}". Square Brackets are handled by Squiz_Sniffs_Arrays_ArrayBracketSpacingSniff.

Code

public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
  $tokens = $phpcsFile
    ->getTokens();

  // Ignore curly brackets in javascript files.
  if ($tokens[$stackPtr]['code'] === T_CLOSE_CURLY_BRACKET && $phpcsFile->tokenizerType === 'JS') {
    return;
  }
  if (isset($tokens[$stackPtr - 1]) === true && $tokens[$stackPtr - 1]['code'] === T_WHITESPACE) {
    $before = $phpcsFile
      ->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr - 1, null, true);
    if ($before !== false && $tokens[$stackPtr]['line'] === $tokens[$before]['line']) {
      $error = 'There should be no white space before a closing "%s"';
      $phpcsFile
        ->addError($error, $stackPtr - 1, 'ClosingWhitespace', array(
        $tokens[$stackPtr]['content'],
      ));
    }
  }
}