Skip to content

Refactor main.py to improve cohesion (LCOM4: 4+ responsibilities) #213

@coderabbitai

Description

@coderabbitai

Low Cohesion Issue

File: .github/actions/rust-build-release/src/main.py

Problem

This module has at least 4 different responsibilities amongst its 33 functions (LCOM4 threshold = 4).

Why This Matters

Cohesion is a measure of how well the elements in a file belong together. CodeScene measures cohesion using the LCOM4 metric (Lack of Cohesion Measure). With LCOM4, the functions inside a module are related if:

  • a) they access the same data members, or
  • b) they call each other

High Cohesion is desirable as it means that all functions are related and likely to represent the same responsibility.

Low Cohesion is problematic since it means that the module contains multiple behaviours. Low Cohesion leads to code that's harder to understand, requires more tests, and very often becomes a coordination magnet for developers.

Recommended Fix

Look to modularise the code by splitting the file into more cohesive units; functions that belong together should still be located together. A common refactoring is EXTRACT CLASS.

Consider splitting responsibilities such as:

  • Toolchain management
  • Cross/cargo decision logic
  • Target validation
  • Container runtime management
  • Build execution orchestration
  • Path/manifest resolution

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions