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

Breadcrumb

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

class Counter

Same name in this branch
  1. 11.1.x vendor/open-telemetry/sdk/Metrics/Counter.php \OpenTelemetry\SDK\Metrics\Counter
  2. 11.1.x core/modules/views/src/Plugin/views/field/Counter.php \Drupal\views\Plugin\views\field\Counter

Hierarchy

  • class \SebastianBergmann\LinesOfCode\Counter

Expanded class hierarchy of Counter

1 file declares its use of Counter
ExcludeList.php in vendor/phpunit/phpunit/src/Util/ExcludeList.php
2 string references to 'Counter'
views.field.schema.yml in core/modules/views/config/schema/views.field.schema.yml
core/modules/views/config/schema/views.field.schema.yml
ViewsViewsHooks::viewsData in core/modules/views/src/Hook/ViewsViewsHooks.php
Implements hook_views_data().

File

vendor/sebastian/lines-of-code/src/Counter.php, line 20

Namespace

SebastianBergmann\LinesOfCode
View source
final class Counter {
    
    /**
     * @throws RuntimeException
     */
    public function countInSourceFile(string $sourceFile) : LinesOfCode {
        return $this->countInSourceString(file_get_contents($sourceFile));
    }
    
    /**
     * @throws RuntimeException
     */
    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
    }
    
    /**
     * @psalm-param non-negative-int $linesOfCode
     *
     * @param Node[] $nodes
     *
     * @throws RuntimeException
     */
    public function countInAbstractSyntaxTree(int $linesOfCode, array $nodes) : LinesOfCode {
        $traverser = new NodeTraverser();
        $visitor = new LineCountingVisitor($linesOfCode);
        $traverser->addVisitor($visitor);
        try {
            
            /* @noinspection UnusedFunctionResultInspection */
            $traverser->traverse($nodes);
            // @codeCoverageIgnoreStart
        } catch (Error $error) {
            throw new RuntimeException($error->getMessage(), $error->getCode(), $error);
        }
        // @codeCoverageIgnoreEnd
        return $visitor->result();
    }

}

Members

Title Sort descending Modifiers Object type Summary
Counter::countInAbstractSyntaxTree public function @psalm-param non-negative-int $linesOfCode
Counter::countInSourceFile public function
Counter::countInSourceString public function

API Navigation

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