use crate::adapters::analyzers::iosp::{ComplexityMetrics, FunctionAnalysis};
use crate::config::sections::ComplexityConfig;
pub(super) fn would_trigger(
f: &FunctionAnalysis,
c: &ComplexityMetrics,
cx: &ComplexityConfig,
) -> bool {
exceeds_basic_thresholds(c, cx)
|| exceeds_length(f, c, cx)
|| exceeds_unsafe(c, cx)
|| exceeds_error_handling(f, c, cx)
}
fn exceeds_basic_thresholds(c: &ComplexityMetrics, cx: &ComplexityConfig) -> bool {
c.cognitive_complexity > cx.max_cognitive
|| c.cyclomatic_complexity > cx.max_cyclomatic
|| c.max_nesting > cx.max_nesting_depth
}
fn exceeds_length(f: &FunctionAnalysis, c: &ComplexityMetrics, cx: &ComplexityConfig) -> bool {
!f.is_test && c.function_lines > cx.max_function_lines
}
fn exceeds_unsafe(c: &ComplexityMetrics, cx: &ComplexityConfig) -> bool {
cx.detect_unsafe && c.unsafe_blocks > 0
}
fn exceeds_error_handling(
f: &FunctionAnalysis,
c: &ComplexityMetrics,
cx: &ComplexityConfig,
) -> bool {
if !cx.detect_error_handling || f.is_test {
return false;
}
let expect_threshold = if cx.allow_expect { 0 } else { 1 };
c.unwrap_count + c.panic_count + c.todo_count + c.expect_count.min(expect_threshold) > 0
}