The famous phploc package to measure project size was archived by Sebastian on Jan 10, 2023. I used this package to get feedback on CLI apps vendor shrink and for fast estimation of project size in Rector upgrades.
That's why I needed a replacement. Fast!
There are a few forks kind of working, but they don't provide enum support, rely on PHP tokens, and conflict with installation.
You might also suggest generic Linux tools like cloc, but it requires specific operation system, thus different installation etc. Also it doesn't provide PHP-specific metrics that will give you better idea about project code quality :
I told myself, "Maybe we can use more reliable tooling to handle this, like php-parser," and I didn't stop there. I shared my idea on Twitter, and the feedback gave me the energy to think more deeply about this.
When we look at "why" such a package is used and what people need from it, we come to a few key points:
/vendor, so anyone can install it on any project with composer requireA few days later, the prototype package was born:
Using lines the first time for writing a post with real data:
— Tomas Votruba (@VotrubaT) August 2, 2023
What is a quick size of the vendor?
* Too long? Make it short 😉
* Too verbose? Make it json 😉 pic.twitter.com/FRsqsNXUJE
composer require tomasvotruba/lines --dev
vendor/bin/lines measure src
vendor/bin/lines measure src --json --short
To get ↓
{
"filesystem": {
"directories": 174,
"files": 753
},
"lines_of_code": {
"code": 42627,
"code_relative": 65.4,
"comments": 22545,
"comments_relative": 34.6,
"total": 65172
}
}
This command is perfect for blog posts, as it gives you a idea about the size without the clutter.
That's it!
Before I even managed to launch the package, Francisco jumped in and gave the CLI output a fresh and sexy look ↓
Give the lines a try, and if you want to improve the package, just go for it!
Happy coding!