Skip to end of metadata
Go to start of metadata

Metrics are the heart of Sonar, using Sonar efficiently means perfectly understanding the definition and calculation algorithm of each one.

Size

Name

Key

Qualitative

Description

Physical lines

lines

no

Number of carriage returns

Comment lines

comment_lines

no

Number of javadoc, multi-comment and single-comment lines. Empty comment lines like, header file comments (mainly used to define the license) and commented-out lines of code are not included.

Commented-out lines of code

commented_out_code_lines

yes

Number of commented-out lines of code. Javadoc blocks are not scanned.

Lines of code

ncloc

no

Number of physical lines of code - number of blank lines - number of comment lines - number of header file comments - commented-out lines of code

Density of comment lines

comment_lines_density

yes

Number of comment lines / (lines of code + number of comments lines) * 100
With such formula :
- 50% means that there is the same number of lines of code and comment lines
- 100% means that the file contains only comment lines and no lines of code

Packages

packages

no

Number of packages

Classes

classes

no

Number of classes including nested classes, interfaces, enums and annotations

Files

files

no

Number of analyzed files

Directories

directories

no

Number of analyzed directories

Accessors

accessors

no

Number of getter and setter methods used to get(reading) or set(writing) a class' property .

Methods

functions

no

Number of Methods without including accessors. A constructor is considered to be a method.

Public API

public_api

no

Number of public classes, public methods (without accessors) and public properties (without public final static ones)

Public undocumented API

public_undocumented_api

yes

Number of public API without a Javadoc block

Density of public documented API

public_documented_api_density

yes

(Number of public API - Number of undocumented public API) / Number of public API * 100

Statements

statements

no

Number of statements as defined in the Java Language Specification but without block definitions. Statements counter gets incremented by one each time an expression, if, else, while, do, for, switch, break, continue, return, throw, synchronized, catch, finally is encountered :

Statements counter is not incremented by a class, method, field, annotation definition or by a package and import declaration.

Tests

NameKeyQualitativeDescription

Unit tests

tests

no

Number of unit tests

Unit tests duration

test_execution_time

no

Time required to execute unit tests

Unit test error

test_errors

yes

Number of unit tests that failed

Unit test failures

test_failures

yes

Number of unit tests that failed with an unexpected exception

Unit test success density

test_success_density

yes

(Unit tests - (errors + failures))/ Unit tests * 100

Skipped unit tests

skipped_tests

yes

Number of skipped unit tests

Line Coverage

line_coverage

yes

On a given line of code, line coverage simply answers the question: "Is this line of code executed during unit test execution?". At project level, this is the density of covered lines:

New Line Coverage

new_line_coverage

yes

identical to line_coverage but restricted to new / update source code

Branch coverage

branch_coverage

yes

On each line of code containing some boolean expressions, the branch coverage simply answers the question: "Has each boolean expression evaluated both to true and false ?". At project level, this is the density of possible branches in flow control structures that have been followed.

New Branch Coverage

new_branch_coverage

yes

identical to branch_coverage but restricted to new / update source code

Coverage

coverage

yes

Coverage metric is a mix of the two previous line coverage and branch coverage metrics to get an even more accurate answer to the question "how much of a source-code is being executed by your unit tests?".
The Coverage is calculated with the following formula :

New Coverage

new_coverage

yes

identical to coverage but restricted to new / update source code

Conditions to Cover

conditions_to_cover

no

Total number of conditions which could be covered by unit tests.

New Conditions to Cover

new_conditions_to_cover

no

identical to conditions_to_cover but restricted to new / update source code

Lines to Cover

lines_to_cover

no

Total number of lines of code which could be covered by unit tests.

New Lines to Cover

new_lines_to_cover

no

identical to lines_to_cover but restricted to new / update source code

Uncovered Conditions

uncovered_conditions

no

Total number of conditions which are not covered by unit tests.

New Uncovered Conditions

new_uncovered_conditions

no

identical to uncovered_conditions but restricted to new / update source code

Uncovered Lines

uncovered_lines

no

Total number of lines of code which are not covered by unit tests.

New Uncovered Lines

new_uncovered_lines

no

identical to uncovered_lines but restricted to new / update source code

Duplication

NameKeyQualitativeDescription

Duplicated lines

duplicated_lines

yes

Number of physical lines touched by a duplication

Duplicated blocks

duplicated_blocks

yes

Number of duplicated blocks of lines

Duplicated files

duplicated_files

yes

Number of files involved in a duplication of lines

Density of duplicated lines

duplicated_lines_density

yes

Duplicated lines / Physical lines * 100

Design

NameKeyQualitativeDescription

Depth of inheritance tree

dit

no

The depth of inheritance tree (DIT) metric provides for each class a measure of the inheritance levels from the object hierarchy top. In Java where all classes inherit Object the minimum value of DIT is 1.

Number of children

noc

no

A class's number of children (NOC) metric simply measures the number of direct and indirect descendants of the class.

Response for class

rfc

no

The response set of a class is a set of methods that can potentially be executed in response to a message received by an object of that class. RFC is simply the number of methods in the set.

Afferent couplings

ca

no

A class's afferent couplings is a measure of how many other classes use the specific class.

Efferent couplings

ce

no

A class's efferent couplings is a measure of how many different classes are used by the specific class.

Lack of cohesion of methods

lcom4

yes

LCOM4 measures the number of "connected components" in a class. A connected component is a set of related methods and fields. There should be only one such component in each class. If there are 2 or more components, the class should be split into so many smaller classes.

Package cycles

package_cycles

yes

Minimal number of package cycles detected to be able to identify all undesired dependencies.

Package dependencies to cut

package_feedback_edges

no

Number of package dependencies to cut in order to remove all cycles between packages.

File dependencies to cut

package_tangles

no

Number of file dependencies to cut in order to remove all cycles between packages.

Package edges weight

package_edges_weight

no

Total number of file dependencies between packages.

Package tangle index

package_tangle_index

yes

Gives the level of tangle of the packages, best value 0% meaning that there is no cycles and worst value 100% meaning that packages are really tangled. The index is calculated using : 2 * (package_tangles / package_edges_weight) * 100.

File cycles

file_cycles

yes

Minimal number of file cycles detected inside a package to be able to identify all undesired dependencies.

Suspect file dependencies

file_feedback_edges

no

File dependencies to cut in order to remove cycles between files inside a package. Warning : cycles are not always bad between files inside a package.

File tangle

file_tangles

no

file_tangles = file_feedback_edges.

File edges weight

file_edges_weight

no

Total number of file dependencies inside a package.

File tangle index

file_tangle_index

yes

2 * (file_tangles / file_edges_weight) * 100.

Complexity

NameKeyQualitativeDescription

Complexity

complexity

no

The Cyclomatic Complexity Number is also known as McCabe Metric. It all comes down to simply counting 'if', 'for', 'while' statements etc. in a method. Whenever the control flow of a method splits, the Cyclomatic counter gets incremented by one.
Each method has a minimum value of 1 per default except accessors which are not considered as method and so don't increment complexity. For each of the following Java keywords/statements this value gets incremented by one:

Note that else, default, and finally don't increment the CCN value any further. On the other hand, a simple method with a switch statement and a huge block of case statements can have a surprisingly high CCN value (still it has the same value when converting a switch block to an equivalent sequence of if statements).
For instance the following method has a complexity of 5

Average complexity by method

function_complexity

yes

Average cyclomatic complexity number by method

Complexity distribution by method

function_complexity_distribution

yes

Number of methods for given complexities

Average complexity by class

class_complexity

yes

Average cyclomatic complexity by class

Complexity distribution by class

class_complexity_distribution

yes

Number of classes for given complexities

Average complexity by file

file_complexity

yes

Average cyclomatic complexity by file

Rules

NameKeyQualitativeDescription

Violations

violations

yes

Total number of rule violations

New Violations

new_violations

yes

Total number of new violations

xxxxx violations

xxxxx_violations

yes

Number of violations with severity xxxxx, xxxxx being blocker, critical, major, minor or info

New xxxxx violations

new_xxxxx_violations

yes

Number of new violations with severity xxxxx, xxxxx being blocker, critical, major, minor or info

Weighted violations

weighted_violations

yes

Sum of the violations weighted by the coefficient associated at each priority (Sum(xxxxx_violations * xxxxx_weight))

Rules compliance index

violations_density

yes

100 - weighted_violations / Lines of code * 100

SCM

NameKeyQualitativeDescription
CommitscommitsnoThe number of commits.
Last commit datelast_commit_datenoThe latest commit date on a resource.
RevisionrevisionnoThe latest revision of a resource.
Authors by lineauthors_by_linenoThe last committer on each line of code.
Revisions by linerevisions_by_linenoThe revision number on each line of code.
Labels: