scitools.com

← Metric catalog

Sum Cyclomatic Complexity is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.

Sum Cyclomatic Complexity

API ID: SumCyclomatic
Also Known As: Weighted Methods per Class (WMC)
Languages: Ada, Basic, C#, C++, Fortran, Java, Jovial, Pascal, Python, Rust, Web
Targets: Architectures, Classes, Files, Functions, Modules, Packages, Project, Subprograms

Sum of cyclomatic complexity of all nested functions or methods.

For example:


class SayHello {
public:
  SayHello() {}
  void printHello();
};

void SayHello::printHello() {
  switch (i) {
    ...
  }
}

void cyclomaticDemo() {
  ...
}

int func();          // declared here, not defined - excluded from aggregates

int main() {
  ...
}

SayHello(), printHello(), cyclomaticDemo(), and main() have Cyclomatic Complexity of 1, 4, 10, and 2. func() is only declared, not defined, so it isn't counted. For the SayHello class, the sum is 1 + 4 = 5. For the whole file (sample.cpp), the sum is 1 + 4 + 10 + 2 = 17.

See Max and Average Cyclomatic Complexity for the other aggregations.

Also known as Chidamber & Kemerer - Weighted Methods per Class (WMC).


Targets By Language: Configuration: