@@ -62,6 +62,7 @@ public void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalys
62
62
63
63
foreach ( var fileAnalysis in fileAnalyses )
64
64
{
65
+ decimal ? fileComplexity = null ;
65
66
var classElement = new XElement (
66
67
"class" ,
67
68
new XAttribute ( "name" , @class . Name ) ,
@@ -95,6 +96,26 @@ public void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalys
95
96
methodElement . Add ( new XAttribute ( "branch-rate" , methodBranchRate . ToString ( CultureInfo . InvariantCulture ) ) ) ;
96
97
methodElement . Add ( new XAttribute ( "complexity" , "NaN" ) ) ;
97
98
99
+ var methodMetrics = file . MethodMetrics . FirstOrDefault ( q => q . ShortName == codeElement . Name ) ;
100
+ if ( methodMetrics != null )
101
+ {
102
+ var complexityMetric = methodMetrics . Metrics . FirstOrDefault ( m => m . Name == ReportResources . CyclomaticComplexity ) ;
103
+ if ( complexityMetric != null && complexityMetric . Value . HasValue )
104
+ {
105
+ if ( ! fileComplexity . HasValue )
106
+ {
107
+ fileComplexity = 0 ;
108
+ }
109
+
110
+ fileComplexity += complexityMetric . Value . Value ;
111
+ methodElement . Add ( new XAttribute ( "complexity" , complexityMetric . Value . Value . ToString ( CultureInfo . InvariantCulture ) ) ) ;
112
+ }
113
+ }
114
+ else
115
+ {
116
+ methodElement . Add ( new XAttribute ( "complexity" , "NaN" ) ) ;
117
+ }
118
+
98
119
methodsElement . Add ( methodElement ) ;
99
120
}
100
121
@@ -110,7 +131,7 @@ public void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalys
110
131
111
132
classElement . Add ( new XAttribute ( "line-rate" , lineRate . ToString ( CultureInfo . InvariantCulture ) ) ) ;
112
133
classElement . Add ( new XAttribute ( "branch-rate" , branchRate . ToString ( CultureInfo . InvariantCulture ) ) ) ;
113
- classElement . Add ( new XAttribute ( "complexity" , "NaN" ) ) ;
134
+ classElement . Add ( new XAttribute ( "complexity" , fileComplexity . HasValue ? fileComplexity . Value . ToString ( CultureInfo . InvariantCulture ) : "NaN" ) ) ;
114
135
115
136
classElement . Add ( linesElement ) ;
116
137
0 commit comments