Cyclomatic complexity is McCabe’s count of the number of linearly independent paths through a function’s control-flow graph. A function with no branches has complexity 1. EachDocumentation Index
Fetch the complete documentation index at: https://mehen.ophi.dev/llms.txt
Use this file to discover all available pages before exploring further.
if, for, while,
case, boolean && / ||, ternary, or exception handler increments the count.
What mehen emits
| Key | Type | Description |
|---|---|---|
cyclomatic | int | Total cyclomatic complexity for the space (function/method/file). |
cyclomatic.sum | int | Sum across child spaces. |
cyclomatic.average | float | Mean across functions. |
cyclomatic.min | int | Minimum across functions. |
cyclomatic.max | int | Maximum across functions. |
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
| Value | Interpretation |
|---|---|
| 1–4 | Simple, low risk. |
| 5–10 | Moderate, well within McCabe’s recommended ceiling. |
| 11–20 | Complex; refactor candidate. |
| 21+ | Untestable in practice — split into smaller functions. |
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.