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. Note: In version 5.0.1, a bug was fixed where lines containing multiple comments were incorrectly double-counted, which could previously result in negative values for $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. Version 5.0.1 fixes a critical bug where lines with multiple comments were double-counted, potentially causing negative $nonCommentLinesOfCode values. Be aware it still 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. Test thoroughly after upgrading to 5.0.1, especially if your codebase contains files with mixed comments or edge-case formatting.

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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai