The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

Lines

Lines stats

Downloads
249K
Stars
225
Open Issues
1
Forks
5

View on GitHub →

Measuring the size of PHP project and its PHP features

Lines of code and PHP Features

CLI tool for quick size measure of PHP project, and real used PHP features.

Zero dependencies. Runs anywhere.


What are killer features?

  • install anywhere - PHP 7.2? PHPUnit 6? Symfony 3? Not a problem, this package has zero dependencies and works on PHP 7.2+
  • get quick overview of your project size - no details, no complexity, just lines of code
  • get easy JSON output for further processing
  • measure used PHP features in your project - how much PHP 8.0-features used? How many attributes? How many arrow function? How many union types?

Install

The package is scoped and downgraded to PHP 7.2. So you can install it anywhere with any set of dependencies:

composer require tomasvotruba/lines --dev

1. Measure Lines and Size

vendor/bin/lines measure

By default, we measure the root directory. To narrow it down, provide explicit path:

vendor/bin/lines measure src

For short output:

vendor/bin/lines measure --short

For json output, just add --json:

vendor/bin/lines measure --json

Also, you can combine them (very handy for blog posts and tweets):

vendor/bin/lines measure --short --json

For the text output, you'll get data like these:

Filesystem count
Directories ......................................... 32
Files .............................................. 160
 
Lines of code count / relative
Code ................................... 15 521 / 70.9 %
Comments ................................ 6 372 / 29.1 %
Total .................................. 21 893 / 100 %
 
Structure count
Namespaces .......................................... 32
Classes ............................................ 134
* Constants ........................................ 91
* Methods ....................................... 1 114
Interfaces .......................................... 20
Traits ............................................... 4
Enums ................................................ 1
Functions ........................................... 36
Global constants ..................................... 0
 
Methods count / relative
Non-static .............................. 1 058 / 95 %
Static ..................................... 56 / 5 %
 
Public .................................... 875 / 78.5 %
Protected .................................. 90 / 8.1 %
Private ................................... 149 / 13.4 %

Or in a json format:

{
"filesystem": {
"directories": 10,
"files": 15
},
"lines_of_code": {
"code": 1064,
"code_relative": 95.4,
"comments": 51,
"comments_relative": 4.6,
"total": 1115
},
"structure": {
"namespaces": 11,
"classes": 14,
"class_methods": 88,
"class_constants": 0,
"interfaces": 1,
"traits": 0,
"enums": 0,
"functions": 5,
"global_constants": 3
},
"methods_access": {
"non_static": 82,
"non_static_relative": 93.2,
"static": 6,
"static_relative": 6.8
},
"methods_visibility": {
"public": 70,
"public_relative": 79.5,
"protected": 2,
"protected_relative": 2.3,
"private": 16,
"private_relative": 18.2
}
}

Longest files

Are you looking for top 10 longest files?

vendor/bin/lines measure --longest

Longest files line count
src/Measurements.php ............................... 320
src/Console/OutputFormatter/TextOutputFormatter.php 136
src/NodeVisitor/StructureNodeVisitor.php ........... 124
src/Console/Command/MeasureCommand.php .............. 98
src/Analyser.php .................................... 92

Scan package in /vendor

This tool measures your code, not the 3rd party libraries. It skips /vendor directory by default to avoid false positives. If you want to measure vendor files too, use --allow-vendor option:

vendor/bin/lines measure vendor/rector/rector --allow-vendor

2. PHP Feature Counter

Two codebases using PHP 8.4 in composer.json, are not the same codebases. One has zero type param/return/property declarations, other has promoted properties. Reveal their real value by counting PHP feature they actually use.

vendor/bin/lines features src

This command:

  • scans your codebase,
  • count PHP feature being used from which PHP version,
  • gives you quick overview of how modern the codebase really is

------------- ----------------------------------------------- ------------
PHP version Feature count
------------- ----------------------------------------------- ------------
7.0 Parameter types 2 793
7.0 Return types 1 736
7.0 Strict declares 492
7.0 Space ship <=> operator 0
------------- ----------------------------------------------- ------------
7.1 Nullable type (?type) 333
7.1 Void return type 317
7.1 Class constant visibility 557
------------- ----------------------------------------------- ------------
7.2 Object type 14
------------- ----------------------------------------------- ------------
7.3 Coalesce ?? operator 69
------------- ----------------------------------------------- ------------
7.4 Typed properties 156
7.4 Arrow functions 38
7.4 Coalesce assign (??=) 0
------------- ----------------------------------------------- ------------
8.0 Named arguments 10
8.0 Union types 147
8.0 Match expression 1
8.0 Nullsafe method call/property fetch 0
8.0 Attributes 0
8.0 Throw expression 111
8.0 Promoted properties 596
------------- ----------------------------------------------- ------------
8.1 First-class callables 8
8.1 Readonly property 3
8.1 Intersection types 0
8.1 Enums 0
------------- ----------------------------------------------- ------------
8.2 Readonly class 182
------------- ----------------------------------------------- ------------
8.3 Typed class constants 0
------------- ----------------------------------------------- ------------
8.4 Property hooks 0
------------- ----------------------------------------------- ------------

That's it. Happy coding!

TomasVotruba photo

@rectorphp

"If you don't want to do something, you'll find an excuse. If you really do, you'll find a way."

Open-Source for Life ❤️️

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Tomasvotruba Lines Related Articles

Debugging production Laravel apps without losing your mind image

Debugging production Laravel apps without losing your mind

Read article
ArtisanFlow: A Flowchart Engine for Laravel and Alpine.js image

ArtisanFlow: A Flowchart Engine for Laravel and Alpine.js

Read article
PHPantom: A Fast PHP Language Server Built in Rust image

PHPantom: A Fast PHP Language Server Built in Rust

Read article
Build an AI Chat Agent with Laravel 12, MongoDB Atlas Vector Search, and Voyage AI image

Build an AI Chat Agent with Laravel 12, MongoDB Atlas Vector Search, and Voyage AI

Read article
Lens for Laravel Brings WCAG Auditing to Your Local Dev Workflow image

Lens for Laravel Brings WCAG Auditing to Your Local Dev Workflow

Read article
Query Builder Expression Aliases in Laravel 12.48 image

Query Builder Expression Aliases in Laravel 12.48

Read article
Securing Laravel logo

Securing Laravel

The essential security resource for Laravel devs, covering everything you need to keep your apps secure. Sign up to receive weekly security tips and monthly in depth articles, diving deep into security concepts you need to know!

Securing Laravel
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Statamic logo

Statamic

The drop-in ready Laravel CMS you’re been waiting for. Go full-stack or headless, flat file or database – it’s up to you.

Statamic
LoadForge logo

LoadForge

Scalable load testing for web apps & APIs. Simulate real-world traffic and identify breaking points and performance limits with powerful, scalable load tests designed for Laravel.

LoadForge
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec