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

Function write_temp_file

src/phpstan.rs:410–424  ·  view source on GitHub ↗

Write content to a temporary file for PHPStan's `--tmp-file` flag. Uses the system temp directory via `tempfile::Builder`. The `.php` extension is preserved because PHPStan requires it. Returns a `NamedTempFile` whose destructor automatically removes the file on drop — the caller must keep it alive until after PHPStan finishes.

(_original: &Path, content: &str)

Source from the content-addressed store, hash-verified

408/// `NamedTempFile` whose destructor automatically removes the file on
409/// drop — the caller must keep it alive until after PHPStan finishes.
410fn write_temp_file(_original: &Path, content: &str) -> Result<NamedTempFile, String> {
411 let mut temp = tempfile::Builder::new()
412 .prefix("phpantom-")
413 .suffix(".php")
414 .tempfile()
415 .map_err(|e| format!("Failed to create temp file: {}", e))?;
416
417 temp.write_all(content.as_bytes())
418 .map_err(|e| format!("Failed to write temp file: {}", e))?;
419
420 temp.flush()
421 .map_err(|e| format!("Failed to flush temp file: {}", e))?;
422
423 Ok(temp)
424}
425
426/// Result of running an external command.
427struct CommandOutput {

Callers 2

run_phpstanFunction · 0.85

Calls 1

prefixMethod · 0.80

Tested by 1