Strict 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.
Strict Modified Cyclomatic Complexity
API ID: CyclomaticStrictModifiedLanguages: Ada, Basic, C#, C++, Fortran, Java, Jovial, Pascal, Python, Rust, Web
Targets: Files, Functions, Modules, Packages, Subprograms
Cyclomatic Complexity with the following conditions.
(1) Logical operators (AND, OR) in conditional expressions add one (1) to the complexity for each occurrence.
(2) In multi-decision structures (switch in C/Java, Case in Ada, computed Goto, and arithmetic if in FORTRAN) the decision points are not counted, 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 && and || in the if condition each add one as well (2 total). That's 9 decision points, for a Strict Modified Cyclomatic Complexity of 10.
To count each case in the switch statement as its own decision instead, use Strict Cyclomatic Complexity. To also stop counting && and || operators, use Cyclomatic Complexity. To change only how the switch is handled, use Modified Cyclomatic Complexity.
See Sum Strict Modified Cyclomatic Complexity, Max Strict Modified Cyclomatic Complexity, and Average Strict Modified Cyclomatic Complexity for aggregated values, such as for an architecture or the project.
- Ada: Type, Entry, Function, Package, Procedure, Protected, Task
- Basic: Method
- C#: Method
- C++: Function
- Fortran: Module, Block Data, Function, Program, Subroutine
- Java: Method
- Jovial: Subroutine
- Pascal: Compunit, Function, Procedure
- Python: File, Function
- Rust: Function
- Web: File
- The cyclomatic metric used is configured from "Project Configuration/Metrics/Complexity". This metric results from having "Count each decision in a multi-way-decision structure" off and having "Count logical conjuctions (OR) and logical and (AND)" on. Checking "Show all available cyclomatic complexity metric variants" will also enable the metric.