@@ -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 ) ,
@@ -93,7 +94,29 @@ public void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalys
93
94
94
95
methodElement . Add ( new XAttribute ( "line-rate" , methodLineRate . ToString ( CultureInfo . InvariantCulture ) ) ) ;
95
96
methodElement . Add ( new XAttribute ( "branch-rate" , methodBranchRate . ToString ( CultureInfo . InvariantCulture ) ) ) ;
96
- methodElement . Add ( new XAttribute ( "complexity" , "NaN" ) ) ;
97
+
98
+ var methodMetrics = file . MethodMetrics
99
+ . FirstOrDefault ( q => q . ShortName == codeElement . Name
100
+ && q . Line == codeElement . FirstLine ) ;
101
+
102
+ if ( methodMetrics != null )
103
+ {
104
+ var complexityMetric = methodMetrics . Metrics . FirstOrDefault ( m => m . Name == ReportResources . CyclomaticComplexity ) ;
105
+ if ( complexityMetric != null && complexityMetric . Value . HasValue )
106
+ {
107
+ if ( ! fileComplexity . HasValue )
108
+ {
109
+ fileComplexity = 0 ;
110
+ }
111
+
112
+ fileComplexity += complexityMetric . Value . Value ;
113
+ methodElement . Add ( new XAttribute ( "complexity" , complexityMetric . Value . Value . ToString ( CultureInfo . InvariantCulture ) ) ) ;
114
+ }
115
+ }
116
+ else
117
+ {
118
+ methodElement . Add ( new XAttribute ( "complexity" , "NaN" ) ) ;
119
+ }
97
120
98
121
methodsElement . Add ( methodElement ) ;
99
122
}
@@ -110,7 +133,7 @@ public void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalys
110
133
111
134
classElement . Add ( new XAttribute ( "line-rate" , lineRate . ToString ( CultureInfo . InvariantCulture ) ) ) ;
112
135
classElement . Add ( new XAttribute ( "branch-rate" , branchRate . ToString ( CultureInfo . InvariantCulture ) ) ) ;
113
- classElement . Add ( new XAttribute ( "complexity" , "NaN" ) ) ;
136
+ classElement . Add ( new XAttribute ( "complexity" , fileComplexity . HasValue ? fileComplexity . Value . ToString ( CultureInfo . InvariantCulture ) : "NaN" ) ) ;
114
137
115
138
classElement . Add ( linesElement ) ;
116
139
@@ -124,16 +147,49 @@ public void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalys
124
147
/// <param name="summaryResult">The summary result.</param>
125
148
public void CreateSummaryReport ( SummaryResult summaryResult )
126
149
{
150
+ decimal ? summaryComplexity = null ;
151
+
127
152
foreach ( var assembly in summaryResult . Assemblies )
128
153
{
154
+ decimal ? assemblyComplexity = null ;
129
155
if ( this . packageElementsByName . TryGetValue ( assembly . Name , out XElement packageElement ) )
130
156
{
131
157
double packageLineRate = assembly . CoverableLines == 0 ? 1 : assembly . CoveredLines / ( double ) assembly . CoverableLines ;
132
158
double packageBranchRate = assembly . TotalBranches . GetValueOrDefault ( ) == 0 ? 1 : assembly . CoveredBranches . GetValueOrDefault ( ) / ( double ) assembly . TotalBranches . GetValueOrDefault ( ) ;
133
159
134
160
packageElement . Add ( new XAttribute ( "line-rate" , packageLineRate . ToString ( CultureInfo . InvariantCulture ) ) ) ;
135
161
packageElement . Add ( new XAttribute ( "branch-rate" , packageBranchRate . ToString ( CultureInfo . InvariantCulture ) ) ) ;
136
- packageElement . Add ( new XAttribute ( "complexity" , "NaN" ) ) ;
162
+
163
+ foreach ( var @class in assembly . Classes )
164
+ {
165
+ foreach ( var file in @class . Files )
166
+ {
167
+ foreach ( var methodMetric in file . MethodMetrics )
168
+ {
169
+ var metric = methodMetric . Metrics . FirstOrDefault ( m =>
170
+ m . Name == ReportResources . CyclomaticComplexity
171
+ && m . Value . HasValue ) ;
172
+
173
+ if ( metric != null )
174
+ {
175
+ if ( ! assemblyComplexity . HasValue )
176
+ {
177
+ assemblyComplexity = 0 ;
178
+ }
179
+
180
+ if ( ! summaryComplexity . HasValue )
181
+ {
182
+ summaryComplexity = 0 ;
183
+ }
184
+
185
+ assemblyComplexity += metric . Value . Value ;
186
+ summaryComplexity += metric . Value . Value ;
187
+ }
188
+ }
189
+ }
190
+ }
191
+
192
+ packageElement . Add ( new XAttribute ( "complexity" , assemblyComplexity . HasValue ? assemblyComplexity . Value . ToString ( CultureInfo . InvariantCulture ) : "NaN" ) ) ;
137
193
}
138
194
}
139
195
@@ -148,7 +204,7 @@ public void CreateSummaryReport(SummaryResult summaryResult)
148
204
rootElement . Add ( new XAttribute ( "lines-valid" , summaryResult . CoverableLines . ToString ( CultureInfo . InvariantCulture ) ) ) ;
149
205
rootElement . Add ( new XAttribute ( "branches-covered" , summaryResult . CoveredBranches . GetValueOrDefault ( ) . ToString ( CultureInfo . InvariantCulture ) ) ) ;
150
206
rootElement . Add ( new XAttribute ( "branches-valid" , summaryResult . TotalBranches . GetValueOrDefault ( ) . ToString ( CultureInfo . InvariantCulture ) ) ) ;
151
- rootElement . Add ( new XAttribute ( "complexity" , "NaN" ) ) ;
207
+ rootElement . Add ( new XAttribute ( "complexity" , summaryComplexity . HasValue ? summaryComplexity . Value . ToString ( CultureInfo . InvariantCulture ) : "NaN" ) ) ;
152
208
rootElement . Add ( new XAttribute ( "version" , 0 ) ) ;
153
209
rootElement . Add ( new XAttribute ( "timestamp" , ( ( long ) ( DateTime . Now - new DateTime ( 1970 , 1 , 1 ) ) . TotalSeconds ) . ToString ( CultureInfo . InvariantCulture ) ) ) ;
154
210
0 commit comments