You are here

public function Drupal_Sniffs_Files_LineLengthSniff::getLineLength in Coder 7.2

Returns the length of a defined line.

Return value

integer

File

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

Class

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

Code

public function getLineLength(PHP_CodeSniffer_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);
}