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.
cloc/tokei in CI, SonarQube, or PHPMetrics — not an in-house counter. It wins only when you need PHP-aware counts computed inside a PHP process you already own (an Artisan command, a scheduled report, a PR bot, a metrics dashboard).app/Modules/Billing grew 40% while shipping three features") is the highest-value use case and the one least likely to be cheaply duplicated by SaaS you already pay for.cloc) before it influences a decision.Adopt when:
artisan metrics:loc command, a nightly reporting job, a Slack digest, or a PR comment — and want PHP-aware parsing (tokenizer-based), so block comments, heredocs, and multi-line strings don't skew the numbers the way wc -l does.LinesOfCode value object with linesOfCode, commentLinesOfCode, and nonCommentLinesOfCode accessors — trivial to serialize into storage and chart.phpunit/php-code-coverage, so it may already be in your composer.lock. Run composer why sebastian/lines-of-code before scoping — the marginal dependency risk may be nil.Look elsewhere when:
tokei or cloc gives one number across the tree..gitignore and vendor/ exclusions, and aggregation are your code, not the package's — budget for a small tested internal utility.Executives / engineering leadership
"This is a free, BSD-licensed PHP library that measures codebase size properly — separating real code from comments and blank lines, using PHP's own tokenizer rather than counting newlines. We'd use it in one narrow place: a lightweight internal report showing how each service grows quarter over quarter, so capacity and refactoring conversations are backed by data rather than anecdotes. It is not a vendor contract, it replaces nothing we pay for today, and it is roughly a one-day integration plus the directory-traversal utility we'd write ourselves. It carries zero runtime footprint in production. My recommendation is to treat it as optional infrastructure, not a roadmap item — and to explicitly commit that LOC is a trend indicator, never a measure of individual or team performance."
Engineering leadership
"The honest framing: this is a component of Sebastian Bergmann's PHPUnit ecosystem, and PHPUnit's coverage tooling already consumes it — so it is very likely already in our lock file. It's stable, tiny, and framework-agnostic: no service provider, no config, no production runtime cost. Two real caveats. First, the current major requires PHP 8.4+; if our apps are on 8.2/8.3 we either pin an older major or run it in a separate container. Second, the API is per-file, so we own the directory walk, the exclusion rules, and the aggregation — that's where the actual engineering cost sits. If all we want is a number in a dashboard,
clocin CI gets us there for near-zero effort. We should take this dependency only if we specifically need PHP-aware counts, computed in-process, from a value object we can persist."
Engineering teams
"Use this when you need PHP-accurate counts inside your own tooling — an
artisan metrics:loccommand, a nightly job, or a warning-level test that flags a module growing past a threshold. You get physical, comment, and non-comment LOC per file, parsed from tokens rather than newlines, so heredocs and block comments don't skew the numbers. Install with--dev. Two things to know before you touch it: the counter is single-file, so you write the recursive scan and the ignore logic; and pin the version to your PHP runtime rather than floating, because majors drop older PHP quickly. Please validate the first run againstcloc— the project has a documented history of a multi-comment double-counting bug that produced negative non-comment LOC — and keep any CI check in warn-only mode for at least a quarter before anyone proposes making it blocking. Never surface the number per developer."
How can I help you explore Laravel packages today?