You are here

public function Drupal_Sniffs_WhiteSpace_OpenBracketSpacingSniff::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/OpenBracketSpacingSniff.php, line 58

Class

Drupal_Sniffs_WhiteSpace_OpenBracketSpacingSniff
Checks that there is no white space after an opening 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_OPEN_CURLY_BRACKET && $phpcsFile->tokenizerType === 'JS') {
    return;
  }
  if (isset($tokens[$stackPtr + 1]) === true && $tokens[$stackPtr + 1]['code'] === T_WHITESPACE && strpos($tokens[$stackPtr + 1]['content'], $phpcsFile->eolChar) === false) {
    $error = 'There should be no white space after an opening "%s"';
    $phpcsFile
      ->addError($error, $stackPtr + 1, 'OpeningWhitespace', array(
      $tokens[$stackPtr]['content'],
    ));
  }
}