From efe5bdb1987411a473d4af15451a376d20928245 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 12 Jun 2026 03:19:34 +0900 Subject: refactor(php-shim): replace literal sprintf calls with format! Convert every sprintf() call with a compile-time literal format string to format!, implementing Display for PhpMixed (delegating to php_to_string) so PhpMixed values render with PHP string semantics through {}. Also merge the format!-wrapped and conditional-literal dynamic sites into single format! calls. Genuinely runtime format strings (table styles, configurable error messages, command synopsis, progress-bar modifiers, regex-built messages) still go through sprintf. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../src/class_map_generator.rs | 2 +- .../src/php_file_parser.rs | 23 +++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'crates/shirabe-class-map-generator/src') diff --git a/crates/shirabe-class-map-generator/src/class_map_generator.rs b/crates/shirabe-class-map-generator/src/class_map_generator.rs index f33c93c..391bee9 100644 --- a/crates/shirabe-class-map-generator/src/class_map_generator.rs +++ b/crates/shirabe-class-map-generator/src/class_map_generator.rs @@ -29,7 +29,7 @@ impl ClassMapGenerator { .map(|w| preg_quote(w, None)) .collect(); let stream_wrappers_regex = - sprintf("{^(?:%s)://}", &[PhpMixed::String(implode("|", &wrappers))]); + format!("{{^(?:{})://}}", PhpMixed::String(implode("|", &wrappers))); ClassMapGenerator { extensions, diff --git a/crates/shirabe-class-map-generator/src/php_file_parser.rs b/crates/shirabe-class-map-generator/src/php_file_parser.rs index d196f8b..84fb418 100644 --- a/crates/shirabe-class-map-generator/src/php_file_parser.rs +++ b/crates/shirabe-class-map-generator/src/php_file_parser.rs @@ -27,24 +27,29 @@ impl PhpFileParser { // Use @ here instead of Silencer to actively suppress 'unhelpful' output let contents = php_strip_whitespace(path); if contents.is_empty() { - let message: &str; + let message: String; if !file_exists(path) { - message = "File at \"%s\" does not exist, check your classmap definitions"; + message = format!( + "File at \"{}\" does not exist, check your classmap definitions", + path + ); } else if !Self::is_readable(path) { - message = "File at \"%s\" is not readable, check its permissions"; + message = format!( + "File at \"{}\" is not readable, check its permissions", + path + ); } else if trim(file_get_contents(path).unwrap_or_default().as_str(), None).is_empty() { // The input file was really empty and thus contains no classes return Ok(vec![]); } else { - message = - "File at \"%s\" could not be parsed as PHP, it may be binary or corrupted"; + message = format!( + "File at \"{}\" could not be parsed as PHP, it may be binary or corrupted", + path + ); } let error = error_get_last(); - let mut message = sprintf( - message, - &[shirabe_php_shim::PhpMixed::String(path.to_string())], - ); + let mut message = message; if let Some(error) = error && let Some(err_msg) = error.get("message") { -- cgit v1.3.1