Skip to content

Commit 928caf4

Browse files
committed
Fix low coupling weight = 0 on when there are no declarations
1 parent f6466d0 commit 928caf4

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

cypher/DependsOn_Relationship_Weights/Add_fine_grained_weights_for_Typescript_internal_module_dependencies.cypher

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
,target
1010
,moduleDependency
1111
,moduleDependency.cardinality AS targetModuleCardinality
12-
1312
// Get optional external (e.g. type) declarations that the external module (target) provides and the source module uses
1413
OPTIONAL MATCH (source)-[elementDependency:DEPENDS_ON|EXPORTS]->(elementType:TS)<-[:EXPORTS]-(target)
1514
WITH source
@@ -40,13 +39,18 @@ OPTIONAL MATCH (source)-[abstractDependency:DEPENDS_ON|EXPORTS]->(abstractType:T
4039
// - "lowCouplingElement25PercentWeight" subtracts 75% of the weights for abstract types like Interfaces and Type aliases
4140
// to compensate for their low coupling influence. Not included "high coupling" elements like Functions and Classes
4241
// remain in the weight as they were. The same applies for "lowCouplingElement10PercentWeight" but with in a stronger manner.
42+
// If there are no declarations and therefore the elementTypeCardinality is zero then the original targetModuleCardinality is used.
4343
SET moduleDependency.declarationCount = elementTypeCount
4444
,moduleDependency.abstractTypeCount = abstractTypeCount
4545
,moduleDependency.abstractTypeCardinality = abstractTypeCardinality
46-
,moduleDependency.lowCouplingElement25PercentWeight =
47-
toInteger(elementTypeCardinality - round(abstractTypeCardinality * 0.75))
48-
,moduleDependency.lowCouplingElement10PercentWeight =
49-
toInteger(elementTypeCardinality - round(abstractTypeCardinality * 0.90))
46+
,moduleDependency.lowCouplingElement25PercentWeight = toInteger(
47+
coalesce(nullif(elementTypeCardinality, 0), targetModuleCardinality) -
48+
round(abstractTypeCardinality * 0.75)
49+
)
50+
,moduleDependency.lowCouplingElement10PercentWeight = toInteger(
51+
coalesce(nullif(elementTypeCardinality, 0), targetModuleCardinality) -
52+
round(abstractTypeCardinality * 0.90)
53+
)
5054
RETURN source.globalFqn AS sourceName
5155
,target.globalFqn AS targetName
5256
,elementTypeCount

0 commit comments

Comments
 (0)