Netbeans PHP Project Code Line Graphs

How can I calculate the LOC of a Netbeans PHP project?

I am using Netbeans 7.0.1 on Windows 7

+5
source share
4 answers

I did not find a way to do this in netbeans (on any OS), but I think you could get away from something like the following:

Save this little script somewhere where you can find it: (let's say "cntln.php")

<?php

function countLinesInFile($fileInfo)
{
    return count(file($fileInfo));
}

function countLinesInDir($directory, $filePattern)
{
    $total = 0;
    $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
    foreach($iterator as $fileInfo)
    {
        if (-1 < preg_match($filePattern, $fileInfo->getFileName()))
        {
            $total += countLinesInFile($fileInfo);
        }
    }
    return $total;
}

function usage($argv)
{
    printf("usage: php -q %s <directory> <filematch>\n", reset($argv));

    printf(" - directory: path to the root directory of a project.\n");
    printf(" - filematch: regex pattern for files to include.\n");

    return 1;
}

if (count($argv) < 3)
{
    die(usage($argv));
}

printf("%d\n", countLinesInDir($argv[1], $argv[2]));

and use it on the command line (cmd.exe):

c:> php -q cntln.php "C:\projects\foo" "~\.php$~"

With some minor tricks, I'm sure you can create a shortcut for it that you can put on the quick launch bar or use it in some other tools.

, , SO.

+5

, LOC, LLOC, ProjectCodeMeter, , .

: phploc . .

+2

you can use ProjectCodeMeter to count logical lines of code (LLOC) in any php project (it knows about comments and empty lines)

0
source

You can use PDepend or PHPMetrics. Both are free open source projects.

0
source

All Articles