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

Breadcrumb

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

function CommaSniff::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/CommaSniff.php, line 49

Class

CommaSniff
\Drupal\Sniffs\WhiteSpace\CommaSniff.

Namespace

Drupal\Sniffs\WhiteSpace

Code

public function process(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    if (isset($tokens[$stackPtr + 1]) === false) {
        return;
    }
    if ($tokens[$stackPtr + 1]['code'] !== T_WHITESPACE && $tokens[$stackPtr + 1]['code'] !== T_COMMA && $tokens[$stackPtr + 1]['code'] !== T_CLOSE_PARENTHESIS) {
        $error = 'Expected one space after the comma, 0 found';
        $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpace');
        if ($fix === true) {
            $phpcsFile->fixer
                ->addContent($stackPtr, ' ');
        }
        return;
    }
    if ($tokens[$stackPtr + 1]['code'] === T_WHITESPACE && isset($tokens[$stackPtr + 2]) === true && $tokens[$stackPtr + 2]['line'] === $tokens[$stackPtr + 1]['line'] && $tokens[$stackPtr + 1]['content'] !== ' ') {
        $error = 'Expected one space after the comma, %s found';
        $fix = $phpcsFile->addFixableError($error, $stackPtr, 'TooManySpaces', [
            strlen($tokens[$stackPtr + 1]['content']),
        ]);
        if ($fix === true) {
            $phpcsFile->fixer
                ->replaceToken($stackPtr + 1, ' ');
        }
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal