scitools.com

← Metric catalog

Strict Cyclomatic Complexity is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.

Strict Cyclomatic Complexity

API ID: CyclomaticStrict
Also Known As: CC2
Languages: Ada, Assembly, Basic, C#, C++, Fortran, Java, Jovial, Pascal, Python, Rust, VHDL, Web
Targets: Files, Functions, Modules, Packages, Subprograms

Strict McCabe Cyclomatic Complexity.

The Cyclomatic Complexity with logical conjunction and logical and in conditional expressions also adding 1 to the complexity for each of their occurrences. i.e. The statement 'if (a && b || c)' would have a cyclomatic complexity of 1 but a strict cyclomatic complexity of 3

For example:


void cyclomaticDemo() {
  bool a = true, b = true, c = true;

  if (a || (b && c)) {
    while (a ? b : c) {
      for (int i = 0; i < 10; i++) {
        switch (i) {
          case 1:
          case 2:
            cout << i << endl;
            break;
          case 5:
            break;
          default:
            cout << i << endl;
        }
      }
    }
  } else {
    try {
      do {
        cout << a << b << c << endl;
      } while (a);
    }
    catch (...) {
    }
  }
}

if, while, the ?: conditional, for, do, and catch are always decision points, for 6 total. Each case in the switch statement adds another (3 total), and the && and || in the if condition each add one as well (2 total). That's 11 decision points, for a Strict Cyclomatic Complexity of 12.

To stop counting && and || operators, use Cyclomatic Complexity. To also count the entire switch statement as a single decision, use Strict Modified Cyclomatic Complexity. To change only how the switch is handled, use Modified Cyclomatic Complexity.

See Sum Strict Cyclomatic Complexity, Max Strict Cyclomatic Complexity, and Average Strict Cyclomatic Complexity for aggregated values, such as for an architecture or the project.

Also known as McCabe - Strict Cyclomatic Complexity (CC2).


Targets By Language: Configuration: