Weave 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

Lines Of Code Laravel Package

sebastian/lines-of-code

A lightweight PHP library from Sebastian Bergmann for counting lines of code in PHP source files, reporting logical and physical line counts. Used by PHPUnit's code coverage tooling and handy for building metrics, reports, and static analysis tools.

View on GitHub
Deep Wiki
Context7

Library for counting the lines of code in PHP source code

Frequently asked questions about Lines Of Code
How do I install sebastian/lines-of-code in a Laravel project?
Install it with Composer using composer require --dev sebastian/lines-of-code, since it is a build-time analytics library rather than a runtime dependency. There is no service provider, config file, or publish step, so nothing else is required. You can then call Counter::count() with an absolute file path from an Artisan command, job, or test.
Which PHP and Laravel versions does sebastian/lines-of-code support?
Support is tied to the package major version rather than to Laravel itself: 5.x requires PHP 8.4 or newer, 4.x requires PHP 8.3, and 3.x targets PHP 8.2. Many Laravel LTS-track applications therefore cannot take the latest major without a runtime upgrade. Either pin the major that matches your runtime, or run the counter in an isolated CI container on PHP 8.4 and leave application runtimes untouched.
What is the difference between lines of code and logical lines of code in sebastian/lines-of-code?
Physical lines are the raw line counts a file occupies, while logical lines of code (LLOC) count executable statements, so a statement spread across several lines still counts once. This package parses each PHP file rather than splitting on newlines, so comments, whitespace, and multi-line strings are handled correctly when computing physical counts. The LinesOfCode value object exposes linesOfCode, commentLinesOfCode, and nonCommentLinesOfCode; check the API of your installed version if you specifically need LLOC output, which also surfaces through PHPUnit's code coverage tooling.
Can sebastian/lines-of-code count lines in Blade templates, JavaScript, or Vue files?
No. It analyzes PHP source files only, so Blade templates, Livewire and Inertia components, JS/Vue/React assets, migrations, and config files are all invisible to it. On a full-stack Laravel team this systematically under-reports delivered work. State the boundary explicitly in any dashboard subtitle, for example PHP application code only, and pair it with a polyglot counter such as cloc or tokei if your audience expects whole-repo totals.
How do I count lines of code for an entire Laravel directory instead of one file?
The public API is per-file: you pass a single path to Counter::count() and get back an immutable value object. Recursive traversal, exclusion of vendor and .gitignore paths, aggregation by module, and the tests around all of that are your own code. Budget one to two days of engineering including validation rather than the three lines the README implies.
Is sebastian/lines-of-code safe to run in production?
It is a stateless, framework-agnostic library that reads a file and returns a value object, with no bindings, configuration, persistence, or network access. That makes it a build-time analytics tool rather than something belonging in the request lifecycle, so production latency and runtime blast radius are effectively zero. Keep it in require-dev unless a reporting job actually ships inside the deployed artifact.
Why does sebastian/lines-of-code return zero or negative non-comment lines of code?
Versions 4.0.1 and 5.0.1 both fix a defect where multi-line comments were double-counted, producing impossible negative non-comment counts, and 5.0.2 added a guard forcing the line count positive. A metric that can return impossible values is a governance hazard if it gates merges, so pin a patched release. Validate against a hand-counted sample file and against cloc before enforcing any threshold, and assert non-negativity in your own wrapper.
Does sebastian/lines-of-code conflict with PHPStan, PHP-CS-Fixer, or Rector?
It depends on nikic/php-parser, the same parser used by PHPStan, PHP-CS-Fixer, and Rector. That shared dependency is exactly why heredocs and block comments are handled correctly, but it also means a version mismatch can break a composer update. Align the constraint with your existing static-analysis stack and let Composer resolve before you lock a version; a failure here is noisy and diagnosable rather than a silent metric error.
Should sebastian/lines-of-code be a dev dependency or a production dependency?
Use composer require --dev unless a reporting job ships inside the deployed artifact. The library is only invoked when you deliberately call it from an Artisan command, scheduled job, CI step, or PR-comment bot. Keeping it in require-dev keeps your production install lean and makes the intent clear to reviewers.
Is sebastian/lines-of-code already installed through PHPUnit, and what are the alternatives?
Very likely yes. It is a transitive dependency of phpunit/php-code-coverage, so it probably already appears in your composer.lock on any Laravel project running PHPUnit. Run composer why sebastian/lines-of-code before scoping anything; if it is present, marginal dependency and procurement risk is effectively nil. Alternatives such as cloc or tokei cover multiple languages, but they are not parser-accurate for PHP comments and strings the way this library is.
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.
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin
skyraptor/chatter
edlugz/sasapay
abbasudo/artisan-route