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/installer.rs | 55 +++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 30 deletions(-) (limited to 'crates/shirabe/src/installer.rs') diff --git a/crates/shirabe/src/installer.rs b/crates/shirabe/src/installer.rs index 3c68b90..86c9714 100644 --- a/crates/shirabe/src/installer.rs +++ b/crates/shirabe/src/installer.rs @@ -384,9 +384,10 @@ impl Installer { "No replacement was suggested".to_string() }; - self.io.write_error(&sprintf( - "Package %s is abandoned, you should avoid using it. %s.", - &[complete.get_pretty_name().into(), replacement.into()], + self.io.write_error(&format!( + "Package {} is abandoned, you should avoid using it. {}.", + complete.get_pretty_name(), + replacement, )); } @@ -461,13 +462,11 @@ impl Installer { } } if funding_count > 0 { - self.io.write_error(&sprintf( - "%d package%s you are using %s looking for funding.", - &[ - funding_count.into(), - (if 1 == funding_count { "" } else { "s" }).into(), - (if 1 == funding_count { "is" } else { "are" }).into(), - ], + self.io.write_error(&format!( + "{} package{} you are using {} looking for funding.", + funding_count, + (if 1 == funding_count { "" } else { "s" }), + (if 1 == funding_count { "is" } else { "are" }), )); self.io .write_error("Use the `composer fund` command to find out more!"); @@ -792,16 +791,14 @@ impl Installer { .as_bool() .unwrap_or(false) { - self.io.write_error(&sprintf( - "Lock file operations: %d install%s, %d update%s, %d removal%s", - &[ - (install_names.len() as i64).into(), - (if 1 == install_names.len() { "" } else { "s" }).into(), - (update_names.len() as i64).into(), - (if 1 == update_names.len() { "" } else { "s" }).into(), - (uninstalls.len() as i64).into(), - (if 1 == uninstalls.len() { "" } else { "s" }).into(), - ], + self.io.write_error(&format!( + "Lock file operations: {} install{}, {} update{}, {} removal{}", + (install_names.len() as i64), + (if 1 == install_names.len() { "" } else { "s" }), + (update_names.len() as i64), + (if 1 == update_names.len() { "" } else { "s" }), + (uninstalls.len() as i64), + (if 1 == uninstalls.len() { "" } else { "s" }), )); if !install_names.is_empty() { self.io.write_error3( @@ -1185,16 +1182,14 @@ impl Installer { if installs.is_empty() && updates.is_empty() && uninstalls.is_empty() { self.io.write_error("Nothing to install, update or remove"); } else { - self.io.write_error(&sprintf( - "Package operations: %d install%s, %d update%s, %d removal%s", - &[ - (installs.len() as i64).into(), - (if 1 == installs.len() { "" } else { "s" }).into(), - (updates.len() as i64).into(), - (if 1 == updates.len() { "" } else { "s" }).into(), - (uninstalls.len() as i64).into(), - (if 1 == uninstalls.len() { "" } else { "s" }).into(), - ], + self.io.write_error(&format!( + "Package operations: {} install{}, {} update{}, {} removal{}", + (installs.len() as i64), + (if 1 == installs.len() { "" } else { "s" }), + (updates.len() as i64), + (if 1 == updates.len() { "" } else { "s" }), + (uninstalls.len() as i64), + (if 1 == uninstalls.len() { "" } else { "s" }), )); if !installs.is_empty() { self.io.write_error3( -- cgit v1.3.1