All Downloads are FREE. Search and download functionalities are using the official Maven repository.

resources.report.rules.pmd.CyclomaticComplexity20.html Maven / Gradle / Ivy



CyclomaticComplexity


CyclomaticComplexity (20)

Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

This rule is defined by the following Java class: net.sourceforge.pmd.rules.CyclomaticComplexity

Example:

                

// Cyclomatic Complexity = 12
public class Foo {
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{
            switch (z) {
9               case 1:
                    fiddle();
                    break;
10              case 2:
                    fiddle();
                    break;
11              case 3:
                    fiddle();
                    break;
12              default:
                    fiddle();
                    break;
            }
        }
    }
}

   
            

This rule has the following properties:

NameDefault valueDescription
reportLevel 20 The Cyclomatic Complexity reporting threshold
showClassesComplexity true Indicate if class average violation should be added to the report
showMethodsComplexity true Indicate if class average violation should be added to the report




© 2015 - 2024 Weber Informatics LLC | Privacy Policy