You are here

public function OpenBracketSpacingSniff::process in Coder 8.2

Same name and namespace in other branches
  1. 8.3 coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenBracketSpacingSniff.php \Drupal\Sniffs\WhiteSpace\OpenBracketSpacingSniff::process()
  2. 8.3.x coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenBracketSpacingSniff.php \Drupal\Sniffs\WhiteSpace\OpenBracketSpacingSniff::process()

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

Parameters

\PHP_CodeSniffer\Files\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 63

Class

OpenBracketSpacingSniff
Checks that there is no white space after an opening bracket, for "(" and "{". Square Brackets are handled by \PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayBracketSpacingSniff.

Namespace

Drupal\Sniffs\WhiteSpace

Code

public function process(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 && isset($tokens[$stackPtr + 2]) === true && $tokens[$stackPtr + 2]['code'] !== T_CLOSE_TAG) {
    $error = 'There should be no white space after an opening "%s"';
    $fix = $phpcsFile
      ->addFixableError($error, $stackPtr + 1, 'OpeningWhitespace', array(
      $tokens[$stackPtr]['content'],
    ));
    if ($fix === true) {
      $phpcsFile->fixer
        ->replaceToken($stackPtr + 1, '');
    }
  }
}