You are here

public function Drupal_Sniffs_Files_TxtFileLineLengthSniff::process in Coder 7.2

Processes this test, when one of its tokens is encountered.

Parameters

PHP_CodeSniffer_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/Files/TxtFileLineLengthSniff.php, line 49

Class

Drupal_Sniffs_Files_TxtFileLineLengthSniff
Drupal_Sniffs_Files_TxtFileLineLengthSniff.

Code

public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
  $fileExtension = strtolower(substr($phpcsFile
    ->getFilename(), -3));
  if ($fileExtension === 'txt' || $fileExtension === '.md') {
    $tokens = $phpcsFile
      ->getTokens();
    $content = rtrim($tokens[$stackPtr]['content']);
    $lineLength = mb_strlen($content, 'UTF-8');
    if ($lineLength > 80) {
      $data = array(
        80,
        $lineLength,
      );
      $warning = 'Line exceeds %s characters; contains %s characters';
      $phpcsFile
        ->addWarning($warning, $stackPtr, 'TooLong', $data);
    }
  }
}