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) --- .../console/helper/debug_formatter_helper.rs | 86 +++++++++------------- 1 file changed, 36 insertions(+), 50 deletions(-) (limited to 'crates/shirabe-external-packages/src/symfony/console/helper/debug_formatter_helper.rs') diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/debug_formatter_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/debug_formatter_helper.rs index 26ad169..170c557 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/debug_formatter_helper.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/debug_formatter_helper.rs @@ -51,13 +51,11 @@ impl DebugFormatterHelper { }, ); - shirabe_php_shim::sprintf( - "%s %s %s\n", - &[ - shirabe_php_shim::PhpMixed::String(self.get_border(id)), - shirabe_php_shim::PhpMixed::String(prefix.to_string()), - shirabe_php_shim::PhpMixed::String(message.to_string()), - ], + format!( + "{} {} {}\n", + shirabe_php_shim::PhpMixed::String(self.get_border(id)), + shirabe_php_shim::PhpMixed::String(prefix.to_string()), + shirabe_php_shim::PhpMixed::String(message.to_string()), ) } @@ -78,24 +76,20 @@ impl DebugFormatterHelper { self.started.get_mut(id).unwrap().out = false; } if !self.started[id].err { - message.push_str(&shirabe_php_shim::sprintf( - "%s %s ", - &[ - shirabe_php_shim::PhpMixed::String(self.get_border(id)), - shirabe_php_shim::PhpMixed::String(error_prefix.to_string()), - ], + message.push_str(&format!( + "{} {} ", + shirabe_php_shim::PhpMixed::String(self.get_border(id)), + shirabe_php_shim::PhpMixed::String(error_prefix.to_string()), )); self.started.get_mut(id).unwrap().err = true; } message.push_str(&shirabe_php_shim::str_replace( "\n", - &shirabe_php_shim::sprintf( - "\n%s %s ", - &[ - shirabe_php_shim::PhpMixed::String(self.get_border(id)), - shirabe_php_shim::PhpMixed::String(error_prefix.to_string()), - ], + &format!( + "\n{} {} ", + shirabe_php_shim::PhpMixed::String(self.get_border(id)), + shirabe_php_shim::PhpMixed::String(error_prefix.to_string()), ), buffer, )); @@ -105,24 +99,20 @@ impl DebugFormatterHelper { self.started.get_mut(id).unwrap().err = false; } if !self.started[id].out { - message.push_str(&shirabe_php_shim::sprintf( - "%s %s ", - &[ - shirabe_php_shim::PhpMixed::String(self.get_border(id)), - shirabe_php_shim::PhpMixed::String(prefix.to_string()), - ], + message.push_str(&format!( + "{} {} ", + shirabe_php_shim::PhpMixed::String(self.get_border(id)), + shirabe_php_shim::PhpMixed::String(prefix.to_string()), )); self.started.get_mut(id).unwrap().out = true; } message.push_str(&shirabe_php_shim::str_replace( "\n", - &shirabe_php_shim::sprintf( - "\n%s %s ", - &[ - shirabe_php_shim::PhpMixed::String(self.get_border(id)), - shirabe_php_shim::PhpMixed::String(prefix.to_string()), - ], + &format!( + "\n{} {} ", + shirabe_php_shim::PhpMixed::String(self.get_border(id)), + shirabe_php_shim::PhpMixed::String(prefix.to_string()), ), buffer, )); @@ -140,25 +130,21 @@ impl DebugFormatterHelper { }; if successful { - return shirabe_php_shim::sprintf( - "%s%s %s %s\n", - &[ - shirabe_php_shim::PhpMixed::String(trailing_eol.to_string()), - shirabe_php_shim::PhpMixed::String(self.get_border(id)), - shirabe_php_shim::PhpMixed::String(prefix.to_string()), - shirabe_php_shim::PhpMixed::String(message.to_string()), - ], - ); - } - - let message = shirabe_php_shim::sprintf( - "%s%s %s %s\n", - &[ + return format!( + "{}{} {} {}\n", shirabe_php_shim::PhpMixed::String(trailing_eol.to_string()), shirabe_php_shim::PhpMixed::String(self.get_border(id)), shirabe_php_shim::PhpMixed::String(prefix.to_string()), shirabe_php_shim::PhpMixed::String(message.to_string()), - ], + ); + } + + let message = format!( + "{}{} {} {}\n", + shirabe_php_shim::PhpMixed::String(trailing_eol.to_string()), + shirabe_php_shim::PhpMixed::String(self.get_border(id)), + shirabe_php_shim::PhpMixed::String(prefix.to_string()), + shirabe_php_shim::PhpMixed::String(message.to_string()), ); if let Some(session) = self.started.get_mut(id) { @@ -170,11 +156,11 @@ impl DebugFormatterHelper { } fn get_border(&self, id: &str) -> String { - shirabe_php_shim::sprintf( - " ", - &[shirabe_php_shim::PhpMixed::String( + format!( + " ", + shirabe_php_shim::PhpMixed::String( COLORS[self.started[id].border as usize].to_string(), - )], + ), ) } } -- cgit v1.3.1