Skip to content

Commit d93f645

Browse files
committed
Adding complexity to Cobertura
Adding complexity to cobertura Revert "Adding complexity to Cobertura" This reverts commit de21ada18a20a32dcdf6bfb78c28736af42f307f.
1 parent 170172b commit d93f645

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/ReportGenerator.Core/Reporting/Builders/CoberturaReportBuilder.cs

+22-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalys
6262

6363
foreach (var fileAnalysis in fileAnalyses)
6464
{
65+
decimal? fileComplexity = null;
6566
var classElement = new XElement(
6667
"class",
6768
new XAttribute("name", @class.Name),
@@ -95,6 +96,26 @@ public void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalys
9596
methodElement.Add(new XAttribute("branch-rate", methodBranchRate.ToString(CultureInfo.InvariantCulture)));
9697
methodElement.Add(new XAttribute("complexity", "NaN"));
9798

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+
98119
methodsElement.Add(methodElement);
99120
}
100121

@@ -110,7 +131,7 @@ public void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalys
110131

111132
classElement.Add(new XAttribute("line-rate", lineRate.ToString(CultureInfo.InvariantCulture)));
112133
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"));
114135

115136
classElement.Add(linesElement);
116137

0 commit comments

Comments
 (0)