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/symfony_question_helper.rs | 80 ++++++++++------------ 1 file changed, 36 insertions(+), 44 deletions(-) (limited to 'crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs') diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs index dd14513..9b388d9 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs @@ -32,33 +32,31 @@ impl SymfonyQuestionHelper { let default = question.get_default(); if question.is_multiline() { - text += &shirabe_php_shim::sprintf( - " (press %s to continue)", - &[PhpMixed::String(self.get_eof_shortcut())], + text += &format!( + " (press {} to continue)", + PhpMixed::String(self.get_eof_shortcut()), ); } // switch (true) if matches!(default, PhpMixed::Null) { - text = shirabe_php_shim::sprintf(" %s:", &[PhpMixed::String(text)]); + text = format!(" {}:", PhpMixed::String(text)); } else if question .as_any() .downcast_ref::() .is_some() { - text = shirabe_php_shim::sprintf( - " %s (yes/no) [%s]:", - &[ - PhpMixed::String(text), - PhpMixed::String( - if shirabe_php_shim::boolval(&default) { - "yes" - } else { - "no" - } - .to_string(), - ), - ], + text = format!( + " {} (yes/no) [{}]:", + PhpMixed::String(text), + PhpMixed::String( + if shirabe_php_shim::boolval(&default) { + "yes" + } else { + "no" + } + .to_string(), + ), ); } else if let Some(choice_question) = question .as_any() @@ -78,38 +76,32 @@ impl SymfonyQuestionHelper { }) .collect(); - text = shirabe_php_shim::sprintf( - " %s [%s]:", - &[ - PhpMixed::String(text), - PhpMixed::String(OutputFormatter::escape(&resolved.join(", ")).unwrap()), - ], + text = format!( + " {} [{}]:", + PhpMixed::String(text), + PhpMixed::String(OutputFormatter::escape(&resolved.join(", ")).unwrap()), ); } else if let Some(choice_question) = question.as_any().downcast_ref::() { let choices = choice_question.get_choices(); - text = shirabe_php_shim::sprintf( - " %s [%s]:", - &[ - PhpMixed::String(text), - PhpMixed::String( - OutputFormatter::escape( - &choices - .get(&default.to_string()) - .map(|v| (**v).clone()) - .unwrap_or(default.clone()) - .to_string(), - ) - .unwrap(), - ), - ], + text = format!( + " {} [{}]:", + PhpMixed::String(text), + PhpMixed::String( + OutputFormatter::escape( + &choices + .get(&default.to_string()) + .map(|v| (**v).clone()) + .unwrap_or(default.clone()) + .to_string(), + ) + .unwrap(), + ), ); } else { - text = shirabe_php_shim::sprintf( - " %s [%s]:", - &[ - PhpMixed::String(text), - PhpMixed::String(OutputFormatter::escape(&default.to_string()).unwrap()), - ], + text = format!( + " {} [{}]:", + PhpMixed::String(text), + PhpMixed::String(OutputFormatter::escape(&default.to_string()).unwrap()), ); } -- cgit v1.3.1