Run phpcbf on a sibling temp file and return the formatted content. Command: ` --no-colors -q ` phpcbf modifies the file in-place.
(
tool_path: &Path,
content: &str,
file_path: &Path,
timeout: Duration,
)
| 433 | /// |
| 434 | /// phpcbf modifies the file in-place. |
| 435 | fn run_phpcbf( |
| 436 | tool_path: &Path, |
| 437 | content: &str, |
| 438 | file_path: &Path, |
| 439 | timeout: Duration, |
| 440 | ) -> Result<String, String> { |
| 441 | let temp = write_sibling_temp_file(file_path, content)?; |
| 442 | |
| 443 | let result = run_command_with_timeout( |
| 444 | Command::new(tool_path) |
| 445 | .arg("--no-colors") |
| 446 | .arg("-q") |
| 447 | .arg(temp.path()), |
| 448 | timeout, |
| 449 | ); |
| 450 | |
| 451 | let formatted = std::fs::read_to_string(temp.path()) |
| 452 | .map_err(|e| format!("Failed to read formatted output: {}", e))?; |
| 453 | |
| 454 | match result { |
| 455 | Ok(status) => { |
| 456 | // phpcbf exit codes: |
| 457 | // 0 = no fixes needed |
| 458 | // 1 = fixes applied (success) |
| 459 | // 2 = could not fix all errors |
| 460 | // 3+ = operational error |
| 461 | match status.code { |
| 462 | 0 | 1 => Ok(formatted), |
| 463 | _ => Err(format!( |
| 464 | "phpcbf exited with code {} (stderr: {})", |
| 465 | status.code, |
| 466 | status.stderr.trim() |
| 467 | )), |
| 468 | } |
| 469 | } |
| 470 | Err(e) => Err(e), |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | // ── Helpers ───────────────────────────────────────────────────────── |
| 475 |
no test coverage detected