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

Breadcrumb

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

function CastSpacingSniff::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/Squiz/Sniffs/WhiteSpace/CastSpacingSniff.php, line 41

Class

CastSpacingSniff

Namespace

PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace

Code

public function process(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    $content = $tokens[$stackPtr]['content'];
    $expected = str_replace(' ', '', $content);
    $expected = str_replace("\t", '', $expected);
    if ($content !== $expected) {
        $error = 'Cast statements must not contain whitespace; expected "%s" but found "%s"';
        $data = [
            $expected,
            $content,
        ];
        $fix = $phpcsFile->addFixableError($error, $stackPtr, 'ContainsWhiteSpace', $data);
        if ($fix === true) {
            $phpcsFile->fixer
                ->replaceToken($stackPtr, $expected);
        }
    }
}
RSS feed
Powered by Drupal