Skip to main content

Class cohesion DevCenter

io.moderne.devcenter.ClassCohesionDevCenter

A DevCenter that finds class quality metrics for repositories and buckets the average LCOM4 (Lack of Cohesion of Methods, version 4) into HIGH / MEDIUM / LOW cohesion categories.

Recipe source

GitHub: code-quality-devcenter.yml, Issue Tracker, Maven Central

This recipe is composed of more than one recipe. If you want to customize the set of recipes this is composed of, you can find and copy the GitHub source for the recipe from the link above.

This recipe is available under the Moderne Source Available License.

Definition

  • Find class quality metrics
  • Find test coverage gaps
  • DevCenter card from a data table column
    • inputDataTable: io.moderne.prethink.table.ClassQualityMetrics
    • cardName: Average Class Maintainability
    • column: maintainabilityIndex
    • aggregation: AVERAGE
    • buckets: [Bucket(name=F, moreThan=0), Bucket(name=D, moreThan=20), Bucket(name=C, moreThan=40), Bucket(name=B, moreThan=60), Bucket(name=A, moreThan=80)]
  • DevCenter card from a data table column
    • inputDataTable: io.moderne.prethink.table.ClassQualityMetrics
    • cardName: Average Class Cohesion
    • column: lcom4
    • aggregation: AVERAGE
    • buckets: [Bucket(name=LOW, moreThan=10), Bucket(name=MEDIUM, moreThan=3), Bucket(name=HIGH, moreThan=0)]
  • DevCenter card from a data table column
    • inputDataTable: io.moderne.prethink.table.TestGaps
    • cardName: Test Gaps Risk
    • column: riskScore
    • aggregation: SUM
    • buckets: [Bucket(name=LOW, moreThan=0), Bucket(name=MEDIUM, moreThan=3), Bucket(name=HIGH, moreThan=10)]

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 ClassCohesionDevCenter

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

mod config recipes jar install io.moderne.recipe:rewrite-devcenter:1.24.0

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

Class quality metrics

io.moderne.prethink.table.ClassQualityMetrics

Per-class code quality metrics including WMC, LCOM4, TCC, CBO, and maintainability index.

Column NameDescription
Source pathThe path to the source file containing the class.
Class nameThe fully qualified name of the class.
Line countNumber of lines in the class.
Method countNumber of methods defined in the class.
Field countNumber of fields defined in the class.
WMCWeighted Methods per Class: sum of cyclomatic complexities of all methods.
LCOM4Lack of Cohesion of Methods (Hitz-Montazeri): number of connected components in the method-field access graph. 1 = cohesive, >1 = should be split.
TCCTight Class Cohesion: proportion of directly connected method pairs (sharing field access). 0.0-1.0, higher is more cohesive.
CBOCoupling Between Objects: number of distinct classes this class is coupled to.
Maintainability indexComposite score (0-100) combining Halstead Volume, cyclomatic complexity, and LOC. Higher is more maintainable.