Skip to content

Commit d6a7300

Browse files
committed
Fix missing declarationCount property on DEPENDS_ON relationships
1 parent fc35197 commit d6a7300

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

cypher/DependsOn_Relationship_Weights/Add_fine_grained_weights_for_Typescript_external_module_dependencies.cypher

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
// Get the top level dependency between a Typescript module and the external modules it uses
44
MATCH (source:TS:Module)-[moduleDependency:DEPENDS_ON]->(target:ExternalModule)
5-
WHERE NOT EXISTS {(target)-[:RESOLVES_TO]->(source)}
5+
// Exclude all targets where an ExternalModule was found that resolves to them
6+
// because those are covered in the fine grained weights for "ExternalModule"s.
7+
WHERE NOT EXISTS { (target)-[:RESOLVES_TO]->(source) }
68
OPTIONAL MATCH (source)-[resolvedModuleDependency:DEPENDS_ON]->(resolvedTarget:TS:Module)<-[:RESOLVES_TO]-(target)
79
WITH source
810
,target
@@ -43,15 +45,17 @@ OPTIONAL MATCH (source)-[ra:DEPENDS_ON]->(declaration)-[:RESOLVES_TO]->(abstract
4345
// - "lowCouplingElement25PercentWeight" subtracts 75% of the weights for abstract types like Interfaces and Type aliases
4446
// to compensate for their low coupling influence. Not included "high coupling" elements like Functions and Classes
4547
// remain in the weight as they were. The same applies for "lowCouplingElement10PercentWeight" but with in a stronger manner.
46-
SET moduleDependency.declarationCount = declarationCount
47-
,moduleDependency.abstractTypeCount = abstractTypeCount
48-
,moduleDependency.abstractTypeCardinality = abstractTypeCardinality
49-
,moduleDependency.lowCouplingElement25PercentWeight = toInteger(moduleDependency.cardinality - round(abstractTypeCardinality * 0.75))
50-
,moduleDependency.lowCouplingElement10PercentWeight = toInteger(moduleDependency.cardinality - round(abstractTypeCardinality * 0.90))
48+
SET moduleDependency.declarationCount = coalesce(declarationCount, 0)
49+
,moduleDependency.abstractTypeCount = coalesce(abstractTypeCount, 0)
50+
,moduleDependency.abstractTypeCardinality = coalesce(abstractTypeCardinality, 0)
51+
,moduleDependency.lowCouplingElement25PercentWeight =
52+
toInteger(moduleDependency.cardinality - round(abstractTypeCardinality * 0.75))
53+
,moduleDependency.lowCouplingElement10PercentWeight =
54+
toInteger(moduleDependency.cardinality - round(abstractTypeCardinality * 0.90))
5155
// Set all new properties also to a resolved (direct) dependency relationship if it exists.
52-
,resolvedModuleDependency.declarationCount = declarationCount
53-
,resolvedModuleDependency.abstractTypeCount = abstractTypeCount
54-
,resolvedModuleDependency.abstractTypeCardinality = abstractTypeCardinality
56+
,resolvedModuleDependency.declarationCount = coalesce(declarationCount, 0)
57+
,resolvedModuleDependency.abstractTypeCount = coalesce(abstractTypeCount, 0)
58+
,resolvedModuleDependency.abstractTypeCardinality = coalesce(abstractTypeCardinality, 0)
5559
,resolvedModuleDependency.lowCouplingElement25PercentWeight = toInteger(resolvedModuleDependency.cardinality - round(abstractTypeCardinality * 0.75))
5660
,resolvedModuleDependency.lowCouplingElement10PercentWeight = toInteger(resolvedModuleDependency.cardinality - round(abstractTypeCardinality * 0.90))
5761
RETURN source.globalFqn AS sourceName

cypher/DependsOn_Relationship_Weights/Add_fine_grained_weights_for_Typescript_internal_module_dependencies.cypher

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,29 @@
88
WITH source
99
,target
1010
,moduleDependency
11-
OPTIONAL MATCH (source)-[elementDependency:DEPENDS_ON]->(elementType:TS)<-[:EXPORTS]-(target)
11+
,moduleDependency.cardinality AS targetModuleCardinality
12+
13+
// Get optional external (e.g. type) declarations that the external module (target) provides and the source module uses
14+
OPTIONAL MATCH (source)-[elementDependency:DEPENDS_ON|EXPORTS]->(elementType:TS)<-[:EXPORTS]-(target)
1215
WITH source
1316
,target
1417
,moduleDependency
15-
,count(DISTINCT elementType.globalFqn) AS elementTypeCount
16-
,sum(elementDependency.cardinality) AS elementTypeCardinality
17-
,collect(DISTINCT elementType.globalFqn)[0..4] AS elementTypeExamples
18-
OPTIONAL MATCH (source)-[abstractDependency:DEPENDS_ON]->(abstractType:TypeAlias|Interface)<-[:EXPORTS]-(target)
18+
,targetModuleCardinality
19+
,coalesce(count(DISTINCT elementType.globalFqn), 0) AS elementTypeCount
20+
,sum(elementDependency.cardinality) AS elementTypeCardinality
21+
,collect(DISTINCT elementType.globalFqn)[0..4] AS elementTypeExamples
22+
// Get optional low coupling elements (TypeAlias, Interface) that the source module contains and defines (low level) that depend on the external module (target)
23+
OPTIONAL MATCH (source)-[abstractDependency:DEPENDS_ON|EXPORTS]->(abstractType:TypeAlias|Interface)<-[:EXPORTS]-(target)
1924
WITH source
2025
,target
2126
,moduleDependency
27+
,targetModuleCardinality
2228
,elementTypeCount
2329
,elementTypeCardinality
2430
,elementTypeExamples
25-
,count(DISTINCT abstractType.globalFqn) AS abstractTypeCount
26-
,sum(abstractDependency.cardinality) AS abstractTypeCardinality
27-
,collect(DISTINCT abstractType.globalFqn)[0..4] AS abstractTypeExamples
31+
,coalesce(count(DISTINCT abstractType.globalFqn), 0) AS abstractTypeCount
32+
,sum(abstractDependency.cardinality) AS abstractTypeCardinality
33+
,collect(DISTINCT abstractType.globalFqn)[0..4] AS abstractTypeExamples
2834
// Set additional fine grained relationship properties (weights) to distinguish low and high coupling elements.
2935
// The "cardinality" property is similar to "weight" property for Java dependencies and comes from the jQAssistant Typescript Plugin.
3036
// - "abstractTypeCardinality" is the sum of all TypeAlias and Interface cardinality properties (if available)
@@ -34,21 +40,22 @@ OPTIONAL MATCH (source)-[abstractDependency:DEPENDS_ON]->(abstractType:TypeAlias
3440
// - "lowCouplingElement25PercentWeight" subtracts 75% of the weights for abstract types like Interfaces and Type aliases
3541
// to compensate for their low coupling influence. Not included "high coupling" elements like Functions and Classes
3642
// remain in the weight as they were. The same applies for "lowCouplingElement10PercentWeight" but with in a stronger manner.
37-
SET moduleDependency.abstractTypeCount = abstractTypeCount
43+
SET moduleDependency.declarationCount = elementTypeCount
44+
,moduleDependency.abstractTypeCount = abstractTypeCount
3845
,moduleDependency.abstractTypeCardinality = abstractTypeCardinality
3946
,moduleDependency.lowCouplingElement25PercentWeight =
4047
toInteger(elementTypeCardinality - round(abstractTypeCardinality * 0.75))
4148
,moduleDependency.lowCouplingElement10PercentWeight =
4249
toInteger(elementTypeCardinality - round(abstractTypeCardinality * 0.90))
4350
RETURN source.globalFqn AS sourceName
4451
,target.globalFqn AS targetName
45-
,abstractTypeCount
4652
,elementTypeCount
47-
,moduleDependency.cardinality AS externalModuleCardinality
48-
,abstractTypeCardinality
53+
,abstractTypeCount
54+
,targetModuleCardinality
4955
,elementTypeCardinality
56+
,abstractTypeCardinality
5057
,moduleDependency.lowCouplingElement25PercentWeight
5158
,moduleDependency.lowCouplingElement10PercentWeight
52-
,abstractTypeExamples
5359
,elementTypeExamples
60+
,abstractTypeExamples
5461
ORDER BY sourceName ASC

0 commit comments

Comments
 (0)