Reducing Cyclomatic Complexity through Refactoring
As put clearly on what adds to cyclomatic complexity in a Java class method here, and to keep the metric around 5-6, following are the refactoring rules we could follow:
1) Keep the method size to less than 25 lines of code.
2) Look at the detail design options of having recursion for intertwined looping constructs with complex logic in case if any.
3) Have fewer points of return by declaring an object of return type and single path of execution to the return statement.
4) Use ternary operations for conditional assignments.
5) Catch exceptions judiciously. Dont catch runtime exceptions, and catch only relevant checked exceptions, throwing other non-relevant exceptions to the caller. This increases cohesions of the method, thus reducing complexity.