Function- and method-level metrics

Name Description Metric code ID Languages
Lines of code number of lines of code in the method or function; calculated as (last line number) - (first line number) + 1 LOC_METHOD 129 C/C++, Java
Number of operands used An operand is an identifier or a constant. This metric calculates the total number of identifiers and constants used in the function or method. Note that a method name is also an identifier. For this metric, a function call is considered an operator. NOOPUSED 130 C/C++, Java
Number of distinct operands used number of unique operands (variables and constants) used in the current function. Variables are distinguished by name, so usages of overridden variables do not contribute to this metric. Constants are distinguished by value, so all strings are assumed to be unique. For this metric, a function call is considered an operator. NODISOPUSED 131 C/C++, Java
Number of operators used number of operators used in the function or method. This metric counts the total number of accesses to variable, binary, ternary, unary, field access, index access, call, new instance of, expr-class, expression-this, and expression-super. All function calls are considered as operators. NOOPRUSED 132 C/C++, Java
Number of distinct operators used number of unique operators used in the function. Like NOOPRUSED, but function calls are considered as one unique operator. For example, Msg and printf function calls are counted only once. NODISOPRUSED 133 C/C++, Java
Number of returns number of return statements in the function (not return points) NORET 134 C/C++, Java
Cyclomatic complexity cyclomatic complexity (McCabe Cyclomatic Complexity metric) shows the number of areas plane is divided by control flow graph CYCLOMATIC 135 C/C++, C#, Java
Number of independent paths Calculates the natural logarithm of the number of independent paths through the function or method. A path is considered independent from a set of other paths if it cannot be expressed as a combination of that set paths' sub-paths. A function with an empty body has exactly one path through it. Additional contribution of non-control flow statements into the metric is zero. For each independent path entering an empty 'if' statement or a loop with an empty body and a simple condition clause, the metric is incremented. For example:
void foo(int i)
{
    /* This function has two independent paths, resulting in the metric being equal to ln(2) = 0.693 */
    if (i > 0) {
        /* This is one independent path */
    } else {
        /* This is the second independent path */
    }
}

void bar(int i)
{
    /* Nested control flow statements increase the number of paths in the branches where they are present,
       for every path at the beginning of that control flow statement */
    /* This function has nine independent paths, resulting in the metric being equal to ln(9) = 2.197 */
    if (i > 0) {
        /* First independent path */
        for (int j = 0; j < i; ++j) {
            /* Still the first independent path */
        }
        /* Second independent path (corresponding to j >= i) */
        /* There are two independent paths at the entry of this control flow statement.
           For each of them, the statement introduces 3 more independent paths */
        switch (i) {
            case 1:
                /* Still the part of the first or second original independent paths */
                break;
            case 2:
                /* 3-rd and 4-th independent paths */
                break;
            case 3:
                /* 5-th and 6-th independent paths */
                break;
            default:
                /* 7-th and 8-th independent paths */
                i++;
        }
    } else {
        /* 9-th independent path */
    }
}
Goto statements in C++ are not taken into consideration in this calculation. Each catch clause is considered to be an independent path. The metric calculation does not take into consideration reach-ability of the paths.
NOINDPATHS 136 C/C++, Java
Number of parameters number of parameters (arguments) in the function or method. In this example f(x,y+z, foo (g)) x, y+z, and g are parameters passed to other functions so the number would be 3. NOPARMS 137 C/C++, C#, Java
Number of calls to unique functions the number of calls from function or methods (for which metrics are calculated) to other functions or methods. Any number of calls to the same function or method adds only one to this metric. NOCALLS 138 C/C++, Java
Number of calls outside the class number of calls outside the class (number of calls to methods with different "this"): For a method, this metric is equal to the total number of calls minus the number of calls to other methods of the same class (including self). For a function that is not a method, this metric is equal to the total number of calls. NOCALLSOC 139 C/C++, Java
Number of parameters passed to other functions number of parameters passed to other functions. In this example, foo (int i) { bar (1, 2, 3); 700 (1); } the number is 4 NOPAROTHER 140 C/C++, Java
Number of executable statements number of executable and blank statements in the function or method. An executable statement is an operator such as a+=b; or a function call such as f(s+y, z). NOEXSTAT 141 C/C++, Java
Number of statements number of expression and control statements (if, for, while). This metric is the sum of NOCONTROLSTAT, NOEXSTAT, and NOMDECLSTAT for the function or method. NOSTAT 142 C/C++, Java
Number of loops number of for, while, and do-while statements in the current function NOLOOPS 143 C/C++, Java
Number of conditional statements number of if and switch statements in the current function NOIF 144 C/C++, Java
Number of else and case statements number of else and case statements in the current function. Default statements are not included. NOBRANCH 145 C/C++, Java
Maximum level of control nesting maximum level of nested control statements (if, switch, for, while, and do-while statements). The initial MAXLEVEL (for example, a function with no operators) is equal to 1. MAXLEVEL 146 C/C++, C#, Java
Average level of control nesting average number of executable statements in a function or method; calculated as the sum of the level of each executable statement for all statements in the function divided by the number of executable statements. If the number of executable statements is 0, AVERLEVEL is 0. AVERLEVEL 147 C/C++, Java
Number of local declarations number of data items declared locally within the function NOLOCDECL 148 C/C++, Java
Maximum number of executable statements in a conditional arc maximum number of executable statements located within the span of a branch of a conditional arc MAXCONDSPAN 149 C/C++, Java
Number of conditional arcs in the control graph of the function or method number of conditional branches in the control graph of the function or method (if, switch, do, while, or for statements) NOCONDARCS 150 C/C++, Java
Number of control statements in the function or method number of control statements (statements that operated control flow within a function or method). This metric calculates the number of loops or conditional statements (if, switch, do, while, for), plus the number of control-passing statements (return, break, continue, goto), plus the number of try-catch statements. NOCONTROLSTAT 151 C/C++, Java
Number of declarative statements in the function or method number of declarative statements in the function or method; for example, the declaration of a local array or a local variable. This differs from NOLOCDECL because 1 declaration statement can declare several local variables. NOMDECLSTAT 152 C/C++, Java
Number of accesses to global variables number of accesses (reads/writes) to variables defined outside the function or method NOACCTOGLOB 153 C/C++, Java
Bytes of local variables declared For more information about calculating this metric, see Specifying sizes for built-in types. BYTESLOCDECL 154 C/C++
Bytes of parameters for the function For more information about calculating this metric, see Specifying sizes for built-in types. BYTESPARMS 155 C/C++
Bytes of parameters passed to other functions For more information about calculating this metric, see Specifying sizes for built-in types. BYTESPAROTHER 156 C/C++
Number of calls to non-prototyped functions number of calls to non-prototyped functions. This metric depends on the completeness of the code. If code is compiled without includes, the metric would be only the number of calls (because no functions would be prototyped). NOCALLSNP 159 C/C++
Number of reads from global variables Number of reads from global variables READFGLOBAL 160 C/C++, Java
Number of writes to global variables Number of writes to global variables WRITETGLOBAL 161 C/C++, Java
Non-comment, non-blank lines of code in the function or method the number of lines of code in a function or method, not including comment lines and blank lines NCNBLOC_METHOD 162 C/C++, C#, Java
Number of bytes of local variables and parameters declared in the function This metric is the sum of the BYTESPARMS and BYTESLOCDECL metrics. For more information about calculating this metric, see Specifying sizes for built-in types. BYTESSTACKSIZE 163 C/C++
Extended cyclomatic complexity Extended cyclomatic complexity includes logical Boolean operators in the decision count. Whenever Klocwork finds a logical Boolean operator (&& or |) within a conditional statement, EXTCYCLOMATIC increases by one. The conditionals Klocwork considers are: If, IfElse, While, DoWhile, For and Switch. EXTCYCLOMATIC 164 C/C++
Plain cyclomatic complexity Like Cyclomatic complexity (metric code 135), but is calculated on plain code (before preprocessor expansion). Any conditional statements generated from macro definitions do not result in PLAINCYCLOMATIC metric. PLAINCYCLOMATIC 165 C/C++
Plain extended cyclomatic complexity Like Extended cyclomatic complexity (metric code 164), but is calculated on plain code (before preprocessor expansion). Any conditional statements generated from macro definitions do not result in PLAINEXTCYCLOMATIC metric. PLAINEXTCYCLOMATIC 166 C/C++