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)
| 408 | /// `NamedTempFile` whose destructor automatically removes the file on |
| 409 | /// drop — the caller must keep it alive until after PHPStan finishes. |
| 410 | fn 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. |
| 427 | struct CommandOutput { |