Skip to content

Commit

Permalink
refactor: renaming and method signature changes #368
Browse files Browse the repository at this point in the history
  • Loading branch information
benedikt-mehl-mw authored and mylinhdao committed Jun 3, 2024
1 parent fa14d8b commit bf730b9
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 122 deletions.
23 changes: 5 additions & 18 deletions src/parser/metrics/coupling/coupling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ let dlog: DebugLoggerFunction = debuglog("metric-gardener", (logger) => {
dlog = logger;
});
export class Coupling implements CouplingMetric {
private readonly filesWithMultipleTypeDeclarations: ParsedFile[] = [];
private readonly alreadyAddedRelationships = new Set<string>();

private typesMap = new Map<FQTN, TypeInfo>();
Expand All @@ -42,19 +41,18 @@ export class Coupling implements CouplingMetric {
) {}

processFile(parsedFile: ParsedFile): void {
const typesFromFile = this.typeCollector.getTypesFromFile(parsedFile);
const typesFromFile: Map<FQTN, TypeInfo> = this.typeCollector.getTypesFromFile(parsedFile);
this.typesMap = new Map([...this.typesMap, ...typesFromFile]);

const accessorsFromFile = this.publicAccessorCollector.getPublicAccessorsFromFile(
parsedFile,
typesFromFile,
);
for (const [accessorName, accessors] of accessorsFromFile) {
const existingAccessors = this.publicAccessorsMap.get(accessorName);
if (existingAccessors === undefined) {
if (this.publicAccessorsMap.get(accessorName) === undefined) {
this.publicAccessorsMap.set(accessorName, accessors);
} else {
existingAccessors.push(...accessors);
this.publicAccessorsMap.get(accessorName)!.push(...accessors);
}
}

Expand All @@ -67,8 +65,6 @@ export class Coupling implements CouplingMetric {
}

calculate(): CouplingResult {
// Postprocessing

dlog("\n\n");
dlog("namespaces", this.typesMap, "\n\n");
dlog("usages", this.usagesCandidates);
Expand Down Expand Up @@ -190,7 +186,7 @@ export class Coupling implements CouplingMetric {
this.addFilePathIfNotExists(couplingValues, toFile);

// Add only +1 outgoing dependency per "toClassName" for every file
this.updateOutgoingDependency(fromFile, couplingValues, couplingItem);
this.updateOutgoingDependency(fromFile, couplingItem);
this.updateMetricsForFile(couplingItem.toSource, "incoming", couplingValues);
}

Expand Down Expand Up @@ -222,11 +218,7 @@ export class Coupling implements CouplingMetric {
}
}

private updateOutgoingDependency(
fromFile: string,
couplingValues: Map<string, CouplingMetrics>,
couplingItem: Relationship,
): void {
private updateOutgoingDependency(fromFile: string, couplingItem: Relationship): void {
if (!this.outgoingDependencyByFile.has(fromFile)) {
this.outgoingDependencyByFile.set(fromFile, new Set());
}
Expand All @@ -250,11 +242,6 @@ export class Coupling implements CouplingMetric {
return;
}

const types = this.typeCollector.getTypesFromFile(parsedFile);
if (types.size > 1) {
this.filesWithMultipleTypeDeclarations.push(parsedFile);
}

couplingMetrics[
direction === "outgoing" ? "outgoing_dependencies" : "incoming_dependencies"
] += 1;
Expand Down
Loading

0 comments on commit bf730b9

Please sign in to comment.