Skip to content

Files

Latest commit

 

History

History
27 lines (20 loc) · 1.2 KB

CyclomaticComplexMethod.md

File metadata and controls

27 lines (20 loc) · 1.2 KB

Pattern: High cyclomatic complexity

Issue: -

Description

Complex methods are hard to understand and read. It might not be obvious what side-effects a complex method has. Prefer splitting up complex methods into smaller methods that are in turn easier to understand. Smaller methods can also be named much clearer which leads to improved readability of the code.

This rule uses McCabe's Cyclomatic Complexity (MCC) metric to measure the number of linearly independent paths through a function's source code (https://www.ndepend.com/docs/code-metrics#CC). The higher the number of independent paths, the more complex a method is. Complex methods use too many of the following statements. Each one of them adds one to the complexity count.

  • Conditional statements - if, else if, when
  • Jump statements - continue, break
  • Loops - for, while, do-while, forEach
  • Operators &&, ||, ?:
  • Exceptions - catch, use
  • Scope Functions - let, run, with, apply, and also -> Reference

Further Reading