scitools.com

← Metric catalog

Modified 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.

Modified Cyclomatic Complexity

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

Modified McCabe Cyclomatic complexity.

The Cyclomatic Complexity except that each decision in a multi-decision structure (switch in C/Java, Case in Ada, computed Goto and arithmetic if in FORTRAN) statement is not counted and instead the entire multi-way decision structure counts as 1.

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. The switch statement adds one more regardless of how many cases it has, and the &&/|| in the if condition are not counted. That's 7 decision points, for a Modified Cyclomatic Complexity of 8.

To count each case in the switch statement as its own decision instead, use Cyclomatic Complexity. To also count && and || operators, use Strict Cyclomatic Complexity. To count those operators without changing how the switch is handled, use Strict Modified Cyclomatic Complexity.

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

Also known as McCabe - Modified Cyclomatic Complexity (CC3).


Targets By Language: Configuration: