计算Netbeans PHP项目的代码行

0xD*_*EEF 5 php metrics netbeans loc

我如何计算Netbeans PHP项目的LOC?

我在Windows 7上使用Netbeans 7.0.1

Kri*_*ris 5

我还没有找到一种方法在netbeans(在任何操作系统上)这样做,但我想你可以逃脱以下的事情:

将这个小脚本保存在可以找到它的地方:(比如说"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]));
Run Code Online (Sandbox Code Playgroud)

并在命令行(cmd.exe)上使用它:

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

通过一些小技巧,我确信你可以创建一个快捷方式,你可以把它放在快速启动栏上或在其他工具中使用它.

我刚刚输入错误,可能有错误,主要是在SO文本框中.