resources.report.rules.pmd.ModifiedCyclomaticComplexity.html Maven / Gradle / Ivy
ModifiedCyclomaticComplexity
ModifiedCyclomaticComplexity
Complexity directly affects maintenance costs is determined by the number of decision points in a method plus one for the method entry. The decision points include ‘if’, ‘while’, ‘for’, and ‘case labels’ calls.
Generally, numbers ranging from 1-4 denote low complexity, 5-7 denote moderate complexity, 8-10 denote high complexity, and 11+ is very high complexity. Modified complexity treats switch statements as a single decision point.
This rule is defined by the following Java class: net.sourceforge.pmd.lang.java.rule.codesize.ModifiedCyclomaticComplexityRule
Example(s):
public class Foo { // This has a Cyclomatic Complexity = 9
1 public void example() {
2 if (a == b) {
3 if (a1 == b1) {
fiddle();
4 } else if a2 == b2) {
fiddle();
} else {
fiddle();
}
5 } else if (c == d) {
6 while (c == d) {
fiddle();
}
7 } else if (e == f) {
8 for (int n = 0; n < h; n++) {
fiddle();
}
} else{
9 switch (z) {
case 1:
fiddle();
break;
case 2:
fiddle();
break;
case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}