-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEffective_lines_of_method_code_per_package.cypher
40 lines (39 loc) · 2.65 KB
/
Effective_lines_of_method_code_per_package.cypher
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Effective lines of method code per package. Requires "Add_file_name and_extension.cypher".
MATCH (artifact:Artifact)-[:CONTAINS]->(package:Package)
MATCH (package)-[:CONTAINS]->(type:Type)
MATCH (type)-[:DECLARES]->(method:Method)
WHERE method.effectiveLineCount > 0
WITH artifact.name AS artifactName
,package.fqn AS fullPackageName
,package.name AS packageName
,sum(method.effectiveLineCount) AS sumEffectiveLinesOfMethodCode
,sum(method.cyclomaticComplexity) AS sumCyclomaticComplexity
,COUNT(DISTINCT method) AS numberOfMethods
,reduce( // Get the max effectiveLineCount of all methods in the package with the name and type of the method
loc = {max:-1}, // initial object with max lines of code = -1
m IN collect({method:method, type:type}) | // collect all methods and their types as objects
CASE WHEN (m.method.effectiveLineCount > loc.max) // when there is a method with a higher line count...
THEN {max: m.method.effectiveLineCount, method: m.method, type: m.type} // then update the object
ELSE loc // otherwise keep the object as it was
END
) AS methodWithMaxLinesOfCode
,reduce( // Get the max cyclomaticComplexity of all methods in the package with the name and type of the method
cmplx = {max:-1}, // initial object with max cyclomatic complexity = -1
m IN collect({method:method, type:type}) | // collect all methods and their types as objects
CASE WHEN (m.method.cyclomaticComplexity > cmplx.max)
THEN {max: m.method.cyclomaticComplexity, method: m.method, type: m.type} // then update the object
ELSE cmplx // otherwise keep the object as it was
END
) AS methodWithMaxCyclomaticComplexity
RETURN artifactName, fullPackageName
,sumEffectiveLinesOfMethodCode AS linesInPackage
,sumCyclomaticComplexity AS complexityInPackage
,numberOfMethods AS methodCount
,methodWithMaxLinesOfCode.max AS maxLinesMethod
,methodWithMaxLinesOfCode.type.name AS maxLinesMethodType
,methodWithMaxLinesOfCode.method.name AS maxLinesMethodName
,methodWithMaxCyclomaticComplexity.max AS maxComplexity
,methodWithMaxCyclomaticComplexity.type.name AS maxComplexityType
,methodWithMaxCyclomaticComplexity.method.name AS maxComplexityMethod
,packageName
ORDER BY linesInPackage DESC, artifactName ASC, fullPackageName