Skip to content

Commit

Permalink
Adding complexity to assembly/summary
Browse files Browse the repository at this point in the history
  • Loading branch information
eddynaka committed Aug 2, 2020
1 parent d93f645 commit 4bb37aa
Showing 1 changed file with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,43 @@ public void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalys
/// <param name="summaryResult">The summary result.</param>
public void CreateSummaryReport(SummaryResult summaryResult)
{
decimal? summaryComplexity = null;
foreach (var assembly in summaryResult.Assemblies)
{
decimal? assemblyComplexity = null;
if (this.packageElementsByName.TryGetValue(assembly.Name, out XElement packageElement))
{
double packageLineRate = assembly.CoverableLines == 0 ? 1 : assembly.CoveredLines / (double)assembly.CoverableLines;
double packageBranchRate = assembly.TotalBranches.GetValueOrDefault() == 0 ? 1 : assembly.CoveredBranches.GetValueOrDefault() / (double)assembly.TotalBranches.GetValueOrDefault();

packageElement.Add(new XAttribute("line-rate", packageLineRate.ToString(CultureInfo.InvariantCulture)));
packageElement.Add(new XAttribute("branch-rate", packageBranchRate.ToString(CultureInfo.InvariantCulture)));
packageElement.Add(new XAttribute("complexity", "NaN"));

foreach (var @class in assembly.Classes)
{
foreach (var file in @class.Files)
{
foreach (var methodMetric in file.MethodMetrics)
{
var metric = methodMetric.Metrics.FirstOrDefault(m =>
m.Name == ReportResources.CyclomaticComplexity
&& m.Value.HasValue);
if (metric != null)
{
if (!assemblyComplexity.HasValue)
{
assemblyComplexity = 0;
summaryComplexity = 0;
}

assemblyComplexity += metric.Value.Value;
summaryComplexity += metric.Value.Value;
}
}
}
}

packageElement.Add(new XAttribute("complexity", assemblyComplexity.HasValue ? assemblyComplexity.Value.ToString(CultureInfo.InvariantCulture) : "NaN"));
}
}

Expand All @@ -169,7 +196,7 @@ public void CreateSummaryReport(SummaryResult summaryResult)
rootElement.Add(new XAttribute("lines-valid", summaryResult.CoverableLines.ToString(CultureInfo.InvariantCulture)));
rootElement.Add(new XAttribute("branches-covered", summaryResult.CoveredBranches.GetValueOrDefault().ToString(CultureInfo.InvariantCulture)));
rootElement.Add(new XAttribute("branches-valid", summaryResult.TotalBranches.GetValueOrDefault().ToString(CultureInfo.InvariantCulture)));
rootElement.Add(new XAttribute("complexity", "NaN"));
rootElement.Add(new XAttribute("complexity", summaryComplexity.HasValue ? summaryComplexity.Value.ToString(CultureInfo.InvariantCulture) : "NaN"));
rootElement.Add(new XAttribute("version", 0));
rootElement.Add(new XAttribute("timestamp", ((long)(DateTime.Now - new DateTime(1970, 1, 1)).TotalSeconds).ToString(CultureInfo.InvariantCulture)));

Expand Down

0 comments on commit 4bb37aa

Please sign in to comment.