Understand how cognitive complexity is calculated
masterCognitive complexity measures how intuitively hard code is to understand. Unlike cyclomatic complexity, it penalizes nesting and specific control structures more heavily.
Increments
An increment is added for each of the following:
if,else if,elseswitch,selectforgotoLABEL,breakLABEL,continueLABEL- Sequence of binary logical operators
- Each method in a recursion cycle
Nesting
Certain structures increase the nesting level, which in turn increases the weight of subsequent increments:
- Nesting level increases for:
if,else if,else,switch,select,for, and function literals/lambdas. - Nesting increments apply to:
if,switch,select, andforstructures based on their depth.