You are here

public function EmptyLinesSniff::process in Coder 8.3.x

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

Class

EmptyLinesSniff
\Drupal\Sniffs\WhiteSpace\EmptyLinesSniff.

Namespace

Drupal\Sniffs\WhiteSpace

Code

public function process(File $phpcsFile, $stackPtr) {
  $tokens = $phpcsFile
    ->getTokens();
  if ($tokens[$stackPtr]['content'] === $phpcsFile->eolChar && isset($tokens[$stackPtr + 1]) === true && $tokens[$stackPtr + 1]['content'] === $phpcsFile->eolChar && isset($tokens[$stackPtr + 2]) === true && $tokens[$stackPtr + 2]['content'] === $phpcsFile->eolChar && isset($tokens[$stackPtr + 3]) === true && $tokens[$stackPtr + 3]['content'] === $phpcsFile->eolChar) {
    $error = 'More than 2 empty lines are not allowed';
    $phpcsFile
      ->addError($error, $stackPtr + 3, 'EmptyLines');
  }
}