In this post to his site Matt Stauffer shares several methods you can use to count the total number of lines of code in a PHP project.
I'm giving a talk soon about Laravel and "the enterprise", and the concept of LOC (lines of code) keeps coming up. It turns out that's actually a much harder number to discover than you might think, so I figured I would write up a few options here.
For what it's worth, I'm not a big fan of LOC as a measure of any importance, but it can at least give us some broad foundations to use to talk about broad differences in project size. If you were to ask me, I would say we shouldn't even think about it. But we don't always have that luxury.
He starts with a tl;dr for those that want the quick win (use PHPLOC) but shares other options with different tools too:
- https://github.com/AlDanial/cloc - a smarter version of PHPLOC that accounts for empty lines, comments, etc
- the Statistic plugin for PHPStorm
- a regular expression match for use in Sublime Text
- manually from the command line using
- using the Silver Searcher tool
He shares answers to a few FAQs about finding lines of code and the output of each tool/command on the same project to show the differences.