orchestrata_ultimate.refactor.codemod.analysis.coupling

Reference › orchestrata_ultimate › refactor › codemod › analysis › coupling

CouplingAnalyzer is a read-only adapter over CodeIntelligenceGraph.coupling_score in _cig. analyze(target) resolves a module through the shared resolver in protocol and returns the CouplingScore record from _types. It changes nothing and is imported by the analysis facade.

At a glance

Source src/orchestrata_ultimate/refactor/codemod/analysis/coupling.py
Lines of code 48
Classes 1
Functions 0
Imports (internal) orchestrata_ultimate.core.base.traces, orchestrata_ultimate.refactor.codemod._cig, orchestrata_ultimate.refactor.codemod._types, orchestrata_ultimate.refactor.codemod.analysis.protocol
Imported by orchestrata_ultimate.refactor.codemod.analysis
Tests that import it none

Class diagram

Class diagram orchestrata_ultimate.refactor.codemod.analysis.coupling

Dependency diagram

Dependency diagram orchestrata_ultimate.refactor.codemod.analysis.coupling

API

Classes

CouplingAnalyzer

Decorators: traces(spec='110', story='US-110-006', reqs=['REQ-110-031', 'REQ-110-032']) · Line 18

Efferent/afferent coupling and instability of one module.

Method Signature Summary
__init__ __init__(cig: CodeIntelligenceGraph) -> None
analyze analyze(target: str | None = None) -> CouplingScore Coupling of target (a module path).
_resolve _resolve(target: str) -> int

Source

Permalink: https://gitlab.com/MSamy/orchestrata-ultimate-architecture/-/blob/a4cbc2bdf/src/orchestrata_ultimate/refactor/codemod/analysis/coupling.py

"""CouplingAnalyzer — read-only adapter over ``CodeIntelligenceGraph.coupling_score``."""

from __future__ import annotations

from typing import TYPE_CHECKING

from orchestrata_ultimate.core.base.traces import traces
from orchestrata_ultimate.refactor.codemod._types import CouplingScore
from orchestrata_ultimate.refactor.codemod.analysis.protocol import resolve_node_id

if TYPE_CHECKING:
    from orchestrata_ultimate.refactor.codemod._cig import CodeIntelligenceGraph

__all__ = ["CouplingAnalyzer"]


@traces(spec="110", story="US-110-006", reqs=["REQ-110-031", "REQ-110-032"])
class CouplingAnalyzer:
    """Efferent/afferent coupling and instability of one module.

    GAP-4: the CIG's CSR index is built from every edge type, so the counts
    include DEFINES and HAS_PARAMETER edges, not only IMPORTS. The adapter
    returns the graph's result unchanged.
    """

    name = "coupling_score"

    @traces(spec="110", story="US-110-006", reqs=["REQ-110-031", "REQ-110-032"])
    def __init__(self, cig: CodeIntelligenceGraph) -> None:
        self._cig = cig

    @traces(spec="110", story="US-110-006", reqs=["REQ-110-031", "REQ-110-032"])
    def analyze(self, target: str | None = None) -> CouplingScore:
        """Coupling of ``target`` (a module path).

        Raises:
            ValueError: ``target`` is missing or names no module in the graph.
        """
        if target is None:
            raise ValueError("coupling_score requires a target module")
        return self._cig.coupling_score(self._resolve(target))

    @traces(spec="110", story="US-110-006", reqs=["REQ-110-031"])
    def _resolve(self, target: str) -> int:
        node_id = resolve_node_id(self._cig, target)
        if node_id is None:
            raise ValueError(f"module '{target}' not found in CIG")
        return node_id