PDepend\Metrics\Analyzer\NodeLocAnalyzer::linesOfCode PHP Method

linesOfCode() private method

ELOC = Non Whitespace Lines + Non Comment Lines array( 0 => 23, // Comment Lines Of Code 1 => 42 // Executable Lines Of Code )
private linesOfCode ( array $tokens, boolean $search = false ) : array
$tokens array The raw token stream.
$search boolean Optional boolean flag, search start.
return array
    private function linesOfCode(array $tokens, $search = false)
    {
        $clines = array();
        $elines = array();
        $llines = 0;
        $count = count($tokens);
        if ($search === true) {
            for ($i = 0; $i < $count; ++$i) {
                $token = $tokens[$i];
                if ($token->type === Tokens::T_CURLY_BRACE_OPEN) {
                    break;
                }
            }
        } else {
            $i = 0;
        }
        for (; $i < $count; ++$i) {
            $token = $tokens[$i];
            if ($token->type === Tokens::T_COMMENT || $token->type === Tokens::T_DOC_COMMENT) {
                $lines =& $clines;
            } else {
                $lines =& $elines;
            }
            switch ($token->type) {
                // These statement are terminated by a semicolon
                //case \PDepend\Source\Tokenizer\Tokens::T_RETURN:
                //case \PDepend\Source\Tokenizer\Tokens::T_THROW:
                case Tokens::T_IF:
                case Tokens::T_TRY:
                case Tokens::T_CASE:
                case Tokens::T_GOTO:
                case Tokens::T_CATCH:
                case Tokens::T_WHILE:
                case Tokens::T_ELSEIF:
                case Tokens::T_SWITCH:
                case Tokens::T_DEFAULT:
                case Tokens::T_FOREACH:
                case Tokens::T_FUNCTION:
                case Tokens::T_SEMICOLON:
                    ++$llines;
                    break;
                case Tokens::T_DO:
                case Tokens::T_FOR:
                    // Because statements at least require one semicolon
                    --$llines;
                    break;
            }
            if ($token->startLine === $token->endLine) {
                $lines[$token->startLine] = true;
            } else {
                for ($j = $token->startLine; $j <= $token->endLine; ++$j) {
                    $lines[$j] = true;
                }
            }
            unset($lines);
        }
        return array(count($clines), count($elines), $llines);
    }