Skip to main content

count lines in a PHP project



I'm just curious. Do you know any tool which can count all the code lines from a PHP project?





Many thx!



Source: Tips4all

Comments

  1. On a POSIX operating system (e.g. Linux or OS X) you can write the following into your Bash shell:

    wc -l `find . -iname "*.php"`


    This will count the lines in all php-files in the current directory and also subdirectories. (Note that those single 'quotes' are backticks, not actual single quotes)

    ReplyDelete
  2. SLOCCount is an awesome tool that produces a line-count report for a large number of languages. It also goes further by producing other, related statistics such as expected developer cost.

    Here's an example:

    $ sloccount .
    Creating filelist for experimental
    Creating filelist for prototype
    Categorizing files.
    Finding a working MD5 command....
    Found a working MD5 command.
    Computing results.


    SLOC Directory SLOC-by-Language (Sorted)
    10965 experimental cpp=5116,ansic=4976,python=873
    832 prototype cpp=518,tcl=314


    Totals grouped by language (dominant language first):
    cpp: 5634 (47.76%)
    ansic: 4976 (42.18%)
    python: 873 (7.40%)
    tcl: 314 (2.66%)




    Total Physical Source Lines of Code (SLOC) = 11,797
    Development Effort Estimate, Person-Years (Person-Months) = 2.67 (32.03)
    (Basic COCOMO model, Person-Months = 2.4 * (KSLOC**1.05))
    Schedule Estimate, Years (Months) = 0.78 (9.33)
    (Basic COCOMO model, Months = 2.5 * (person-months**0.38))
    Estimated Average Number of Developers (Effort/Schedule) = 3.43
    Total Estimated Cost to Develop = $ 360,580
    (average salary = $56,286/year, overhead = 2.40).
    SLOCCount, Copyright (C) 2001-2004 David A. Wheeler
    SLOCCount is Open Source Software/Free Software, licensed under the GNU GPL.
    SLOCCount comes with ABSOLUTELY NO WARRANTY, and you are welcome to
    redistribute it under certain conditions as specified by the GNU GPL license;
    see the documentation for details.
    Please credit this data as "generated using David A. Wheeler's 'SLOCCount'."

    ReplyDelete
  3. Unfortunately, SLOCCount is a bit long in the tooth and a pain in the neck for PHP projects, particularly ones that have a nested vendor directory you don't want counted. Also, it emits a warning for every PHP file that doesn't have a closing tag (which should be all of them if you aren't mixing HTML and PHP).

    CLOC is a more modern alternative that does everything SLOCCount does, but also supports an --exclude-dir option and it doesn't suffer from the aforementioned close tag problem. It also emits a SQLite database that you can extract some pretty advanced metrics from.

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.