Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Lines Of Code Laravel Package

sebastian/lines-of-code

sebastian/lines-of-code is a lightweight PHP library for counting lines of code in PHP source files. Useful for reporting, metrics, and tooling, it can be installed via Composer as a runtime or dev dependency.

View on GitHub
Deep Wiki
Context7

Getting Started

Install the package via Composer as a dev dependency: composer require --dev sebastian/lines-of-code. It requires PHP 8.4+ and nikic/php-parser ^5.0. Use it in a script or test to analyze PHP source code by instantiating SebastianBergmann\LinesOfCode\Counter and calling count() on a directory or file path. The result is an object with properties like linesOfCode, commentLinesOfCode, and nonCommentLinesOfCode.

Implementation Patterns

Use it in CI pipelines (e.g., GitHub Actions) to enforce LOC thresholds by writing a simple PHP script that calls Counter::count() on your src/ and tests/ directories and asserts against configured limits. In unit tests, wrap the counter to validate that new code doesn’t exceed project-specific complexity budgets. Combine with nikic/php-parser AST analysis for deeper insights (e.g., counting only class/method definitions). For integration, pair with tools like PHP_CodeSniffer or PHPMD to correlate LOC with style/maintainability rules.

Gotchas and Tips

The package counts logical lines of code (excluding blank lines and comments), not raw file lines—this may differ from what IDEs report. Be aware it excludes declare() statements and other compiler directives only when they appear on their own line; mixed usage may cause minor variations. Always specify paths relative to your project root; absolute paths may behave unexpectedly in CLI vs CI environments. The library is immutable—each call creates a new Result object, so avoid repeated counting of the same directory in loops without caching. Since it depends on nikic/php-parser, ensure parser version compatibility if you’re also using php-parser directly in your tooling.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport