1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#![cfg_attr(coverage_nightly, coverage(off))]
//! Comprehensive analysis handler implementation
//!
//! This module implements the comprehensive analysis command that aggregates
//! results from multiple analyzers into a unified report.
use crate::cli::ComprehensiveOutputFormat;
use crate::services::defect_report_service::{DefectReportService, ReportFormat};
use anyhow::{Context, Result};
use serde_json;
use std::path::{Path, PathBuf};
use std::time::Instant;
use tracing::info;
/// Configuration for comprehensive analysis
pub struct ComprehensiveConfig {
pub project_path: PathBuf,
pub file: Option<PathBuf>,
pub files: Vec<PathBuf>,
pub format: ComprehensiveOutputFormat,
pub include_duplicates: bool,
pub include_dead_code: bool,
pub include_defects: bool,
pub include_complexity: bool,
pub include_tdg: bool,
pub confidence_threshold: f32,
pub min_lines: usize,
pub include: Option<String>,
pub exclude: Option<String>,
pub output: Option<PathBuf>,
pub perf: bool,
pub executive_summary: bool,
}
/// Handle comprehensive analysis command
///
/// This function performs a comprehensive multi-dimensional analysis of a project or single file,
/// combining results from multiple analyzers including complexity, technical debt, defects,
/// dead code, and duplicates.
///
/// # Arguments
///
/// * `project_path` - The project directory to analyze
/// * `file` - Optional single file to analyze (overrides project path)
/// * `format` - Output format for the report
/// * `include_duplicates` - Whether to include duplicate detection
/// * `include_dead_code` - Whether to include dead code analysis
/// * `include_defects` - Whether to include defect prediction
/// * `include_complexity` - Whether to include complexity metrics
/// * `include_tdg` - Whether to include Technical Debt Gradient
/// * `confidence_threshold` - Minimum confidence threshold for predictions (0.0-1.0)
/// * `min_lines` - Minimum lines of code for analysis
/// * `include` - Optional file pattern to include
/// * `exclude` - Optional file pattern to exclude
/// * `output` - Optional output file path
/// * `perf` - Whether to show performance metrics
/// * `executive_summary` - Whether to include executive summary
///
/// # Examples
///
/// ```no_run
/// # use std::path::PathBuf;
/// # use anyhow::Result;
/// # use pmat::cli::ComprehensiveOutputFormat;
/// # async fn example() -> Result<()> {
/// use pmat::cli::handlers::comprehensive_handler::handle_analyze_comprehensive;
///
/// // Analyze entire project
/// handle_analyze_comprehensive(
/// PathBuf::from("."),
/// None,
/// vec![], // files
/// ComprehensiveOutputFormat::Summary,
/// true, // include_duplicates
/// true, // include_dead_code
/// true, // include_defects
/// true, // include_complexity
/// true, // include_tdg
/// 0.5, // confidence_threshold
/// 10, // min_lines
/// None, // include pattern
/// None, // exclude pattern
/// None, // output file
/// false, // perf
/// false, // executive_summary
/// ).await?;
///
/// // Analyze single file
/// handle_analyze_comprehensive(
/// PathBuf::from("."),
/// Some(PathBuf::from("src/main.rs")),
/// vec![], // files
/// ComprehensiveOutputFormat::Detailed,
/// true, // include_duplicates
/// true, // include_dead_code
/// true, // include_defects
/// true, // include_complexity
/// true, // include_tdg
/// 0.7, // confidence_threshold
/// 10, // min_lines
/// None, // include pattern
/// None, // exclude pattern
/// Some(PathBuf::from("report.md")), // output file
/// true, // perf
/// true, // executive_summary
/// ).await?;
/// # Ok(())
/// # }
/// ```
#[allow(clippy::too_many_arguments)]
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "path_exists")]
pub async fn handle_analyze_comprehensive(
project_path: PathBuf,
file: Option<PathBuf>,
files: Vec<PathBuf>,
format: ComprehensiveOutputFormat,
include_duplicates: bool,
include_dead_code: bool,
include_defects: bool,
include_complexity: bool,
include_tdg: bool,
confidence_threshold: f32,
min_lines: usize,
include: Option<String>,
exclude: Option<String>,
output: Option<PathBuf>,
perf: bool,
executive_summary: bool,
) -> Result<()> {
let config = ComprehensiveConfig {
project_path,
file,
files,
format,
include_duplicates,
include_dead_code,
include_defects,
include_complexity,
include_tdg,
confidence_threshold,
min_lines,
include,
exclude,
output,
perf,
executive_summary,
};
handle_analyze_comprehensive_with_config(config).await
}
include!("comprehensive_handler_analysis.rs");
include!("comprehensive_handler_tests.rs");