aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages/src/symfony/console/descriptor
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-12 03:19:34 +0900
committernsfisis <nsfisis@gmail.com>2026-06-12 03:19:34 +0900
commitefe5bdb1987411a473d4af15451a376d20928245 (patch)
tree54d3c9e7ab92cfc7d7ec3d90ca3f29e828d929c4 /crates/shirabe-external-packages/src/symfony/console/descriptor
parent981cae63d9777b877aa9f96907c7995ec020fbf9 (diff)
downloadphp-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/descriptor')
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/descriptor/markdown_descriptor.rs36
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs138
2 files changed, 79 insertions, 95 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/markdown_descriptor.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/markdown_descriptor.rs
index 5ec5c95..1fec085 100644
--- a/crates/shirabe-external-packages/src/symfony/console/descriptor/markdown_descriptor.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/markdown_descriptor.rs
@@ -256,20 +256,18 @@ impl MarkdownDescriptor {
&command_names
.iter()
.map(|command_name| {
- Ok(shirabe_php_shim::sprintf(
- "* [`%s`](#%s)",
- &[
- PhpMixed::String(command_name.clone()),
- PhpMixed::String(shirabe_php_shim::str_replace(
- ":",
- "",
- &description
- .get_command(command_name)?
- .borrow()
- .get_name()
- .unwrap_or_default(),
- )),
- ],
+ Ok(format!(
+ "* [`{}`](#{})",
+ PhpMixed::String(command_name.clone()),
+ PhpMixed::String(shirabe_php_shim::str_replace(
+ ":",
+ "",
+ &description
+ .get_command(command_name)?
+ .borrow()
+ .get_name()
+ .unwrap_or_default(),
+ )),
))
})
.collect::<anyhow::Result<Vec<String>>>()?
@@ -294,12 +292,10 @@ impl MarkdownDescriptor {
fn get_application_title(&self, application: &Application) -> String {
if "UNKNOWN" != application.get_name() {
if "UNKNOWN" != application.get_version() {
- return shirabe_php_shim::sprintf(
- "%s %s",
- &[
- PhpMixed::String(application.get_name()),
- PhpMixed::String(application.get_version()),
- ],
+ return format!(
+ "{} {}",
+ PhpMixed::String(application.get_name()),
+ PhpMixed::String(application.get_version()),
);
}
diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs
index 963fcd8..b5faaae 100644
--- a/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs
@@ -56,22 +56,20 @@ impl TextDescriptor {
let spacing_width = total_width - shirabe_php_shim::strlen(argument.get_name());
self.write_text(
- &shirabe_php_shim::sprintf(
- " <info>%s</info> %s%s%s",
- &[
- PhpMixed::String(argument.get_name().to_string()),
- PhpMixed::String(shirabe_php_shim::str_repeat(" ", spacing_width as usize)),
- // + 4 = 2 spaces before <info>, 2 spaces after </info>
- PhpMixed::String(Preg::replace(
- "/\\s*[\\r\\n]\\s*/",
- &format!(
- "\n{}",
- shirabe_php_shim::str_repeat(" ", (total_width + 4) as usize)
- ),
- argument.get_description(),
- )?),
- PhpMixed::String(default),
- ],
+ &format!(
+ " <info>{}</info> {}{}{}",
+ PhpMixed::String(argument.get_name().to_string()),
+ PhpMixed::String(shirabe_php_shim::str_repeat(" ", spacing_width as usize)),
+ // + 4 = 2 spaces before <info>, 2 spaces after </info>
+ PhpMixed::String(Preg::replace(
+ "/\\s*[\\r\\n]\\s*/",
+ &format!(
+ "\n{}",
+ shirabe_php_shim::str_repeat(" ", (total_width + 4) as usize)
+ ),
+ argument.get_description(),
+ )?),
+ PhpMixed::String(default),
),
&options,
);
@@ -112,28 +110,23 @@ impl TextDescriptor {
let synopsis = format!(
"{}{}",
if option.get_shortcut().is_some() {
- shirabe_php_shim::sprintf(
- "-%s, ",
- &[PhpMixed::String(option.get_shortcut().unwrap().to_string())],
+ format!(
+ "-{}, ",
+ PhpMixed::String(option.get_shortcut().unwrap().to_string()),
)
} else {
" ".to_string()
},
if option.is_negatable() {
- shirabe_php_shim::sprintf(
- "--%1$s|--no-%1$s",
- &[
- PhpMixed::String(option.get_name().to_string()),
- PhpMixed::String(value.clone()),
- ],
+ format!(
+ "--{0}|--no-{0}",
+ PhpMixed::String(option.get_name().to_string()),
)
} else {
- shirabe_php_shim::sprintf(
- "--%1$s%2$s",
- &[
- PhpMixed::String(option.get_name().to_string()),
- PhpMixed::String(value.clone()),
- ],
+ format!(
+ "--{0}{1}",
+ PhpMixed::String(option.get_name().to_string()),
+ PhpMixed::String(value.clone()),
)
}
);
@@ -141,27 +134,25 @@ impl TextDescriptor {
let spacing_width = total_width - Helper::width(&synopsis);
self.write_text(
- &shirabe_php_shim::sprintf(
- " <info>%s</info> %s%s%s%s",
- &[
- PhpMixed::String(synopsis),
- PhpMixed::String(shirabe_php_shim::str_repeat(" ", spacing_width as usize)),
- // + 4 = 2 spaces before <info>, 2 spaces after </info>
- PhpMixed::String(Preg::replace(
- "/\\s*[\\r\\n]\\s*/",
- &format!(
- "\n{}",
- shirabe_php_shim::str_repeat(" ", (total_width + 4) as usize)
- ),
- option.get_description(),
- )?),
- PhpMixed::String(default),
- PhpMixed::String(if option.is_array() {
- "<comment> (multiple values allowed)</comment>".to_string()
- } else {
- String::new()
- }),
- ],
+ &format!(
+ " <info>{}</info> {}{}{}{}",
+ PhpMixed::String(synopsis),
+ PhpMixed::String(shirabe_php_shim::str_repeat(" ", spacing_width as usize)),
+ // + 4 = 2 spaces before <info>, 2 spaces after </info>
+ PhpMixed::String(Preg::replace(
+ "/\\s*[\\r\\n]\\s*/",
+ &format!(
+ "\n{}",
+ shirabe_php_shim::str_repeat(" ", (total_width + 4) as usize)
+ ),
+ option.get_description(),
+ )?),
+ PhpMixed::String(default),
+ PhpMixed::String(if option.is_array() {
+ "<comment> (multiple values allowed)</comment>".to_string()
+ } else {
+ String::new()
+ }),
),
&options,
);
@@ -294,12 +285,11 @@ impl TextDescriptor {
for command in &command_list {
let command = command.borrow();
self.write_text(
- &shirabe_php_shim::sprintf(
- &format!("%-{}s %s", width),
- &[
- PhpMixed::String(command.get_name().unwrap_or_default()),
- PhpMixed::String(command.get_description()),
- ],
+ &format!(
+ "{:<w$} {}",
+ PhpMixed::String(command.get_name().unwrap_or_default()),
+ PhpMixed::String(command.get_description()),
+ w = width as usize,
),
&options,
);
@@ -361,9 +351,9 @@ impl TextDescriptor {
if let Some(ref described_namespace) = described_namespace {
self.write_text(
- &shirabe_php_shim::sprintf(
- "<comment>Available commands for the \"%s\" namespace:</comment>",
- &[PhpMixed::String(described_namespace.clone())],
+ &format!(
+ "<comment>Available commands for the \"{}\" namespace:</comment>",
+ PhpMixed::String(described_namespace.clone()),
),
&options,
);
@@ -412,20 +402,18 @@ impl TextDescriptor {
String::new()
};
self.write_text(
- &shirabe_php_shim::sprintf(
- " <info>%s</info>%s%s",
- &[
- PhpMixed::String(name.clone()),
- PhpMixed::String(shirabe_php_shim::str_repeat(
- " ",
- spacing_width as usize,
- )),
- PhpMixed::String(format!(
- "{}{}",
- command_aliases,
- command.get_description()
- )),
- ],
+ &format!(
+ " <info>{}</info>{}{}",
+ PhpMixed::String(name.clone()),
+ PhpMixed::String(shirabe_php_shim::str_repeat(
+ " ",
+ spacing_width as usize,
+ )),
+ PhpMixed::String(format!(
+ "{}{}",
+ command_aliases,
+ command.get_description()
+ )),
),
&options,
);