How to measure # of lines of code in project?
Asked Answered
P

7

8

How can I measure number of lines of code in my PHP web development projects?

Edit: I'm interested in windows tools only

Polarization answered 13/1, 2009 at 4:7 Comment(0)
V
-3

If you're using a full fledged IDE the quick and dirty way is to count the number of "\n" patterns using the search feature (assuming it supports regexes)

Varicelloid answered 13/1, 2009 at 4:9 Comment(2)
Lines of code is not the same as number of lines in the file. Especially for PHP, which often has code interspersed with markup.Theory
Which is why I was so surprised. :)Varicelloid
S
28

Check CLOC, it's a source code line counter that supports many languages, I always recommend it.

It will differentiate between actual lines of code, blank lines or comments, it's very good.

In addition there are more code counters that you can check:

Saltigrade answered 13/1, 2009 at 4:9 Comment(5)
All of these are linux tools, do you have any windows ones?Polarization
Hey, check the download link of CLOC, downloads.sourceforge.net/cloc/…Sthenic
I did download it but i got a blank DOS screen and then it disappeared?Polarization
It's a console app!, you have to run it from the command line, i.e. cloc-1.06.exe C:\myProject\folderSthenic
Thanks, i tried it but there's something wrong, it said there were only 3 PHP files in my project? that's impossible. Other than that it seems very useful :)Polarization
E
4

phploc

No experience if it runs on Windows, tho, but searching on the web showed some results of people getting it to work on Windows..

Eaves answered 9/5, 2012 at 7:42 Comment(0)
D
1

If you are on a linux box, the easiest way is probably directed by this SO question:

count (non-blank) lines-of-code in bash

Discomfortable answered 13/1, 2009 at 4:10 Comment(0)
P
1

If you are using VS code, install this extension called Lines of Code (LOC)

After installation, use ctrl+p, type linecount, and you will find below options.

enter image description here

Count Workspace files will give the output in the following format.

enter image description here

This works on any OS with VS Code with the above plugin installed.

Peptidase answered 25/1, 2023 at 15:24 Comment(0)
V
1
  1. npm install -g cloc
  2. Go to the project folder
  3. Delete the node_modules and dist folder (if you have any), Because you don't need to calculate loc in dist and node_modules
  4. inside the project folder
  5. run this command: cloc *

Output will look like this :

enter image description here

Vassallo answered 6/2, 2023 at 9:14 Comment(0)
U
0

Our SD Source Code Search Engine is a GUI for searching across large bodies of source code such as a PHP web site. It is fast because it preindexes the source code.

As a side effect of the indexing process, it also computes metrics on the source code base, including SLOC, Comments, blank lines, Cyclomatic and Halsted complexity numbers.

And it runs on Windows.

Ultrared answered 24/8, 2009 at 22:2 Comment(1)
Downvoter: what's the objection? It not only counts code lines accuratly but also provides additional metrics data.Ultrared
V
-3

If you're using a full fledged IDE the quick and dirty way is to count the number of "\n" patterns using the search feature (assuming it supports regexes)

Varicelloid answered 13/1, 2009 at 4:9 Comment(2)
Lines of code is not the same as number of lines in the file. Especially for PHP, which often has code interspersed with markup.Theory
Which is why I was so surprised. :)Varicelloid

© 2022 - 2024 — McMap. All rights reserved.