if, for, while,
case, boolean && / ||, ternary, or exception handler increments the count.
What mehen emits
Formula
E edges, N nodes, and P connected components.
In practice, mehen counts decisions plus 1:
if, else if,
loops, switch arms, && / ||, ternary expressions, exception handlers, and other control-flow
constructs.
Per-language increments
The exact set of node kinds that increment complexity is owned by each language analyzer crate. The list matches McCabe’s original prescription closely:- Branches:
if,else if,case/whenarms. - Loops:
for,while,do,loop,until. - Boolean operators:
&&,||(each occurrence). - Ternary / conditional expression: the
?:operator. - Exception handlers:
catch,rescue,except. - Early returns: counted in NEXITS, not cyclomatic.
How to read it
McCabe’s original 1976 paper recommended 10 as the upper limit per function, with rare exceptions for
state machines.
References
- McCabe, T. J. (1976). A Complexity Measure. IEEE Transactions on Software Engineering, SE-2(4): 308–320. DOI · PDF (literateprogramming.com archive).
- Kearney, J. K., et al. Software Complexity Measurement — MIT lecture notes covering McCabe and Halstead together. PDF (MIT OCW 16.355).
- Watson, A. H. & McCabe, T. J. (1996). Structured Testing: A Testing Methodology Using the Cyclomatic Complexity Metric. NIST Special Publication 500-235. NIST PDF.
- Sonar: Cyclomatic complexity.
See also
- Cognitive complexity — Sonar’s “how hard to understand” complement.
- Weighted Methods per Class (WMC) — sum of cyclomatic across class methods.