Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

More details

...

  • Keywords incrementing the complexity: if, for, while, case, catch, throw, return (that is not the last statement of a method), &&, ||, ?
  • else, default, and finally keywords do not increment the complexity. On the other hand, a simple method with a switch statement and a huge block of case statements can have a surprisingly high complexity value (still it has the same value when converting a switch block to an equivalent sequence of if statements).Notes:
  •  accessors are not considered as methods and so do not increment the complexity
Example: the following method has a complexity of 5
NameKeyDescription
Anchor
metricComplexity
metricComplexity
Complexity
complexity

It is the cyclomatic complexity, also known as McCabe metric. Whenever the control flow of a method splits, the complexity counter gets incremented by one.
Each method has a minimum value of 1 per default.

Expand
title
LanguageNotes
ABAPThe following keywords increase the complexity by one: AND, CATCH, CONTINUE, DO, ELSEIF, IF, LOOP, LOOPAT, OR, PROVIDE, SELECT…ENDSELECT, TRY, WHEN, WHILE.
CobolThe following commands increase the complexity by one: ALSO, ALTER, AND, DEPENDING, END_OF_PAGE, ENTRY, EOP, EXCEPTION, EXIT, GOBACK, CONTINUE, IF, INVALID, OR, OVERFLOW, SIZE, STOP, TIMES, UNTIL, USE, VARYING, WHEN, EXEC CICS HANDLE, EXEC CICS LINK, EXEC CICS XCTL and EXEC CICS RETURN.
Java
Code Block
public void process(Car myCar){          <- +1
    if(myCar.isNotMine()){               <- +1
         return;                         <- +1
    }
    car.paint("red");
    car.changeWheel();
    while(car.hasGazol() && car.getDriver().isNotStressed()){   <- +2
         car.drive();
    }
    return;
}
PL/IThe following keywords increase the complexity by one: PROC, PROCEDURE, GOTO, GO TO, RETURN, DO, IF, WHEN, |, !, |=, !=, &, &=.PL/SQLThe complexity gets incremented by one for: the main PL/SQL anonymous block (not inner ones), create procedure, create trigger, procedure_definition, basic loop statement, when_clause_statement (the “when” of simple_case_statement and searched_case_statement), continue_statement, cursor_for_loop_statement, continue_exit_when_clause (The “WHEN” part of the continue and exit statements), exception_handler (every individual “WHEN”), exit_statement, for_loop_statement, forall_statement, if_statement, elsif_clause, raise_statement, return_statement, while_loop_statement, and_expression (“and” reserved word used within PL/SQL expressions), or_expression (“or” reserved word used within PL/SQL expressions), when_clause_expression (the “when” of simple_case_expression and searched_case_expression)VB.NETThe complexity gets incremented by one for: method or constructor declaration (Sub, Function), AndAlso, Case, Continue, End, Error, Exit, If, Loop, On Error, GoTo, OrElse, Resume, Return (except if it is the last statement of a function), Stop, Throw, Try.Complexity /classclass_complexityAverage complexity by class.Complexity /filefile_complexityAverage complexity  complexity by file.Complexity /methodfunction_complexityAverage complexity  complexity by method.

Design

More details

...

NameKeyDescription

Afferent couplings

ca

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

Depth in Tree

dit

The depth of inheritance tree (DIT) metric provides for each class a measure of the inheritance levels from the object hierarchy top.

Expand
title
LanguageNote
JavaAs every class inherits from Object, the minimum value of DIT is 1.

Efferent couplings

ce

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

File cycles

file_cycles

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

Anchor
metricFileEdgesWeight
metricFileEdgesWeight
File edges weight

file_edges_weight

Number of file dependencies inside a package.

File dependencies to cut

package_tangles

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

Anchor
metricFileTangle
metricFileTangle
File tangle

file_tangles

File tangle = Suspect file dependencies

Anchor
metricFileTangleIndex
metricFileTangleIndex
File tangle index

file_tangle_index

File tangle index = 2 * (File tangle / File edges weight) * 100.

 

LCOM4

lcom4

Lack of cohesion of methods. See LCOM4 documentation page.

Number of children

noc

The number of children of a class is the number of direct and indirect descendants of this class.

Package cycles

package_cycles

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

Package dependencies to cut

package_feedback_edges

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

Package tangle index

package_tangle_index

Level of tangle of the packages. Best value (0%) means that there is no cycle and worst value (100%) means that packages are really tangled. This metric is computed with the following formula: 2 * (File dependencies to cut / Number of file dependencies between packages) * 100.

Response for class

rfc

See RFC documentation page.

Package edges weight

package_edges_weight

Number of file dependencies between packages.

Anchor
metricFileFeedbackEdges
metricFileFeedbackEdges
Suspect file dependencies

file_feedback_edges

File dependencies to cut in order to remove cycles between files inside a package. Note that cycles between files inside a package does not always mean a bad quality architecture.

Suspect LCOM4 densitysuspect_lcom4_densityDensity of files having a LCOM4 density greater than 1.

...

More details

...

NameKeyDescription
Blank commentscomment_blank_linesNumber of non-significant comment lines (empty comment line, comment line containing only special characters, etc.).
Anchor
metricCommentLines
metricCommentLines
Comment lines
comment_lines

Number of lines containing a comment.

Expand
title
LanguageNote
CobolLines containing the following instructions are counted both as comments and lines of code: AUTHOR, INSTALLATION, DATE-COMPILED, DATE-WRITTEN, SECURITY.
JavaFile headers are not counted as comment lines (as they usually define the license).
Comments (%)comment_lines_density

Density of comment lines = Comment lines / (Lines of code + Comment lines) * 100

With such a formula:

  • 50% means that the number of lines of code equals the number of comment lines
  • 100% means that the file only contains comment lines
Comments in Procedure Divisions Comments in Procedure divisions (Cobol only)
Anchor
metricPublicDocumentedApiDensity
metricPublicDocumentedApiDensity
Public documented API (%)
public_documented_api_densityDensity of public documented API = (Public API - Public undocumented API) / Public API * 100
Anchor
publicUndocumentedApi
publicUndocumentedApi
Public undocumented API
public_undocumented_apiPublic API without comments header.

Duplications

NameKeyDescription

Duplicated blocks

duplicated_blocks

Number of duplicated blocks of lines.

Duplicated filesduplicated_filesNumber of files involved in a duplication.
Anchor
metricDuplicatedLines
metricDuplicatedLines
Duplicated lines
duplicated_linesNumber of lines involved in a duplication.
Duplicated lines (%)duplicated_lines_density

Density of duplication = Duplicated lines / Lines * 100

Reviews

NameKeyDescription

Active reviews

active_reviews

Number of active reviews (status not closed).

False-positive reviewsfalse_positive_reviewsNumber fo false-positive reviews.
New unreviewed violationsnew_unreviewed_violationsNumber of new unreviewed violations.
Unassigned reviewsunassigned_reviewsNumber of unassigned reviews.
Unplanned reviewsunplanned_reviewsNumber of unplanned reviews (not associated with an action plan).
Unreviewed violationsunreviewed_violationsNumber of unreviewed violations.

...

NameKeyDescription

New violations

new_violations

Number of new violations.

New xxxxx violations

new_xxxxx_violations

Number of new violations with severity xxxxx, xxxxx being Blocker, Critical, Major, Minor or Info.

Violations

violations

Number of violations.

xxxxx violations

xxxxx_violations

Number of violations with severity xxxxx, xxxxx being Blocker, Critical, Major, Minor or Info.

Anchor
metricWeightedViolations
metricWeightedViolations
Weighted violations

weighted_violations

Sum of the violations weighted by the coefficient associated to each severity (Sum(xxxxx_violations * xxxxx_weight)).
To set the weight of each severity, log in as an administrator, go to Settings > Configuration > General Settings > General and set the Rules weight property.

Rules compliance

violations_density

Rules compliance index (RCI) = 100 - (Weighted violations / Lines of code * 100)

SCM

NameKeyQualitativeDescription
Authors by lineauthors_by_linenoThe last committer on each line of code.

...

More details

...

MetricKeyDescription
Anchor
metricAccessors
metricAccessors
Accessors
accessors

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

Expand
title
LanguageNote
Java
Code Block
titleGetters
linenumberstrue
languagejava
private String field;
 
// Recognized as a getter by Sonar
public String getField() {
  return field;
}

// Recognized as a getter by Sonar
public String getMyOwnField() {
  return field;
}

// Not recognized as a getter by Sonar
public String getField() {
  String a = "toto";
  return field;
}
Code Block
titleSetters
linenumberstrue
languagejava
private String field;
 
// Recognized as a setter by Sonar
public void setField(String field) {
  this.field = field;
}

// Recognized as a setter by Sonar
public void setMyOwnField(String myOwnField) {
  this.field = myOwnField;
}

// Not recognized as a setter by Sonar
public void setField(String field) {
  if (field == null) {
    this.field = "My field is null";
  } else {
    this.field = field;
  }
}
Anchor
metricClasses
metricClasses
ClassesclassesNumber of classes (including nested classes, interfaces, enums and annotations).
Anchor
metricDirectories
metricDirectories
DirectoriesdirectoriesNumber of directories.
Anchor
metricFiles
metricFiles
FilesfilesNumber of files.Generated Linesgenerated_lines

Number of lines generated by Cobol code generators like CA-Telon.

Generated lines of codegenerated_nclocNumber of lines of code generated by Cobol code generators like CA-Telon.Inside Control Flow Statementscobol_inside_ctrlflow_statementsNumber of inside (intra program) control flow statements (GOBACK, STOP RUN, DISPLAY, CONTINUE, EXIT, RETURN, PERFORM paragraph1 THRU paragraph2).
Cobol only.
Anchor
metricLines
metricLines
LineslinesNumber of physical lines (number of carriage returns).
Anchor
metricNcloc
metricNcloc
Lines of codencloc

Number of physical lines that contain at least one character which is neither a whitespace or a tabulation or part of a comment.

Expandtitle

More details

...

LanguageNote
CobolGenerated lines of code and pre-processing instructions (SKIP1, SKIP2, SKIP3, COPY, EJECT, REPLACE) are not counted as lines of code.
LOCs in Data Divisionscobol_data_division_nclocNumber of lines of code in Data divisions. Generated lines of code are excluded.
Cobol only. LOCs in Procedure Divisionscobol_procedure_division_nclocNumber of lines of code in Procedure divisions. Generated lines of code are excluded.
Cobol only.
Anchor
metricFunctions
metricFunctions
Methodsfunctions

Number of methods/functions.

Expandtitle

More details

...

LanguageNote
CobolIt is the number of paragraphs.
Java
  • Accessors are considered as methods if the sonar.squid analyse.property.accessors is set to false
  • Constructors are considered as methods
VB.NETAccessors are not considered as methods.
Outside Control Flow Statementscobol_outside_ctrlflow_statementsNumber of outside (inter programs) control flow statements (CALL, EXEC CICS LINK, EXEC CICS XCTL, EXEC SQL, EXEC CICS RETURN).
Cobol only.
Anchor
metricPackages
metricPackages
PackagespackagesNumber of packages.
Anchor
metricProjects
metricProjects
ProjectsprojectsNumber of projects in a view.
Anchor
metricPublicApi
metricPublicApi
Public APIpublic_api

Number of public Classes + number of public Methods + number of public Properties

Expandtitle

 Metrics - Public APIMore details

...

LanguageNote
Java

Number of public properties but without public final static ones.

Anchor
metricStatements
metricStatements
Statementsstatements

Number of statements.

Expandtitle

More details

...

LanguageNote
Cobolmove, if, accept, add, alter, call, cancel, close, compute, continue, delete, display, divide, entry, evaluate, exitProgram, goback, goto, initialize, inspect, merge, multiply, open, perform, read, release, return, rewrite, search, set, sort, start, stop, string, subtract, unstring, write, exec, ibmXmlParse , ibmXmlGenerate , readyReset , mfCommit , mfRollback
Java

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

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

PL/SQLOnly includes SQL statements used within PL/SQL blocks, but not outside.

Tests

MetricKeyDescription
Anchor
metricBranchCoverage
metricBranchCoverage
Branch coverage
branch_coverage

On each line of code containing some boolean expressions, the branch coverage simply answers the following question: 'Has each boolean expression been evaluated both to true and false?'. This is the density of possible branches in flow control structures that have been followed during unit tests execution.

Code Block
Branch coverage = (CT + CF) / (2*B)

where

CT = branches that have been evaluated to 'true' at least once
CF = branches that have been evaluated to 'false' at least once

B = total number of branches
Anchor
metricCoverage
metricCoverage
Coverage
coverage

It is a mix of Line coverage and Branch coverage. Its goal is to provide an even more accurate answer to the following question: 'How much of the source code has been covered by the unit tests?".

Code Block
Coverage = (CT + CF + LC)/(2*B + EL)

where

CT = branches that have been evaluated to 'true' at least once
CF = branches that have been evaluated to 'false' at least once
LC = covered lines = lines_to_cover - uncovered_lines

B = total number of branches
EL = total number of executable lines (lines_to_cover)
Anchor
metricLineCoverage
metricLineCoverage
Line coverage
line_coverage

On a given line of code, Line coverage simply answers the following question: 'Has this line of code been executed during the execution of the unit tests?'. It is the density of covered lines by unit tests:

Code Block
Line coverage = LC / EL

where

LC = covered lines (lines_to_cover - uncovered_lines)
EL = total number of executable lines (lines_to_cover)
Anchor
metricLinesToCover
metricLinesToCover
Lines to cover
lines_to_coverNumber of lines of code which could be covered by unit tests (for example, blank lines or full comments lines are not considered as lines to cover).
New branch coveragenew_branch_coverageIdentical to Branch coverage but restricted to new / updated source code.
New coveragenew_coverageIdentical to Coverage but restricted to new / updated source code.
New line coveragenew_line_coverageIdentical to Line coverage but restricted to new / updated source code.
New lines to covernew_lines_to_coverIdentical to Lines to cover but restricted to new / updated source code.
New uncovered linesnew_uncovered_linesIdentical to Uncovered lines but restricted to new / updated source code.
Skipped unit testsskipped_testsNumber of skipped unit tests.
Anchor
metricUncoveredBranches
metricUncoveredBranches
Uncovered branches
uncovered_branchesNumber of branches which are not covered by unit tests.
Anchor
metricUncoveredLines
metricUncoveredLines
Uncovered lines
uncovered_linesNumber of lines of code which are not covered by unit tests.
Anchor
metricUnitTests
metricUnitTests
Unit tests
testsNumber of unit tests.
Unit tests durationtest_execution_timeTime required to execute all the unit tests.
Anchor
metricUnitTestErrors
metricUnitTestErrors
Unit test errors
test_errorsNumber of unit tests that have failed.
Anchor
metricUnitTestFailures
metricUnitTestFailures
Unit test failures
test_failuresNumber of unit tests that have failed with an unexpected exception.
Unit test success density (%)test_success_densityTest success density = (Unit tests - (Unit test errors + Unit test failures)) / Unit tests * 100

The same kinds of metrics exist for Integration tests coverage and Overall tests coverage (Units tests + Integration tests).

...