Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Counter.php

function Counter::countInSourceString

Throws

RuntimeException

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

Counter

Namespace

SebastianBergmann\LinesOfCode

Code

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
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal