MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / run_php_cs_fixer

Function run_php_cs_fixer

src/formatting.rs:317–358  ·  view source on GitHub ↗

Run php-cs-fixer on a sibling temp file and return the formatted content. Command: ` fix --using-cache=no --quiet --no-interaction ` php-cs-fixer modifies the file in-place. Exit code 0 means success.

(
    tool_path: &Path,
    content: &str,
    file_path: &Path,
    timeout: Duration,
)

Source from the content-addressed store, hash-verified

315///
316/// php-cs-fixer modifies the file in-place. Exit code 0 means success.
317fn run_php_cs_fixer(
318 tool_path: &Path,
319 content: &str,
320 file_path: &Path,
321 timeout: Duration,
322) -> Result<String, String> {
323 let temp = write_sibling_temp_file(file_path, content)?;
324
325 let result = run_command_with_timeout(
326 Command::new(tool_path)
327 .arg("fix")
328 .arg("--using-cache=no")
329 .arg("--quiet")
330 .arg("--no-interaction")
331 .arg(temp.path()),
332 timeout,
333 );
334
335 let formatted = std::fs::read_to_string(temp.path())
336 .map_err(|e| format!("Failed to read formatted output: {}", e))?;
337
338 match result {
339 Ok(status) => {
340 // php-cs-fixer exit codes (bitmask):
341 // 0 = OK
342 // 1 = general error / PHP version issue
343 // 16 = configuration error
344 // 32 = fixer configuration error
345 // 64 = exception
346 if status.code == 0 {
347 Ok(formatted)
348 } else {
349 Err(format!(
350 "php-cs-fixer exited with code {} (stderr: {})",
351 status.code,
352 status.stderr.trim()
353 ))
354 }
355 }
356 Err(e) => Err(e),
357 }
358}
359
360/// Run Pint via stdin and return the formatted content.
361///

Callers 1

run_toolFunction · 0.85

Calls 2

write_sibling_temp_fileFunction · 0.85
run_command_with_timeoutFunction · 0.70

Tested by

no test coverage detected