Count Lines of Code on Netbeans PHP Project [closed]
Asked Answered
H

4

6

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

i´m using Netbeans 7.0.1 on Windows 7

Hectare answered 1/11, 2011 at 16:28 Comment(1)
I remember that there isn't the support for this but I could be wrong.Allot
S
5

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.

Scream answered 1/11, 2011 at 16:53 Comment(2)
note that this will see comments etc. as code. but you could change countLinesInFile to only found lines not starting with "~\s+?(\/\/|#)~" to get a somewhat more accurate reading without comments.Scream
netbeans does not offer such a feature for php-projects apparently... so this is a solution that works ide-independent (+1) and is enough for now. thanksHectare
T
2

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.

Tactics answered 12/8, 2014 at 10:57 Comment(1)
Does not support for above PHP 7.2 is no longer supported.Salpinx
B
0

you can use ProjectCodeMeter to count logical lines of code (LLOC) on any php project (it is aware of comments and empty lines)

Backstairs answered 4/11, 2011 at 7:45 Comment(0)
H
0

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

Hilburn answered 7/6, 2016 at 21:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.