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/require_command.rs | 62 ++++++++++++--------------- 1 file changed, 28 insertions(+), 34 deletions(-) (limited to 'crates/shirabe/src/command/require_command.rs') diff --git a/crates/shirabe/src/command/require_command.rs b/crates/shirabe/src/command/require_command.rs index dd91524..9e47a02 100644 --- a/crates/shirabe/src/command/require_command.rs +++ b/crates/shirabe/src/command/require_command.rs @@ -446,9 +446,9 @@ impl RequireCommand { let version_parser = VersionParser::new(); for (package, constraint) in &requirements { if strtolower(package) == composer.get_package().get_name() { - let msg = sprintf( - "Root package '%s' cannot require itself in its composer.json", - &[PhpMixed::String(package.clone())], + let msg = format!( + "Root package '{}' cannot require itself in its composer.json", + PhpMixed::String(package.clone()), ); self.get_io().write_error3(&msg, true, io_interface::NORMAL); @@ -464,48 +464,46 @@ impl RequireCommand { self.get_inconsistent_require_keys(&requirements, require_key); if (inconsistent_require_keys.len() as i64) > 0 { for package in &inconsistent_require_keys { - let warn_msg = sprintf( - "%s is currently present in the %s key and you ran the command %s the --dev flag, which will move it to the %s key.", - &[ - PhpMixed::String(package.clone()), - PhpMixed::String(remove_key.to_string()), - PhpMixed::String( - if input.borrow().get_option("dev")?.as_bool().unwrap_or(false) { - "with" - } else { - "without" - } - .to_string(), - ), - PhpMixed::String(require_key.to_string()), - ], + let warn_msg = format!( + "{} is currently present in the {} key and you ran the command {} the --dev flag, which will move it to the {} key.", + PhpMixed::String(package.clone()), + PhpMixed::String(remove_key.to_string()), + PhpMixed::String( + if input.borrow().get_option("dev")?.as_bool().unwrap_or(false) { + "with" + } else { + "without" + } + .to_string(), + ), + PhpMixed::String(require_key.to_string()), ); self.get_io().warning(&warn_msg, &[]); } if self.get_io().is_interactive() { - let q1 = sprintf( - "Do you want to move %s? [no]? ", - &[PhpMixed::String( + let q1 = format!( + "Do you want to move {}? [no]? ", + PhpMixed::String( if (inconsistent_require_keys.len() as i64) > 1 { "these requirements" } else { "this requirement" } .to_string(), - )], + ), ); if !self.get_io().ask_confirmation(q1, false) { - let q2 = sprintf( - "Do you want to re-run the command %s --dev? [yes]? ", - &[PhpMixed::String( + let q2 = format!( + "Do you want to re-run the command {} --dev? [yes]? ", + PhpMixed::String( if input.borrow().get_option("dev")?.as_bool().unwrap_or(false) { "without" } else { "with" } .to_string(), - )], + ), ); if !self.get_io().ask_confirmation(q2, true) { return Ok(0); @@ -1086,14 +1084,10 @@ impl RequireCommand { ); } self.get_io().write_error3( - &sprintf( - "Using version %s for %s", - &[ - PhpMixed::String( - requirements.get(package_name).cloned().unwrap_or_default(), - ), - PhpMixed::String(package_name.clone()), - ], + &format!( + "Using version {} for {}", + PhpMixed::String(requirements.get(package_name).cloned().unwrap_or_default(),), + PhpMixed::String(package_name.clone()), ), true, io_interface::NORMAL, -- cgit v1.3.1