UNPKG

archunit

Version:

ArchUnit TypeScript is an architecture testing library, to specify and assert architecture rules in your TypeScript app

165 lines (164 loc) 4.97 kB
import { ClassInfo, Metric } from '../extraction/interface'; /** * LCOM (Lack of Cohesion of Methods) metrics interface */ export interface LCOMMetric extends Metric { name: string; calculate(classInfo: ClassInfo): number; description: string; } /** * LCOM96a (Lack of Cohesion of Methods, Handerson et al., 1996) * * Formula: LCOM96a = (1/(1-m)) * ((1/a) * Σ(μ(A)) - m) for all attributes A * * Where: * - a is the number of attributes (fields) in the class * - m is the number of attributes (fields) in the class * - μ(A) is the number of methods that access an attribute (field) A * - The formula measures how methods are connected through attributes * * Returns a value >= 0: * - 0: perfect cohesion * - Higher values: increasing lack of cohesion */ export declare class LCOM96a implements LCOMMetric { name: string; description: string; calculate(classInfo: ClassInfo): number; } /** * LCOM96b (Lack of Cohesion of Methods, Handerson et al., 1996) * * Formula: LCOM96b = (1/a) * Σ((1/m) * (m - μ(A))) for all attributes A * * Where: * - m is the number of methods in the class * - a is the number of attributes (fields) in the class * - μ(A) is the number of methods that access an attribute (field) A * - The formula measures how methods are connected through attributes * * Returns a value between 0 and 1: * - 0: perfect cohesion (all methods access all attributes) * - 1: complete lack of cohesion (each method accesses its own attribute) */ export declare class LCOM96b implements LCOMMetric { name: string; description: string; calculate(classInfo: ClassInfo): number; } /** * LCOM1 (Chidamber & Kemerer, 1991) * * Formula: LCOM1 = |P| - |Q|, where P > Q, otherwise 0 * * Where: * - P is the set of method pairs that do not share instance variables * - Q is the set of method pairs that share at least one instance variable * - If P <= Q, then LCOM1 = 0 * * Returns a value >= 0: * - 0: good cohesion * - Higher values: lack of cohesion */ export declare class LCOM1 implements LCOMMetric { name: string; description: string; calculate(classInfo: ClassInfo): number; } /** * LCOM2 (Chidamber & Kemerer, 1994 - revised) * * Formula: LCOM2 = 1 - (Σ(MF) / (M * F)) * * Where: * - M is the number of methods in the class * - F is the number of fields in the class * - MF is the number of methods that access each field * - Σ(MF) is the sum of MF over all fields * * Returns a value between 0 and 1: * - 0: perfect cohesion (all methods access all fields) * - 1: no cohesion (no method accesses any field) */ export declare class LCOM2 implements LCOMMetric { name: string; description: string; calculate(classInfo: ClassInfo): number; } /** * LCOM3 (Li & Henry, 1993) * * Formula: LCOM3 = (M - Σ(MF)/F) / (M - 1) * * Where: * - M is the number of methods in the class * - F is the number of fields in the class * - MF is the number of methods that access each field * - Σ(MF) is the sum of MF over all fields * * Returns a value between 0 and 1: * - 0: perfect cohesion * - 1: lack of cohesion */ export declare class LCOM3 implements LCOMMetric { name: string; description: string; calculate(classInfo: ClassInfo): number; } /** * LCOM4 (Hitz & Montazeri, 1995) * * Formula: LCOM4 = number of connected components in the method-field graph * * Where: * - A connected component is a maximal set of methods connected through shared fields * - Methods are connected if they access the same field or are transitively connected * * Returns a value >= 1: * - 1: perfect cohesion (all methods are connected) * - Higher values: increasing lack of cohesion */ export declare class LCOM4 implements LCOMMetric { name: string; description: string; calculate(classInfo: ClassInfo): number; } /** * LCOM5 (Henderson-Sellers, 1996) * * Formula: LCOM5 = (a - μΣ(mA)) / (a - μ) * * Where: * - a is the number of attributes (fields) * - μ is the number of methods * - mA is the number of methods accessing attribute A * - Σ(mA) is the sum over all attributes * * Returns a value between 0 and 1: * - 0: perfect cohesion * - 1: lack of cohesion */ export declare class LCOM5 implements LCOMMetric { name: string; description: string; calculate(classInfo: ClassInfo): number; } /** * LCOM* (Fernandez & Pena, 2006) - also known as LCOM-star * * Formula: LCOM* = (number of method pairs without shared attributes) / (total method pairs) * * Where: * - Method pairs are counted once (not twice) * - Shared attributes means both methods access at least one common field * * Returns a value between 0 and 1: * - 0: perfect cohesion (all method pairs share attributes) * - 1: no cohesion (no method pairs share attributes) */ export declare class LCOMStar implements LCOMMetric { name: string; description: string; calculate(classInfo: ClassInfo): number; }