Metrics Reference

Category: Size
Other names: Number of Lines of Code
Languages: C, C++
Targets: Variable, Function, Type, File, Folder, Project

This metric counts all lines of code in the measured entity, including lines containing white space and comments. In the case of variable definitions the count also includes the initializer expression if present. In the case of structured types (e.g. classes, structs) the count also includes the definitions of its members even if defined in a different file than the file containing the structured type definition. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

References: Lorenz94, Henderson95

Category: Size

Languages: C, C++
Targets: Project

This metric counts the assemblies contained in the measured entity. An assembly is the binary output of a linking process. It may take the form of a library, a library archive, or an executable file. The assemblies are defined in the build process and typically represent self-contained independent components, which can be used separately in multiple systems. Typically, the compilation of a system results in a single final assembly, which in turn may contain other assemblies. This metric aggregates above the project level as the sum of the metric values computed on the contained projects.

Category: Size

Languages: C, C++
Targets: Type, File, Folder, Project

This metric counts the attributes (member variables) of a structured type. The count does not include the attributes of contained member structured types. In the case of a file the count includes only the attributes actually defined in the file in question, so static class attributes which are only declared and not defined in a header file are not counted. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

References: Lorenz94

Category: Size

Languages: C++
Targets: File, Folder, Project

This metric counts all classes defined in the measured entity. The count also includes member class definitions contained in the counted classes. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

References: Riel96, Singham08

Category: Size

Languages: C, C++
Targets: Type, File, Folder, Project

This metric counts all function definitions (global functions, methods, constructors, operator overloads, etc.) contained in the definition of the measured entity. In the case of structured types (e.g. classes, structs) the count also includes the functions defined in the contained member structured types. So if a class definition contains a member class definition, the functions defined in the contained member class definition will also be counted. In the case of a file only the functions defined in that file are counted. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Size

Languages: C, C++
Targets: File, Folder, Project

This metric counts the global functions defined in a file. The count does not include global functions declared as extern, because such functions are only declared and not defined in the file in question. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Size

Languages: C, C++
Targets: File, Folder, Project

This metric counts the global variables defined in a file. The count does not include global variables declared as extern, because such variables are only declared and not defined in the file in question. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Size

Languages: C, C++
Targets: Function, Type, File, Folder, Project

This metric counts the local variables defined in a function body. Same name variables defined in disjoint code blocks are counted separately. This metric aggregates above the function level as the sum of the metric values computed on the contained functions.

Category: Size

Languages: C++
Targets: Type, File, Folder, Project

This metric counts all methods (including constructors, destructors, and operator overloads) defined in the measured entity. The count also includes abstract (pure virtual) methods. While abstract methods have no definitions, they are counted becuase they belong to the enclosing structured type’s interface. In the case of structured types (e.g. classes, structs) the count does not include the methods defined in the contained member structured types. So if a class definition contains a member class definition, the methods defined in the contained member class definition will not be counted. In the case of a file only the methods defined in that file are counted, so for a header file containing a structured type definition, whose methods are only declared (not defined) in this header file, the count will not include these methods. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Size

Languages: C, C++
Targets: File, Folder, Project

This metric counts the modules in the measured file. A module represents the parsable source code inside a file. Note that the value of this metric is 1 if the file in question contains parsable source code and 0 otherwise. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Size

Languages: C++
Targets: Type, File, Folder, Project

This metric counts the public attributes (member variables) of a structured type. The count does not include the attributes of contained member structured types. In the case of a file the count includes only the attributes actually defined in the file in question, so public static class attributes which are only declared and not defined in a header file are not counted. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

References: Lanza06

Category: Size

Languages: C++
Targets: Type, File, Folder, Project

This metric counts all public methods (including constructors, destructors, and operator overloads) defined in the measured entity. The count also includes abstract (pure virtual) methods. While abstract methods have no definitions, they are counted becuase they belong to the enclosing structured type’s interface. In the case of structured types (e.g. classes, structs) the count does not include the methods defined in the contained member structured types. So if a class definition contains a member class definition, the methods defined in the contained member class definition will not be counted. In the case of a file only the methods defined in that file are counted, so for a header file containing a structured type definition, whose methods are only declared (not defined) in this header file, the count will not include these methods. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

References: Lanza06

Category: Size

Languages: C, C++
Targets: Folder, Project

This metric counts the source folders contained in the measured entity. A source folder must contain at least one module (file containing parsable source code). If a source folder contains subfolders, the subfolders which are also source folders are counted separately. This metric aggregates above the folder level as the sum of the metric values computed on the contained folders.

Category: Size

Languages: C, C++
Targets: File, Folder, Project

This metric counts all structs defined in the measured entity. The count also includes member struct definitions contained in the counted structs. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Size

Languages: C, C++
Targets: File, Folder, Project

This metric counts all type definitions (classes, structs, unions and typedefs) contained in the measured entity. The count also includes member type definitions contained in the counted structured types. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Size

Languages: C, C++
Targets: Function, Type, File, Folder, Project

This metric counts all variable definitions (local varibales, formal parameters, class attributes, enum constants, global variables, etc.) contained in the definition of the measured entity. In the case of structured types (e.g. classes, structs) the count also includes the variables defined in the contained member structured types. So if a class defini tion contains a member class definition, the variables defined in the contained member class definition will also be counted. In the case of a file the count includes only the variables actually defined in the file in question. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Complexity
Other names: Conditional Complexity
Languages: C, C++
Targets: Function, Type, File, Folder, Project

This metric represents the number of linearly-independent control-flow paths through a function body and is determined by adding 1 to the number of decision points within the function body (even an empty body has at least one control-flow path through it). A decision point is one of the following:

  • an “if” statement
  • a “case” branch of a switch statement
  • a loop statement (“for”, “while”, or “do-while” statement)
  • an exception handler (“catch” block)
  • a ternary conditional expression (a < 10 ? a : 10)
  • a short-circuit logical operator (“&&” or “||” operator).

A high cyclomatic complexity makes the implementation of a function difficult to understand. In the case of structured types (e.g. classes, structs) this metric also sums up the cyclomatic complexities of the contained initializer blocks, because these are essentially unnamed functions implicitly called at instantiation. This metric aggregates above the function level as the sum of the metric values computed on the contained functions.

References: McCabe76, Lorenz94

Category: Complexity
Other names: Maximum Nesting Level, Depth of Conditional Nesting
Languages: C, C++
Targets: Function, Type, File, Folder, Project

This metric represents the maximum depth of control structure nesting within a function body. Within this context, control structure means either a decision statement (e.g. “if”, “switch” statement), a loop statement (e.g. “for”, “while” statement) or a “try” statement. In the case of structured types (e.g. classes, structs) this metric also takes into account the nesting depth of initializer blocks, because these are essentially unnamed functions implicitly called at instantiation. This metric aggregates above the function level as the maximum of the metric values computed on the contained functions.

References: French99, Sommerville01

Category: Complexity

Languages: C, C++
Targets: Function, Type, File, Folder, Project

This metric counts the number of formal parameters of a function. A high number of parameters makes the function difficult and error prone to use. This metric aggregates above the function level as the sum of the metric values computed on the contained functions.

References: Fenton97

Category: Complexity

Languages: C, C++
Targets: Function, Type, File, Folder, Project

This metric counts the number of statemnts within a function body. The count explicitly excludes all block statements (including “catch” and “finally” blocks”), individual branches of a conditional statement (e.g. “case” branch, “default” branch, “else” branch), initialization statements of “for” statement, and label statements. This does not mean that other kinds of statements, contained within the excluded statements are also excluded. In the following example, the value of this metric is 4, because the block statement surrounding the positive branch of the “if” statement and the “else” branch are not counted. Also the initialization statemnt of the “for” statement (“int i = 0”) is not counted.

for (int i = 0; i < b; i++)  // First statement is the "for" statement
  if (a[i] < i) {            // Second statement is the "if" statement
    a[i] = i;                // Third statement is the assignment
  }
  else
    return i;                // Fourth statement is the "return" statement

In the case of structured types (e.g. classes, structs) this metric also counts the statements contained in initializer blocks, because these are essentially unnamed functions implicitly called at instantiation. This metric aggregates above the function level as the sum of the metric values computed on the contained functions.

Category: Complexity

Languages: C++
Targets: Type, File, Folder, Project

This metric counts the number of methods (including operator overloads, but not constructors and destructors) which can potentially be executed in response to a message received by an object of the measured class. This includes all methods of the measured class, all inherited methods, and all external methods directly called from the methods of the measured class. Static methods are also counted and each method is counted only once, regardless of the number and locations of the calls to it. Classes having a large value of this metric are more complex and harder to understand, making their testing and debugging more complicated. As a result, this metric has been shown to correlate with the number of faults associated with the measured class. This metric aggregates above the type level as the average of the metric values computed on the contained types.

References: Chidamber94

Category: Complexity

Languages: C++
Targets: Type, File, Folder, Project

This metric calculates the sum of the Cyclomatic Complexity (CYCLO) metric of all the methods (including constructors, destructors, and operator overloads) contained in the measured entity. In the case of structured types (e.g. classes, structs) the metric ignores methods defined in contained member structured types. So if a class definition contains a member class definition, the methods defined in the contained member class definition will not be considered. In the case of a file only the methods defined in that file are considered. This metric aggregates above the type level as the sum of the metric values computed on the contained types.

References: Chidamber94

Category: Complexity

Languages: C++
Targets: Type, File, Folder, Project

This metric quantifies the amount of functionality provided by the measured class. It is computed based on the Number of Public Attributes (NOPUA) and Number of Public Methods (NOPUM) metrics using the formula:

WOC = #FunctionalMethods / (NOPUA + NOPUM)

where #FunctionalMethods is the number of functional public methods defined in the measured class. A functional method is a non-empty method, which does not return a constant value and is not an accessor. A low value of this metric indicates a structured type, which provides little to no functionality to its clients. This metric aggregates above the type level as the average of the metric values computed on the contained types.

References: Lanza06

Category: Coupling

Languages: C, C++
Targets: Function, Type, File, Folder

This metric represents the incoming coupling of the measured entity. It counts the number of distinct entities of the same kind as the measured entity (e.g. functions, types, files, etc.) referencing the measured entity. The count does not include the measured entity, even if it references itself. The measured entity is considered to be referenced if the referencing entity contains:

  • a reference to the definition of the measured entity
  • a reference to any declaration of the measured entity
  • a reference to an entity defined or declared in the measured entity
  • a reference to any declaration of an entity defined in the measured entity.

This metric does not aggregate.

References: Martin02

Category: Coupling

Languages: C++
Targets: Type, File, Folder, Project

This metric counts the number of other structured types (e.g. classes, structs) coupled to the measured structured type. A structured type is considered to be coupled to another structured type in the following cases:

  • it references the other structured type (through a type reference)
  • it references a declaration of the other structured type (through a type reference)
  • it is referenced by the other structured type (through a type reference)
  • one of its declarations is referenced by the other structured type (through a type reference)
  • it references a member definition or declaration of the other structured type (through a type reference, operation call, operation access, or data access)
  • one of its member definitions or declarations is referenced by the other structured type (through a type reference, operation call, operation access, or data access)

This metric aggregates above the type level as the average of the metric values computed on the contained types.

References: Chidamber94, Briand99

Category: Coupling

Languages: C, C++
Targets: Function, Type, File, Folder

This metric represents the outgoing coupling of the measured entity. It counts the number of distinct entities of the same kind as the measured entity (e.g. functions, types, files, etc.) referenced by the measured entity. The count does not include the measured entity, even if it references itself. A measured entity is considered to reference a target entity if the measured entity contains:

  • a reference to the definition of the target entity
  • a reference to any declaration of the target entity
  • a reference to an entity defined or declared in the target entity
  • a reference to any declaration of an entity defined in the target entity.

This metric does not aggregate.

References: Martin02

Category: Coupling
Other names: Foreign Data Providers
Languages: C++
Targets: Variable, Function, Type, File, Folder

This metric counts the number of distinct classes defining or declaring variables (e.g. member variables) accessed from the measured entity. A variable is accessed from the measured entity if the measured entity contains a data access to the definition or any declaration of the variable in question. The count does not include:

  • the measured entity itself (if applicable)
  • the enclosing class of the measured entity (if applicable)
  • classes defined in the measured entity (if applicable)

This metric does not aggregate.

References: Briand99

Category: Coupling
Other names: Foreign Data Providers
Languages: C, C++
Targets: Variable, Function, Type, File, Folder

This metric counts the number of distinct modules defining or declaring variables (e.g. global variable, member variables) accessed from the measured entity. A variable is accessed from the measured entity if the measured entity contains a data access to the definition or any declaration of the variable in question. The count does not include:

  • the measured entity itself (if applicable)
  • the enclosing module of the measured entity (if applicable)
  • modules contained in the measured entity (if applicable)

This metric does not aggregate.

References: Briand99

Category: Coupling
Other names: Instability
Languages: C, C++
Targets: Function, Type, File, Folder

This metric indicates the instability of the measured entity, represented by its lack of resilience to change. It is computed based on the Afferent Coupling (Ca) and Efferent Coupling (Ce) metrics using the formula:

IF = Ce / (Ca + Ce)

The value of this metric is in the range [0, 1], with 0 representing a completely stable entity and 1 representing a completely unstable entity. In case of an entity having no incoming and no outgoing coupling (Ca = Ce = 0), by convention the value of this metric is 0. This metric does not aggregate.

References: Martin02

Category: Coupling

Languages: C++
Targets: Type, File, Folder, Project

This metric counts all accessor methods (including operator overloads) defined in the measured entity. An accessor method is a method whose entire behaviour consists of either setting or getting the value of a data member. If a method contains any additional behavior (including dereferencing a pointer data member), the method is not considered an accessor. In the case of structured types (e.g. classes, structs) the count does not include the methods defined in the contained member structured types. So if a class definition contains a member class definition, the methods defined in the contained member class definition will not be counted. In the case of a file only the methods defined in that file are counted, so for a header file containing a structured type definition, whose methods are only declared (not defined) in this header file, the count will not include these methods. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Coupling

Languages: C, C++
Targets: Variable, Function, Type, File, Folder, Project

This metric counts all accesses to data entities (local variable, class attribute, etc.) contained in the definition of the measured entity. Any reference to a data entity, regardless of the role it plays in an expression (lvalue, rvalue, etc.) is considered an access to the data entity. Only explicit accesses are considered, meaning that the accesses themselves must have a representation in the source code after all macros have been expanded. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Coupling

Languages: C, C++
Targets: Variable, Type, File, Folder

This metric counts all incoming accesses to the measured entity or its contained data entities (global variable, class attribute, etc.) from outside the measured entity. This also includes accesses to all declarations of the measured entity and all declarations of its contained data entities. Any reference to a data entity, regardless of the role it plays in an expression (lvalue, rvalue, etc.) is considered an access to the data entity. Only explicit accesses are considered, meaning that the accesses themselves must have a representation in the source code after all macros have been expanded. In the case of structured types (e.g. classes, structs) the count also includes incoming accesses to member data entities of the contained member structured types. So if a class definition contains a member class definition, the incoming accesses to all attributes of the contained member class definition are also counted. In the case of a file, all incoming accesses from outside the file to all data entities defined and declared in that file are counted. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Coupling

Languages: C, C++
Targets: File, Folder

This metric counts all incoming module references to the measured entity or its contained entities from outside the measured entity. A module reference is a reference to an external file by using its name in an include statement. Only explicit references are taken into account, meaning that the references themselves must have a representation in the source code after all macros have been expanded. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Coupling

Languages: C, C++
Targets: Function, Type, File, Folder

This metric counts all incoming operation accesses to the measured entity or its contained operations (including overloaded operators, constructors, or destructors) from outside the measured entity. An operation access is a use of an operation name in an expression other than a call, which does not result in the operation being called. A typical example of an operation access if the use of an operation’s address in an assignment to a function pointer. This also includes accesses to all declarations of the measured entity and all declarations of its contained operations. Only explicit accesses are considered, meaning that the accesses themselves must have a representation in the source code after all macros have been expanded. In the case of structured types (e.g. classes, structs) the count also includes incoming accesses to methods of the contained member structured types. So if a class definition contains a member class definition, the incoming accesses to all methods of the contained member class definition are also counted. In the case of a file, all incoming accesses from outside the file to all operations defined and declared in that file are counted. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Coupling

Languages: C, C++
Targets: Function, Type, File, Folder

This metric counts all incoming operation calls to the measured entity or its contained operations (including overloaded operators, constructors, or destructors) from outside the measured entity. This also includes calls to all declarations of the measured entity and all declarations of its contained operations. Only explicit calls are taken into account, meaning that the calls themselves must have a representation in the source code after all macros have been expanded, even if this representation does not take the form of a typical operation call expression. Examples of non-typical operation call expressions include:

  • implicit calls to no-args constructors (variable declaration)
  • explicit calls to destructors (“delete” expressions)
  • calls to overloaded operators.

In the case of structured types (e.g. classes, structs) the count also includes incoming calls to methods of the contained member structured types. So if a class definition contains a member class definition, the incoming calls to all methods of the contained member class definition are also counted. In the case of a file, all incoming calls from outside the file to all operations defined and declared in that file are counted. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Coupling

Languages: C, C++
Targets: Variable, Function, Type, File, Folder

This metric counts all incoming references to the measured entity and / or its contained entities from outside the measured entity. This also includes the references to all declarations of the measured entity and all declarations of its contained entities. The following kind of references are counted:

  • included file references
  • type references (declarations of data type, base type declarations, cast expressions, etc.)
  • function calls (including calls to overloaded operators, constructors, or destructors)
  • function accesses (using the function address in an assignment to a function pointer)
  • variable accesses (read and write accesses).

Only explicit references are taken into account, meaning that the references themselves must have a representation in the source code after all macros have been expanded. In the case of structured types (e.g. classes, structs) the count also includes incoming references to members of the contained member structured types. So if a class definition contains a member class definition, the incoming references to all members of the contained member class definition are also counted. In the case of a file, in addition to the incoming references to the file itself, all incoming references from outside the file to all entities defined and declared in that file are also counted. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Coupling

Languages: C, C++
Targets: Type, File, Folder

This metric counts all incoming type references (declarations of data type, base type declarations, cast expressions, etc.) to the measured entity and / or its contained types from outside the measured entity. This also includes the type references to all declarations of the measured entity and all decla rations of its contained types. Only explicit references are taken into account, meaning that the references themselves must have a representation in the source code after all macros have been expanded. In the case of structured types (e.g. classes, structs) the count also includes incoming type references to all contained member types and their type members. So if a class definition contains a member class definition, the incoming type references to this member class definition are also counted. In the case of a file, all incoming type references from outside the file to all types defined and declared in that file are counted. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Coupling

Languages: C, C++
Targets: File, Folder, Project

This metric counts all module references contained in a file. A module reference is a reference to an external file by using its name in an include statement. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Coupling

Languages: C, C++
Targets: Variable, Function, Type, File, Folder, Project

This metric counts all operation accesses contained in the definition of the measured entity. An operation access is a use of an operation name in an expression other than a call, which does not result in the operation being called. A typical example of an operation access if the use of an operation’s address in an assignment to a function pointer. Only explicit accesses are considered, meaning that the accesses themselves must have a representation in the source code after all macros have been expanded. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Coupling

Languages: C, C++
Targets: Variable, Function, Type, File, Folder, Project

This metric counts all operation calls contained in the definition of the measured entity, including calls to overloaded operators, constructors or destructors. Only explicit calls are considered, meaning that the calls themselves must have a representation in the source code after all macros have been expanded, even if this representation does not take the form of a typical operation call expression. Examples of non-typical operation call expressions include:

  • implicit calls to no-args constructors (variable declaration)
  • explicit calls to destructors (“delete” expressions)
  • calls to overloaded operators.

This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Coupling

Languages: C, C++
Targets: Variable, Function, Type, File, Folder

This metric counts the number of distinct function definitions (e.g. methods, global functions) referenced by the measured entity. The count does not include the measured entity even if it references itself and it does not include any functions defined in the measured entity even if these functions are referenced by the measured entity. A measured entity is considered to reference a target function if the measured entity contains:

  • a reference to the definition of the target function
  • a reference to any declaration of the target funciton

This metric does not aggregate.

Category: Coupling

Languages: C, C++
Targets: Variable, Function, Type, File, Folder

This metric counts the number of distinct modules (files containing source code) referenced by the measured entity. The count does not include the measured entity even if it references itself and it does not include any modules contained in the measured entity even if these modules are referenced by the measured entity. A measured entity is considered to reference a target module if the measured entity contains:

  • an include file reference to the target module
  • a reference to an entity defined or declared in the target module
  • a reference to any declaration of an entity defined in the target module

This metric does not aggregate.

Category: Coupling

Languages: C, C++
Targets: Variable, Function, Type, File, Folder

This metric counts the number of distinct type definitions (e.g. classes, structs, enums, typedefs) referenced by the measured entity. The count does not include the measured entity even if it references itself and it does not include any types defined in the measured entity even if these types are referenced by the measured entity. A measured entity is considered to reference a target type if the measured entity contains:

  • a reference to the definition of the target type
  • a reference to any declaration of the target type
  • a reference to an entity defined or declared in the target type
  • a reference to any declaration of an entity defined in the target type

This metric does not aggregate.

Category: Coupling

Languages: C, C++
Targets: Variable, Function, Type, File, Folder

This metric counts the number of distinct variable definitions (e.g. attributes, global variables) referenced by the measured entity. The count does not include the measured entity even if it references itself and it does not include any variables defined in the measured entity even if these variables are referenced by the measured entity. A measured entity is considered to reference a target variable if the measured entity contains:

  • a reference to the definition of the target variable
  • a reference to any declaration of the target variable

This metric does not aggregate.

Category: Coupling

Languages: C, C++
Targets: Variable, Function, Type, File, Folder, Project

This metric counts all references contained in the definition of the measured entity. The count includes:

  • included file references
  • type references (declarations of data type, base type declarations, cast expressions, etc.)
  • function calls (including calls to overloaded operators, constructors, or destructors)
  • function accesses (using the function address in an assignment to a function pointer)
  • variable accesses (read and write accesses).

Only explicit references are taken into account, meaning that the references themselves must have a representation in the source code after all macros have been expanded. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Coupling

Languages: C, C++
Targets: Variable, Function, Type, File, Folder

This metric counts the number of distinct functions referencing the measured entity. The count does not include the measured entity even if it references itself and does not include any functions defined in the measured entity even if these functions are referencing the measured entity. The measured entity is considered to be referenced if the referencing function contains:

  • a reference to the definition of the measured entity
  • a reference to any declaration of the measured entity
  • a reference to an entity defined or declared in the measured entity
  • a reference to any declaration of an entity defined in the measured entity

This metric does not aggregate.

Category: Coupling

Languages: C, C++
Targets: Variable, Function, Type, File, Folder

This metric counts the number of distinct modules (files containing source code) referencing the measured entity. The count does not include the measured entity even if it references itself and it does not include any modules contained in the measured entity even if these modules are referencing the measured entity. The measured entity is considered to be referenced if the referencing module contains:

  • a reference to the definition of the measured entity
  • a reference to any declaration of the measured entity
  • a reference to an entity defined or declared in the measured entity
  • a reference to any declaration of an entity defined in the measured entity

This metric does not aggregate.

Category: Coupling

Languages: C, C++
Targets: Variable, Function, Type, File, Folder

This metric counts the number of distinct type definitions (e.g. classes, structs, typedefs) referencing the measured entity. The count does not include the measured entity even if it references itself and it does not include any types defined in the measured entity even if these types are referencing the measured entity. The measured entity is considered to be referenced if the referencing type contains:

  • a reference to the definition of the measured entity
  • a reference to any declaration of the measured entity
  • a reference to an entity defined or declared in the measured entity
  • a reference to any declaration of an entity defined in the measured entity

This metric does not aggregate.

Category: Coupling

Languages: C, C++
Targets: Variable, Function, Type, File, Folder, Project

This metric counts all type references (declarations of data type, base type declarations, cast expressions, etc.) contained in the definition of the measured entity. Only explicit type references are taken into account, meaning that the type references themselves must have a representation in the source code after all macros have been expanded. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Size

Languages: C, C++
Targets: Type, File, Folder, Project

This metric counts all unused function definitions (global functions, methods, constructors, operator overloads, etc.) contained in the measured entity. A function definition is considred unused if the following conditions are met:

  • it is not referenced (called or accessed) in the source code
  • none of its declarations are referenced in the source code

In the case of structured types (e.g. classes, structs) the count also includes the functions defined in the contained member structured types. So if a class definition contains a member class definition, a function defined in the contained member class definition will al so be counted if unused. In the case of a file only the unused functions actually defined in that file are counted. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Size

Languages: C, C++
Targets: File, Folder, Project

This metric counts the unused modules in the measured file. A module represents the parsable source code inside a file. A module is considered unused if the following conditions are met:

  • it is not referenced in the source code
  • none of its contained definitions or declartions are referenced in the source code

Note that the value of this metric is 1 if the measured file contains contains an unused module and 0 otherwise. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Size

Languages: C, C++
Targets: File, Folder, Project

This metric counts all unused type definitions (classes, structs, unions and typedefs) contained in the measured entity. A type definition is considered unused if all of the following conditions are met:

  • it is not referenced in the source code
  • none of its declarations are referenced in the source code
  • none of its member definitions or member declartions are referenced in the source code

This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Size

Languages: C, C++
Targets: Function, Type, File, Folder, Project

This metric counts all unused variable definitions (local varibales, formal parameters, class attributes, enum constants, global variables, etc.) contained in the measured entity. A variable definition is considered unused if the following conditions are met:

  • it is not accessed in the source code
  • none of its declarations are accessed in the source code

In the case of structured types (e.g. classes, structs) the count also includes the variables defined in the contained member structured types. So if a class definition contains a member class definition, a variable defined in the contained member class definition will also be counted if unused. In the case of a file the count includes only the unused variables actually defined in the file in question. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Cohesion

Languages: C++
Targets: Type, File, Folder, Project

This metric quantifies the internal cohesion of a structured type (e.g. class, struct), based on the usage of internal attributes by its methods. It is calculated based on the Number of Methods (NOM) and Number of Attributes (NOA) metrics using the formula:

LCOM = (NOM – sum(#AccessingMethods) / NOA) / (NOM – 1)

where sum(#AccessingMethods) represents the sum over all attributes of the measured structured type of the number of methods from the measured structured type accessing each attribute. The metric has a value in the range of [0, 2] with values higher than 1 indicating non-cohesive structured types. In case of a structured type having no internal attributes or a structured type having at most one method, the value of this metric is by convention 0. This metric aggregates above the type level as the average of the metric values computed on the contained types.

References: Henderson95

Category: Cohesion

Languages: C++
Targets: Type, File, Folder, Project

This metric quantifies the internal cohesion of a structured type (e.g. class, struct), based on the common usage of internal attributes by its methods. The metric is closely related to Tight Class Cohesion (TCC) metric and is calculated using the formula:

LCC = 2 * #AllConnectedMethodPairs / (#VisibleMethods * (#VisibleMethods – 1))

where #VisibleMethods is the number of non-private methods (including constructors, destructors and operator overloads) of the measured structured type and #AllConnectedMethodPairs is the number of pairs of directly and indirectly connected visible methods of the measured structured type. Two methods of a structured type are directly connected if:

  • they both access at least one common internal attribute of their enclosing structured type
  • both their call trees access at least one common internal attribute of their enclosing structured type. When calculating the call trees of the methods, only call branches to methods (including private methods) of the enclosing structured type are considered, while the other branches are pruned.

Two methods of a structured type are indirectly connected if they are not directly connected but rather connected through other methods. For example if method A is directly connected to B, B is directly connected to C, and A is not directly connected to C, then A and C are indirectly connected. The metric has a value in the range of [0, 1] with values lower than 0.5 typically indicating non-cohesive structured types. Note that from the definitions of TCC and LCC it follows that TCC <= LCC for any given structured type, so using the same threshold as in the case of TCC to indicate non-cohesive structured types, as suggested by the original authors of the metric, may result in a stronger condition for this metric. In case of a structured type having at most one method, the value of this metric is by convention 1. This metric aggregates above the type level as the average of the metric values computed on the contained types.

References: Bieman95

Category: Cohesion

Languages: C++
Targets: Type, File, Folder, Project

This metric quantifies the internal cohesion of a structured type (e.g. class, struct), based on the common usage of internal attributes by its methods. The metric is closely related to Loose Class Cohesion (LCC) metric and is calculated using the formula:

TCC = 2 * #DirectlyConnectedMethodPairs / (#VisibleMethods * (#VisibleMethods – 1))

where #VisibleMethods is the number of non-private methods (including constructors, destructors and operator overloads) of the measured structured type and #DirectlyConnectedMethodPairs is the number of pairs of directly connected visible methods of the measured structured type. Two methods of a structured type are directly connected if:

  • they both access at least one common internal attribute of their enclosing structured type
  • both their call trees access at least one common internal attribute of their enclosing structured type. When calculating the call trees of the methods, only call branches to methods (including private methods) of the enclosing structured type are considered, while the other branches are pruned.

The metric has a value in the range of [0, 1] with values lower than 0.5 typically indicating non-cohesive structured types. Note that from the definitions of TCC and LCC it follows that TCC <= LCC for any given structured type, so using the same threshold as in the case of LCC to indicate non-cohesive structured types, as suggested by the original authors of the metric, may result in a weaker condition for this metric. In case of a structured type having at most one method, the value of this metric is by convention 1. This metric aggregates above the type level as the average of the metric values computed on the contained types.

References: Bieman95

Category: Inheritance
Other names: Class Hierarchy Nesting Level
Languages: C++
Targets: Type, File, Folder, Project

This metric measures the longest path from a structured type (e.g. class, struct) to the root of its class hierarchy. If the class hiearchy has several roots, the one having the longest path to it is considered. This metric aggregates above the type level as the average of the metric values computed on the contained types.

References: Chidamber94, Basili96

Category: Size

Languages: C++
Targets: File, Folder, Project

This metric counts all abstract classes defined in the measured entity. An abstract class is a class having at least one pure virtual method. The count also includes abstract member class definitions contained in the counted classes. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

References: Lorenz94

Category: Inheritance

Languages: C++
Targets: Type, File, Folder, Project

This metric counts the abstract (pure virtual) methods (including operator overloads) contained in the measured entity. While abstract methods have no definitions, they are counted becuase they belong to the enclosing structured type’s interface. In the case of structured types (e.g. classes, structs) the count does not include the methods of contained member structured types. So if a class definition contains a member class definition, the methods of this contained member class definition will not be counted. In the case of a file the count will include all pure virtual methods declared in the file. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

Category: Inheritance

Languages: C++
Targets: Type, File, Folder, Project

This metric counts new public methods (including operator overloads) defined in the measured entity. A method is considered new if it does not override an inherited method. The count also includes abstract (pure virtual) methods. While abstract methods have no definitions, they are counted becuase they belong to the enclosing abstract data type’s interface. In the case of structured types (e.g. classes, structs) the count does not include the methods defined in the contained member structured types. So if a class definition contains a member class definition, the methods defined in the contained member class definition will not be counted. In the case of a file only the methods defined in that file are counted, so for a header file containing a structured type definition, whose methods are only declared (not defined) in this header file, the count will not include these methods. This metric aggregates above the file level as the sum of the metric values computed on the contained files.

References: Lorenz94

Category: Inheritance

Languages: C++
Targets: Type, File, Folder, Project

This metric counts the direct descendants of a structured type (e.g. class, structure). The count also includes descendants connected to the structured type through protected and private inheritance. This metric aggregates above the type level as the average of the metric values computed on the contained types.

References: Chidamber94, Riel96

Category: Inheritance

Languages: C++
Targets: Type, File, Folder, Project

This metric counts all descendants (direct or indirect) of a structured type (e.g. class, structure). The count also includes descendants connected to the structured type through protected and private inheritance. This metric aggregates above the type level as the average of the metric values computed on the contained types.