use crate::priority::{DebtType, FunctionRole, UnifiedDebtItem};
pub fn format_impact(impact: &crate::priority::ImpactMetrics) -> String {
let mut parts = Vec::new();
if impact.coverage_improvement > 0.0 {
if impact.coverage_improvement >= 100.0 {
parts.push("Full test coverage".to_string());
} else if impact.coverage_improvement >= 50.0 {
parts.push(format!(
"+{}% function coverage",
impact.coverage_improvement as i32
));
} else {
parts.push("Partial coverage after refactor".to_string());
}
}
if impact.complexity_reduction > 0.0 {
parts.push(format!(
"-{} complexity",
impact.complexity_reduction as i32
));
}
if impact.risk_reduction > 0.0 {
parts.push(format!("-{:.1} risk", impact.risk_reduction));
}
if impact.lines_reduction > 0 {
parts.push(format!("-{} LOC", impact.lines_reduction));
}
if parts.is_empty() {
"Improved maintainability".to_string()
} else {
parts.join(", ")
}
}
pub fn extract_complexity_info(item: &UnifiedDebtItem) -> (u32, u32, u32, u32, usize) {
let cyclomatic = item.cyclomatic_complexity;
let cognitive = item.cognitive_complexity;
let branch_count = cyclomatic;
(
cyclomatic,
cognitive,
branch_count,
item.nesting_depth,
item.function_length,
)
}
pub fn extract_dependency_info(item: &UnifiedDebtItem) -> (usize, usize) {
(item.upstream_dependencies, item.downstream_dependencies)
}
pub fn format_debt_type(debt_type: &DebtType) -> &'static str {
match debt_type {
DebtType::TestingGap { .. } => "TEST GAP",
DebtType::ComplexityHotspot { .. } => "COMPLEXITY",
DebtType::DeadCode { .. } => "DEAD CODE",
DebtType::Duplication { .. } => "DUPLICATION",
DebtType::Risk { .. } => "RISK",
DebtType::TestComplexityHotspot { .. } => "TEST COMPLEXITY",
DebtType::TestTodo { .. } => "TEST TODO",
DebtType::TestDuplication { .. } => "TEST DUPLICATION",
DebtType::ErrorSwallowing { .. } => "ERROR SWALLOWING",
DebtType::AllocationInefficiency { .. } => "ALLOCATION",
DebtType::StringConcatenation { .. } => "STRING CONCAT",
DebtType::NestedLoops { .. } => "NESTED LOOPS",
DebtType::BlockingIO { .. } => "BLOCKING I/O",
DebtType::SuboptimalDataStructure { .. } => "DATA STRUCTURE",
DebtType::GodObject { .. } => "GOD OBJECT",
DebtType::FeatureEnvy { .. } => "FEATURE ENVY",
DebtType::PrimitiveObsession { .. } => "PRIMITIVE OBSESSION",
DebtType::MagicValues { .. } => "MAGIC VALUES",
DebtType::AssertionComplexity { .. } => "ASSERTION COMPLEXITY",
DebtType::FlakyTestPattern { .. } => "FLAKY TEST",
DebtType::AsyncMisuse { .. } => "ASYNC MISUSE",
DebtType::ResourceLeak { .. } => "RESOURCE LEAK",
DebtType::CollectionInefficiency { .. } => "COLLECTION INEFFICIENCY",
DebtType::ScatteredType { .. } => "SCATTERED TYPE",
DebtType::OrphanedFunctions { .. } => "ORPHANED FUNCTIONS",
DebtType::UtilitiesSprawl { .. } => "UTILITIES SPRAWL",
_ => "OTHER",
}
}
pub fn format_role(role: FunctionRole) -> &'static str {
match role {
FunctionRole::PureLogic => "PureLogic",
FunctionRole::Orchestrator => "Orchestrator",
FunctionRole::IOWrapper => "IOWrapper",
FunctionRole::EntryPoint => "EntryPoint",
FunctionRole::PatternMatch => "PatternMatch",
FunctionRole::Debug => "Debug",
FunctionRole::Unknown => "Unknown",
}
}