Skip to main content

Find method complexity

io.moderne.prethink.quality.FindMethodComplexity

Compute per-method code quality metrics including cyclomatic complexity, cognitive complexity, max nesting depth, line count, parameter count, ABC metric, and Halstead measures.

Recipe source

This recipe is only available to users of Moderne.

This recipe is available under the Moderne Proprietary License.

Used by

This recipe is used as part of the following composite recipes:

Usage

This recipe has no required configuration options. Users of Moderne can run it via the Moderne CLI.

You will need to have configured the Moderne CLI on your machine before you can run the following command.

shell
mod run . --recipe FindMethodComplexity

If the recipe is not available locally, then you can install it using:

mod config recipes jar install io.moderne.recipe:rewrite-prethink:0.4.1

See how this recipe works across multiple open-source repositories

Run this recipe on OSS repos at scale with the Moderne SaaS.

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.

Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.

Data Tables

Method quality metrics

io.moderne.prethink.table.MethodQualityMetrics

Per-method code quality metrics including cyclomatic complexity, cognitive complexity, nesting depth, Halstead measures, and ABC metric.

Column NameDescription
Source pathThe path to the source file containing the method.
Class nameThe fully qualified name of the containing class.
Method nameThe simple name of the method.
Method signatureThe full method signature including parameter types.
Cyclomatic complexityNumber of linearly independent paths through the method. 1-10 low, 11-20 moderate, 21-50 high, 50+ very high.
Cognitive complexityWeighted complexity penalizing nesting depth and flow-breaking structures.
Max nesting depthMaximum depth of nested control structures.
Line countNumber of lines in the method body.
Parameter countNumber of parameters the method accepts.
ABC scoreABC metric magnitude: sqrt(A^2 + B^2 + C^2) where A=assignments, B=branches (calls), C=conditions.
AssignmentsNumber of assignment operations (the A in ABC metric).
BranchesNumber of method/function calls (the B in ABC metric).
ConditionsNumber of boolean conditions (the C in ABC metric).
Halstead volumeInformation content of the method: N * log2(n) where N=total operators+operands, n=distinct operators+operands.
Halstead difficultyError proneness: (n1/2) * (N2/n2) where n1=distinct operators, N2=total operands, n2=distinct operands.
Halstead estimated bugsEstimated number of delivered bugs: E^(2/3) / 3000 where E = difficulty * volume.