Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. OpenBracketSpacingSniff.php

function 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

Overrides Sniff::process

File

vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/WhiteSpace/OpenBracketSpacingSniff.php, line 53

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', [
            $tokens[$stackPtr]['content'],
        ]);
        if ($fix === true) {
            $phpcsFile->fixer
                ->replaceToken($stackPtr + 1, '');
        }
    }
}
RSS feed
Powered by Drupal