Metrics Checks

Checkstyle Logo

CyclomaticComplexity

Description

Checks cyclomatic complexity against a specified limit. The complexity is measured by the number of if, while, do, for, ?:, catch, switch, case statements, and operators && and || (plus one) in the body of a constructor, method, static initializer, or instance initializer. It is a measure of the minimum number of possible paths through the source and therefore the number of required tests. Generally 1-4 is considered good, 5-7 ok, 8-10 consider re-factoring, and 11+ re-factor now!

Properties

name description type default value
max the maximum threshold allowed integer 10

Examples

To configure the check:

<module name="CyclomaticComplexity"/>
      

To configure the check with a threshold of 7:

<module name="CyclomaticComplexity">
    <property name="max" value="7"/>
</module>
      
      

Package

com.puppycrawl.tools.checkstyle.checks.metrics

Parent Module

TreeWalker


Back to the Checkstyle Home Page