Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mehen.ophi.dev/llms.txt

Use this file to discover all available pages before exploring further.

Weighted Methods per Class (WMC) is one of the six classic CK (Chidamber & Kemerer) object-oriented metrics. It sums the cyclomatic complexity of every method declared in a class or interface.

What mehen emits

KeyTypeDescription
wmcintSum of cyclomatic complexity across all methods in the file.
wmc.classesintWMC summed over classes only.
wmc.interfacesintWMC summed over interfaces only.

Definition

WMC(C) = Σ cyclomatic_complexity(m_i)
for each method m_i defined in class C. A class with five methods of cyclomatic complexity {1, 1, 4, 5, 8} has WMC = 19.

Why a sum, not an average

A class with one 50-CC method is different from a class with fifty 1-CC methods, even though the average is the same. WMC captures the total decision burden of a class, which correlates with how much of the class a maintainer must understand to make a change.

How to read it

There is no universal threshold; common conventions:
WMCInterpretation
1–14Small/cohesive class.
15–40Normal in Java/C# / TS classes.
41+Likely god-class candidate.
Read WMC alongside NOM: a high WMC with low NOM signals a few very complex methods; a high WMC with high NOM signals a class doing too much.

Languages where WMC applies

WMC is meaningful for languages with explicit class/interface declarations: Java, Kotlin, TypeScript, Python (classes), Ruby, C++, C#. mehen reports wmc = 0 for files with no declarations of those kinds (e.g., a Go file or a procedural C file).

References

  • Chidamber, S. R. & Kemerer, C. F. (1994). A Metrics Suite for Object Oriented Design. IEEE Transactions on Software Engineering 20(6): 476–493. DOI · Author copy (MIT).
  • Basili, V. R., Briand, L. C. & Melo, W. L. (1996). A validation of object-oriented design metrics as quality indicators. IEEE TSE 22(10): 751–761. DOI.
  • Sonar: Metrics definitions.

See also