Generate Lines Of Code And Comment Statistics Using phploc

Loading

You have been writing a lot of PHP code and want to generate statistics about the number of comment and code lines in your application. Maybe you want to generate statistics about some PHP project. You can do it with just one command.

phploc helps you quickly generate numbers about the size of a PHP project.

You can install phploc from the PEAR installer. The PHP PEAR package itself is most likely available from your distribution vendor.

Once you have installed PHP PEAR you have to add the pear.phpunit.de channel.

pear channel-discover pear.phpunit.de

Next step is to install phploc.

pear install phpunit/phploc

Now you should be ready to generate statistics.

Let's run it against Drupal. I have downloaded Drupal and extracted the files in /home/sudheer/download/drupal.

phploc /home/sudheer/localnfs/download/drupal/

The output looks like

phploc 1.1.1 by Sebastian Bergmann.
 
Directories:                               15
Files:                                     63
 
Lines of Code (LOC):                     4697
Comment Lines of Code (CLOC):            2145
Non-Comment Lines of Code (NCLOC):       2552
 
Interfaces:                                 0
Classes:                                    0
Non-Static Methods:                         0
Static Methods:                             0
Functions:                                 51

I recently ran phploc against BizSense and published the results at Binary Vibes Blog.

Looking at the results, you can have an overview of how object oriented is your application. The ration of comments to code is often an interesting metric. When you are asked to work on an existing PHP application, running phploc can help you get an overview of the project code base. You can also use it to compare the growth of your application from one version to another.

Generate statistics about your PHP project and let us know how useful is phploc.

About the author

Sudheer is an entrepreneur and software developer. Get more from Sudheer on Twitter.


Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>. The supported tag styles are: <foo>, [foo].

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.