6

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

我在 Windows 7 上使用 Netbeans 7.0.1

4

4 回答 4

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]));

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

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

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

可能有错误,因为我刚刚输入它,主要是在 SO 文本框中。

于 2011-11-01T16:53:14.950 回答
2

我一直在寻找相同的问题并偶然发现了这个问题,但接受的答案仅适用于 LOC,不适用于 LLOC,而且 ProjectCodeMeter 似乎有点矫枉过正。

我发现对我来说是一个可行的解决方案: Sebastian Bergmann 的phploc。奇迹般有效。

于 2014-08-12T10:57:32.413 回答
0

您可以使用 ProjectCodeMeter 计算任何 php 项目的逻辑代码行数 (LLOC)(它知道注释和空行)

于 2011-11-04T07:45:58.323 回答
0

您可以使用 PDepend 或 PHPMetrics。两者都是免费的开源项目

于 2016-06-07T21:13:47.907 回答