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

Breadcrumb

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

function HereNowdocIdentifierSpacingSniff::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/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/WhiteSpace/HereNowdocIdentifierSpacingSniff.php, line 43

Class

HereNowdocIdentifierSpacingSniff

Namespace

PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace

Code

public function process(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    if (strpos($tokens[$stackPtr]['content'], ' ') === false && strpos($tokens[$stackPtr]['content'], "\t") === false) {
        // Nothing to do.
        $phpcsFile->recordMetric($stackPtr, 'Heredoc/nowdoc identifier', 'no space between <<< and ID');
        return;
    }
    $phpcsFile->recordMetric($stackPtr, 'Heredoc/nowdoc identifier', 'space between <<< and ID');
    $error = 'There should be no space between the <<< and the heredoc/nowdoc identifier string';
    $data = [
        $tokens[$stackPtr]['content'],
    ];
    $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceFound', $data);
    if ($fix === true) {
        $replacement = str_replace([
            ' ',
            "\t",
        ], '', $tokens[$stackPtr]['content']);
        $phpcsFile->fixer
            ->replaceToken($stackPtr, $replacement);
    }
}
RSS feed
Powered by Drupal