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) --- crates/shirabe/src/command/init_command.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'crates/shirabe/src/command/init_command.rs') diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs index aea9faf..205494c 100644 --- a/crates/shirabe/src/command/init_command.rs +++ b/crates/shirabe/src/command/init_command.rs @@ -906,9 +906,9 @@ impl InitCommand { if !Preg::is_match(r"{^[^/][A-Za-z0-9\-_/]+/$}", &value_or_default).unwrap_or(false) { return Err(InvalidArgumentException { - message: sprintf( - "The src folder name \"%s\" is invalid. Please add a relative path with tailing forward slash. [A-Za-z0-9_-/]+/", - &[PhpMixed::String(value_or_default.clone())], + message: format!( + "The src folder name \"{}\" is invalid. Please add a relative path with tailing forward slash. [A-Za-z0-9_-/]+/", + PhpMixed::String(value_or_default.clone()), ), code: 0, } @@ -1057,9 +1057,9 @@ impl InitCommand { return false; } - let pattern = sprintf( - "{^/?%s(/\\*?)?$}", - &[PhpMixed::String(preg_quote(vendor, None))], + let pattern = format!( + "{{^/?{}(/\\*?)?$}}", + PhpMixed::String(preg_quote(vendor, None)), ); let lines = file(ignore_file, FILE_IGNORE_NEW_LINES).unwrap_or_default(); @@ -1240,9 +1240,10 @@ impl InitCommand { } if let (Some(name), Some(email)) = (author_name, author_email) { - return Some(sprintf( - "%s <%s>", - &[PhpMixed::String(name), PhpMixed::String(email)], + return Some(format!( + "{} <{}>", + PhpMixed::String(name), + PhpMixed::String(email), )); } -- cgit v1.3.1