You are here

public function LineLengthSniff::getLineLength in Coder 8.2

Same name and namespace in other branches
  1. 8.3 coder_sniffer/Drupal/Sniffs/Files/LineLengthSniff.php \Drupal\Sniffs\Files\LineLengthSniff::getLineLength()
  2. 8.3.x coder_sniffer/Drupal/Sniffs/Files/LineLengthSniff.php \Drupal\Sniffs\Files\LineLengthSniff::getLineLength()

Returns the length of a defined line.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:

int $currentLine The current line.:

Return value

int

File

coder_sniffer/Drupal/Sniffs/Files/LineLengthSniff.php, line 119

Class

LineLengthSniff
Checks comment lines in the file, and throws warnings if they are over 80 characters in length.

Namespace

Drupal\Sniffs\Files

Code

public function getLineLength(File $phpcsFile, $currentLine) {
  $tokens = $phpcsFile
    ->getTokens();
  $tokenCount = 0;
  $currentLineContent = '';
  $trim = strlen($phpcsFile->eolChar) * -1;
  for (; $tokenCount < $phpcsFile->numTokens; $tokenCount++) {
    if ($tokens[$tokenCount]['line'] === $currentLine) {
      $currentLineContent .= $tokens[$tokenCount]['content'];
    }
  }
  return strlen($currentLineContent);
}