Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count Lines of Code on Netbeans PHP Project [closed]

How can i count the LOC of a Netbeans PHP-Project?

i´m using Netbeans 7.0.1 on Windows 7

like image 831
0xDEADBEEF Avatar asked Nov 01 '11 16:11

0xDEADBEEF


2 Answers

I haven't found a way to do that in netbeans (on any OS) but i guess you could get away with something like the following:

Save this little script someplace where you can find it: (lets 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 commandline (cmd.exe):

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

With some minor trickery I'm sure you can create a shortcut to it that you can put on the quick launch bar or use it in some other tooling.

Might have bugs since I typed it just now, mostly in the SO text box.

like image 53
Kris Avatar answered Nov 18 '22 11:11

Kris


I was looking for the same and stumbled over this question, but the accepted answer is only for LOC, not for LLOC, and ProjectCodeMeter seems to be a bit overkill.

What I found as a working solution for me: phploc by Sebastian Bergmann. Works like a charm.

like image 2
hchr Avatar answered Nov 18 '22 12:11

hchr