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/style | |
| 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/style')
| -rw-r--r-- | crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs | 53 |
1 files changed, 21 insertions, 32 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs b/crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs index 72579fc..e91f432 100644 --- a/crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs +++ b/crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs @@ -336,7 +336,7 @@ impl SymfonyStyle { let mut r#type = r#type.map(|t| t.to_string()); let mut line_indentation = String::new(); if let Some(t) = &r#type { - let formatted = shirabe_php_shim::sprintf("[%s] ", &[PhpMixed::String(t.clone())]); + let formatted = format!("[{}] ", PhpMixed::String(t.clone())); indent_length = shirabe_php_shim::strlen(&formatted); line_indentation = shirabe_php_shim::str_repeat(" ", indent_length as usize); r#type = Some(formatted); @@ -409,12 +409,10 @@ impl SymfonyStyle { )); if let Some(style) = style { - *line = shirabe_php_shim::sprintf( - "<%s>%s</>", - &[ - PhpMixed::String(style.to_string()), - PhpMixed::String(line.clone()), - ], + *line = format!( + "<{}>{}</>", + PhpMixed::String(style.to_string()), + PhpMixed::String(line.clone()), ); } } @@ -505,21 +503,19 @@ impl StyleInterface for SymfonyStyle { self.auto_prepend_block(); self.writeln( PhpMixed::List(vec![ - Box::new(PhpMixed::String(shirabe_php_shim::sprintf( - "<comment>%s</>", - &[PhpMixed::String( - OutputFormatter::escape_trailing_backslash(message), - )], + Box::new(PhpMixed::String(format!( + "<comment>{}</>", + PhpMixed::String(OutputFormatter::escape_trailing_backslash(message),), ))), - Box::new(PhpMixed::String(shirabe_php_shim::sprintf( - "<comment>%s</>", - &[PhpMixed::String(shirabe_php_shim::str_repeat( + Box::new(PhpMixed::String(format!( + "<comment>{}</>", + PhpMixed::String(shirabe_php_shim::str_repeat( "=", Helper::width(&Helper::remove_decoration( &mut *self.get_formatter().borrow_mut(), message, )) as usize, - ))], + )), ))), ]), OUTPUT_NORMAL, @@ -532,21 +528,19 @@ impl StyleInterface for SymfonyStyle { self.auto_prepend_block(); self.writeln( PhpMixed::List(vec![ - Box::new(PhpMixed::String(shirabe_php_shim::sprintf( - "<comment>%s</>", - &[PhpMixed::String( - OutputFormatter::escape_trailing_backslash(message), - )], + Box::new(PhpMixed::String(format!( + "<comment>{}</>", + PhpMixed::String(OutputFormatter::escape_trailing_backslash(message),), ))), - Box::new(PhpMixed::String(shirabe_php_shim::sprintf( - "<comment>%s</>", - &[PhpMixed::String(shirabe_php_shim::str_repeat( + Box::new(PhpMixed::String(format!( + "<comment>{}</>", + PhpMixed::String(shirabe_php_shim::str_repeat( "-", Helper::width(&Helper::remove_decoration( &mut *self.get_formatter().borrow_mut(), message, )) as usize, - ))], + )), ))), ]), OUTPUT_NORMAL, @@ -558,9 +552,7 @@ impl StyleInterface for SymfonyStyle { fn listing(&mut self, elements: Vec<PhpMixed>) { self.auto_prepend_text(); let elements: Vec<PhpMixed> = shirabe_php_shim::array_map( - |element: &PhpMixed| { - PhpMixed::String(shirabe_php_shim::sprintf(" * %s", &[element.clone()])) - }, + |element: &PhpMixed| PhpMixed::String(format!(" * {}", element.clone())), &elements, ); @@ -582,10 +574,7 @@ impl StyleInterface for SymfonyStyle { vec![message] }; for message in messages { - self.writeln( - PhpMixed::String(shirabe_php_shim::sprintf(" %s", &[message])), - OUTPUT_NORMAL, - ); + self.writeln(PhpMixed::String(format!(" {}", message)), OUTPUT_NORMAL); } } |
