You are here

public function NamespaceSniff::process in Coder 8.2

Same name and namespace in other branches
  1. 8.3 coder_sniffer/Drupal/Sniffs/WhiteSpace/NamespaceSniff.php \Drupal\Sniffs\WhiteSpace\NamespaceSniff::process()
  2. 8.3.x coder_sniffer/Drupal/Sniffs/WhiteSpace/NamespaceSniff.php \Drupal\Sniffs\WhiteSpace\NamespaceSniff::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/NamespaceSniff.php, line 47

Class

NamespaceSniff
Checks that there is exactly one space after the namespace keyword.

Namespace

Drupal\Sniffs\WhiteSpace

Code

public function process(File $phpcsFile, $stackPtr) {
  $tokens = $phpcsFile
    ->getTokens();
  if ($tokens[$stackPtr + 1]['content'] !== ' ') {
    $error = 'There must be exactly one space after the namepace keyword';
    $fix = $phpcsFile
      ->addFixableError($error, $stackPtr + 1, 'OneSpace');
    if ($fix === true) {
      $phpcsFile->fixer
        ->replaceToken($stackPtr + 1, ' ');
    }
  }
}