New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

foreach and while are not counted as LLOC #63

Closed
gooh opened this Issue Sep 2, 2013 · 1 comment

Comments

Projects
None yet
2 participants
@gooh
Copy link

gooh commented Sep 2, 2013

When running PHPLoc 2.0.0 on the following code

function fn()
{
    foreach([1,2,3] as $i) {
        echo $i;
    }
}

I get the following metrics

Lines of Code (LOC)                                6
Non-Comment Lines of Code (NCLOC)                  6 (100.00%)
Logical Lines of Code (LLOC)                       1 (16.67%)
  Functions                                        1 (100.00%)
    Average Function Length                        1
  Not in classes or functions                      0 (0.00%)

I get the same when using while instead of foreach.

The problem seems to be in line https://github.com/sebastianbergmann/phploc/blob/master/src/Analyser.php#L306:

if ($token == ';') {
    if ($className !== NULL && !$testClass) {
        $this->count['llocClasses']++;
    }

    else if ($functionName !== NULL) {
        $this->count['llocFunctions']++;
    }

    $this->count['lloc']++;
}

So apparently you are only counting the statements when terminate with a semicolon. But since while and foreach are both executable statements, they should be counted, shouldn't they?

@sebastianbergmann

This comment has been minimized.

Copy link
Owner

sebastianbergmann commented Sep 2, 2013

Logical Lines of Code (LLOC) are the number of semicolon-terminated statements. This means that for (;;) is counted as two LLOC whereas while and foreach are not counted towards LLOC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment