diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-12 03:19:34 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-12 03:19:34 +0900 |
| commit | efe5bdb1987411a473d4af15451a376d20928245 (patch) | |
| tree | 54d3c9e7ab92cfc7d7ec3d90ca3f29e828d929c4 /crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs | |
| parent | 981cae63d9777b877aa9f96907c7995ec020fbf9 (diff) | |
| download | php-shirabe-efe5bdb1987411a473d4af15451a376d20928245.tar.gz php-shirabe-efe5bdb1987411a473d4af15451a376d20928245.tar.zst php-shirabe-efe5bdb1987411a473d4af15451a376d20928245.zip | |
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) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs')
| -rw-r--r-- | crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs | 80 |
1 files changed, 36 insertions, 44 deletions
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(" <info>%s</info>:", &[PhpMixed::String(text)]); + text = format!(" <info>{}</info>:", PhpMixed::String(text)); } else if question .as_any() .downcast_ref::<ConfirmationQuestion>() .is_some() { - text = shirabe_php_shim::sprintf( - " <info>%s (yes/no)</info> [<comment>%s</comment>]:", - &[ - PhpMixed::String(text), - PhpMixed::String( - if shirabe_php_shim::boolval(&default) { - "yes" - } else { - "no" - } - .to_string(), - ), - ], + text = format!( + " <info>{} (yes/no)</info> [<comment>{}</comment>]:", + 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( - " <info>%s</info> [<comment>%s</comment>]:", - &[ - PhpMixed::String(text), - PhpMixed::String(OutputFormatter::escape(&resolved.join(", ")).unwrap()), - ], + text = format!( + " <info>{}</info> [<comment>{}</comment>]:", + PhpMixed::String(text), + PhpMixed::String(OutputFormatter::escape(&resolved.join(", ")).unwrap()), ); } else if let Some(choice_question) = question.as_any().downcast_ref::<ChoiceQuestion>() { let choices = choice_question.get_choices(); - text = shirabe_php_shim::sprintf( - " <info>%s</info> [<comment>%s</comment>]:", - &[ - 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!( + " <info>{}</info> [<comment>{}</comment>]:", + 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( - " <info>%s</info> [<comment>%s</comment>]:", - &[ - PhpMixed::String(text), - PhpMixed::String(OutputFormatter::escape(&default.to_string()).unwrap()), - ], + text = format!( + " <info>{}</info> [<comment>{}</comment>]:", + PhpMixed::String(text), + PhpMixed::String(OutputFormatter::escape(&default.to_string()).unwrap()), ); } |
