Calculates the Cyclomatic Complexity Metric for a class or method. Cyclomatic Complexity is a metric of complexity that counts the number of independent paths through the source code, and assigns a single numerical score for each method. The Cyclomatic Complexity score can also serve as an upper bound for the number of test cases that are necessary to achieve a complete branch coverage for a particular method ().
Implemented by the
The Cyclomatic Complexity Metric calculates a value for each method. Furthermore, if a class
field is initialized to a Closure (
ClosureExpression), then that Closure is analyzed
just like a method.
?:ternary operator and
The value of 10 is often considered as the threshold between acceptable (low risk) code and too complex (higher risk). See  and , for instance. As McCabe () says,
The particular upper bound that has been used for cyclomatic complexity is 10 which seems like a reasonable, but not magical, upper limit.
Other sources cite 15 as a useful threshold, and/or draw further delineations between low/medium/high/unacceptable complexity values. NDepend (), for instance, recommends that methods with a score of
“15 are hard to understand and maintain. Methods where CC is higher than 30 are extremely complex and should be split.”
On the other hand,  categorizes cyclomatic complexity scores into the following levels:
The following properties can be configured for this metric within a MetricSet. See Creating a MetricSet for information on the syntax of setting a metric property.
 The original paper from Thomas J. McCabe describing Cyclomatic Complexity in IEEE Transactions on Software Engineering Vol. 2, No. 4, p. 308 (1976).
 Groovy Code Metrics: Cyclomatic Complexity - Discusses using GMetrics and CodeNarc for measuring and enforcing Cyclomatic Complexity on Groovy code.
 NDepend - an impressive source code metrics tool for Java.