getProjectMetrics method

ProjectMetrics getProjectMetrics()

Calculates project-wide statistics.

ADR-016 2.1: Use List<num> directly to avoid cast<num>() wrapper lists.

Implementation

ProjectMetrics getProjectMetrics() {
  if (_functionMetrics.isEmpty) {
    return ProjectMetrics.empty();
  }

  // ADR-016 2.1: Use List<num> from start to avoid cast<num>()
  final miValues = <num>[];
  final cyclomaticValues = <num>[];
  final cognitiveValues = <num>[];
  final locValues = <num>[];
  var totalVolume = 0.0;
  var totalLoc = 0;

  for (final func in _functionMetrics.values) {
    miValues.add(func.result.maintainabilityIndex);
    cyclomaticValues.add(func.result.cyclomaticComplexity);
    cognitiveValues.add(func.result.cognitiveComplexity);
    locValues.add(func.result.linesOfCode);
    totalVolume += func.result.halsteadMetrics.volume;
    totalLoc += func.result.linesOfCode;
  }

  return ProjectMetrics(
    fileCount: fileCount,
    functionCount: functionCount,
    totalLinesOfCode: totalLoc,
    maintainabilityIndex: _calculateStats(miValues),
    cyclomaticComplexity: _calculateStats(cyclomaticValues),
    cognitiveComplexity: _calculateStats(cognitiveValues),
    linesOfCode: _calculateStats(locValues),
    totalHalsteadVolume: totalVolume,
  );
}