function Counter::countInSourceString
Throws
1 call to Counter::countInSourceString()
- Counter::countInSourceFile in vendor/
sebastian/ lines-of-code/ src/ Counter.php
File
-
vendor/
sebastian/ lines-of-code/ src/ Counter.php, line 33
Class
Namespace
SebastianBergmann\LinesOfCodeCode
public function countInSourceString(string $source) : LinesOfCode {
$linesOfCode = substr_count($source, "\n");
if ($linesOfCode === 0 && !empty($source)) {
$linesOfCode = 1;
}
assert($linesOfCode >= 0);
try {
$nodes = (new ParserFactory())->createForHostVersion()
->parse($source);
assert($nodes !== null);
return $this->countInAbstractSyntaxTree($linesOfCode, $nodes);
// @codeCoverageIgnoreStart
} catch (Error $error) {
throw new RuntimeException($error->getMessage(), $error->getCode(), $error);
}
// @codeCoverageIgnoreEnd
}