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/symfony/console/helper/formatter_helper.rs | 35 ++++++++++------------ 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'crates/shirabe-external-packages/src/symfony/console/helper/formatter_helper.rs') diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/formatter_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/formatter_helper.rs index ef33f93..5b26b75 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/formatter_helper.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/formatter_helper.rs @@ -14,14 +14,12 @@ pub struct FormatterHelper { impl FormatterHelper { /// Formats a message within a section. pub fn format_section(&self, section: &str, message: &str, style: &str) -> String { - shirabe_php_shim::sprintf( - "<%s>[%s] %s", - &[ - shirabe_php_shim::PhpMixed::String(style.to_string()), - shirabe_php_shim::PhpMixed::String(section.to_string()), - shirabe_php_shim::PhpMixed::String(style.to_string()), - shirabe_php_shim::PhpMixed::String(message.to_string()), - ], + format!( + "<{}>[{}] {}", + shirabe_php_shim::PhpMixed::String(style.to_string()), + shirabe_php_shim::PhpMixed::String(section.to_string()), + shirabe_php_shim::PhpMixed::String(style.to_string()), + shirabe_php_shim::PhpMixed::String(message.to_string()), ) } @@ -38,10 +36,11 @@ impl FormatterHelper { let mut lines: Vec = Vec::new(); for message in &messages { let message = OutputFormatter::escape(message).unwrap(); - lines.push(shirabe_php_shim::sprintf( - if large { " %s " } else { " %s " }, - &[shirabe_php_shim::PhpMixed::String(message.clone())], - )); + lines.push(if large { + format!(" {} ", message) + } else { + format!(" {} ", message) + }); len = std::cmp::max(Helper::width(&message) + (if large { 4 } else { 2 }), len); } @@ -65,13 +64,11 @@ impl FormatterHelper { let mut i = 0; while i < messages.len() { - messages[i] = shirabe_php_shim::sprintf( - "<%s>%s", - &[ - shirabe_php_shim::PhpMixed::String(style.to_string()), - shirabe_php_shim::PhpMixed::String(messages[i].clone()), - shirabe_php_shim::PhpMixed::String(style.to_string()), - ], + messages[i] = format!( + "<{}>{}", + shirabe_php_shim::PhpMixed::String(style.to_string()), + shirabe_php_shim::PhpMixed::String(messages[i].clone()), + shirabe_php_shim::PhpMixed::String(style.to_string()), ); i += 1; } -- cgit v1.3.1