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/application.rs | 78 ++++++------ .../src/symfony/console/color.rs | 40 +++--- .../src/symfony/console/cursor.rs | 45 +++---- .../console/descriptor/markdown_descriptor.rs | 36 +++--- .../symfony/console/descriptor/text_descriptor.rs | 138 ++++++++++----------- .../symfony/console/formatter/output_formatter.rs | 6 +- .../console/helper/debug_formatter_helper.rs | 86 ++++++------- .../symfony/console/helper/descriptor_helper.rs | 6 +- .../src/symfony/console/helper/formatter_helper.rs | 35 +++--- .../src/symfony/console/helper/helper.rs | 21 +--- .../src/symfony/console/helper/helper_set.rs | 6 +- .../src/symfony/console/helper/process_helper.rs | 24 ++-- .../src/symfony/console/helper/progress_bar.rs | 4 +- .../src/symfony/console/helper/question_helper.rs | 7 +- .../console/helper/symfony_question_helper.rs | 80 ++++++------ .../src/symfony/console/helper/table.rs | 20 +-- .../src/symfony/console/helper/table_cell.rs | 6 +- .../src/symfony/console/helper/table_cell_style.rs | 14 +-- .../src/symfony/console/input/argv_input.rs | 67 +++++----- .../src/symfony/console/input/array_input.rs | 23 ++-- .../src/symfony/console/input/input.rs | 33 +++-- .../src/symfony/console/input/input_definition.rs | 122 ++++++++---------- .../src/symfony/console/input/string_input.rs | 10 +- .../console/output/console_section_output.rs | 6 +- .../console/output/trimmed_buffer_output.rs | 16 ++- .../symfony/console/question/choice_question.rs | 8 +- .../src/symfony/console/style/symfony_style.rs | 53 ++++---- 27 files changed, 425 insertions(+), 565 deletions(-) (limited to 'crates/shirabe-external-packages') diff --git a/crates/shirabe-external-packages/src/symfony/console/application.rs b/crates/shirabe-external-packages/src/symfony/console/application.rs index e15b68d..8838eaf 100644 --- a/crates/shirabe-external-packages/src/symfony/console/application.rs +++ b/crates/shirabe-external-packages/src/symfony/console/application.rs @@ -353,9 +353,9 @@ impl Application { .borrow() .writeln(&["".to_string()], output_interface::OUTPUT_NORMAL); let formatted_block = FormatterHelper::default().format_block( - FormatBlockMessages::String(shirabe_php_shim::sprintf( - "Command \"%s\" is not defined.", - &[PhpMixed::from(name.clone())], + FormatBlockMessages::String(format!( + "Command \"{}\" is not defined.", + PhpMixed::from(name.clone()), )), "error", true, @@ -364,9 +364,9 @@ impl Application { .borrow() .writeln(&[formatted_block], output_interface::OUTPUT_NORMAL); if !style.confirm( - &shirabe_php_shim::sprintf( - "Do you want to run \"%s\" instead? ", - &[PhpMixed::from(alternative.clone())], + &format!( + "Do you want to run \"{}\" instead? ", + PhpMixed::from(alternative.clone()), ), false, ) { @@ -595,11 +595,9 @@ impl Application { if command.borrow().get_name().is_none() { return Err(LogicException(shirabe_php_shim::LogicException { - message: shirabe_php_shim::sprintf( - "The command defined in \"%s\" cannot have an empty name.", - &[PhpMixed::from(shirabe_php_shim::get_debug_type_obj( - &command, - ))], + message: format!( + "The command defined in \"{}\" cannot have an empty name.", + PhpMixed::from(shirabe_php_shim::get_debug_type_obj(&command,)), ), code: 0, }) @@ -624,9 +622,9 @@ impl Application { if !self.has(name) { return Err(CommandNotFoundException::new( - shirabe_php_shim::sprintf( - "The command \"%s\" does not exist.", - &[PhpMixed::from(name.to_string())], + format!( + "The command \"{}\" does not exist.", + PhpMixed::from(name.to_string()), ), Vec::new(), 0, @@ -637,9 +635,9 @@ impl Application { // When the command has a different name than the one used at the command loader level if !self.commands.contains_key(name) { return Err(CommandNotFoundException::new( - shirabe_php_shim::sprintf( - "The \"%s\" command cannot be found because it is registered under multiple names. Make sure you don't set a different name via constructor or \"setName()\".", - &[PhpMixed::from(name.to_string())], + format!( + "The \"{}\" command cannot be found because it is registered under multiple names. Make sure you don't set a different name via constructor or \"setName()\".", + PhpMixed::from(name.to_string()), ), Vec::new(), 0, @@ -742,9 +740,9 @@ impl Application { let namespaces = shirabe_php_shim::preg_grep(&format!("{{^{}}}", expr), &all_namespaces); if namespaces.is_empty() { - let mut message = shirabe_php_shim::sprintf( - "There are no commands defined in the \"%s\" namespace.", - &[PhpMixed::from(namespace.to_string())], + let mut message = format!( + "There are no commands defined in the \"{}\" namespace.", + PhpMixed::from(namespace.to_string()), ); let alternatives = self.find_alternatives(namespace, &all_namespaces); @@ -769,12 +767,10 @@ impl Application { let exact = namespaces.iter().any(|n| n == namespace); if namespaces.len() > 1 && !exact { return Err(NamespaceNotFoundException(CommandNotFoundException::new( - shirabe_php_shim::sprintf( - "The namespace \"%s\" is ambiguous.\nDid you mean one of these?\n%s.", - &[ - PhpMixed::from(namespace.to_string()), - PhpMixed::from(self.get_abbreviation_suggestions(&namespaces)), - ], + format!( + "The namespace \"{}\" is ambiguous.\nDid you mean one of these?\n{}.", + PhpMixed::from(namespace.to_string()), + PhpMixed::from(self.get_abbreviation_suggestions(&namespaces)), ), namespaces.clone(), 0, @@ -845,9 +841,9 @@ impl Application { self.find_namespace(&name[..pos as usize])?; } - let mut message = shirabe_php_shim::sprintf( - "Command \"%s\" is not defined.", - &[PhpMixed::from(name.to_string())], + let mut message = format!( + "Command \"{}\" is not defined.", + PhpMixed::from(name.to_string()), ); let mut alternatives = self.find_alternatives(name, &all_commands); @@ -956,12 +952,10 @@ impl Application { let suggestions = self.get_abbreviation_suggestions(&filtered); return Err(CommandNotFoundException::new( - shirabe_php_shim::sprintf( - "Command \"%s\" is ambiguous.\nDid you mean one of these?\n%s.", - &[ - PhpMixed::from(name.to_string()), - PhpMixed::from(suggestions), - ], + format!( + "Command \"{}\" is ambiguous.\nDid you mean one of these?\n{}.", + PhpMixed::from(name.to_string()), + PhpMixed::from(suggestions), ), commands.clone(), 0, @@ -976,9 +970,9 @@ impl Application { if command.borrow().is_hidden() { return Err(CommandNotFoundException::new( - shirabe_php_shim::sprintf( - "The command \"%s\" does not exist.", - &[PhpMixed::from(name.to_string())], + format!( + "The command \"{}\" does not exist.", + PhpMixed::from(name.to_string()), ), Vec::new(), 0, @@ -1075,15 +1069,15 @@ impl Application { if let Some(running_command) = &self.running_command { output.borrow().writeln( - &[shirabe_php_shim::sprintf( - "%s", - &[PhpMixed::from( + &[format!( + "{}", + PhpMixed::from( OutputFormatter::escape(&shirabe_php_shim::sprintf( &running_command.borrow_mut().get_synopsis(false), &[PhpMixed::from(self.get_name())], )) .unwrap(), - )], + ), )], output_interface::VERBOSITY_QUIET, ); diff --git a/crates/shirabe-external-packages/src/symfony/console/color.rs b/crates/shirabe-external-packages/src/symfony/console/color.rs index 4bf52f3..537893c 100644 --- a/crates/shirabe-external-packages/src/symfony/console/color.rs +++ b/crates/shirabe-external-packages/src/symfony/console/color.rs @@ -75,19 +75,16 @@ impl Color { if available.is_none() { return Err(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "Invalid option specified: \"%s\". Expected one of (%s).", - &[ - option.clone().into(), - shirabe_php_shim::implode( - ", ", - &AVAILABLE_OPTIONS - .iter() - .map(|(k, _)| k.to_string()) - .collect::>(), - ) - .into(), - ], + message: format!( + "Invalid option specified: \"{}\". Expected one of ({}).", + option.clone(), + shirabe_php_shim::implode( + ", ", + &AVAILABLE_OPTIONS + .iter() + .map(|(k, _)| k.to_string()) + .collect::>(), + ), ), code: 0, }, @@ -156,10 +153,7 @@ impl Color { if shirabe_php_shim::strlen(&color) != 6 { return Err(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "Invalid \"%s\" color.", - &[color.clone().into()], - ), + message: format!("Invalid \"{}\" color.", color.clone(),), code: 0, }, )); @@ -184,12 +178,10 @@ impl Color { available.extend(BRIGHT_COLORS.iter().map(|(k, _)| k.to_string())); Err(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "Invalid \"%s\" color; expected one of (%s).", - &[ - color.into(), - shirabe_php_shim::implode(", ", &available).into(), - ], + message: format!( + "Invalid \"{}\" color; expected one of ({}).", + color, + shirabe_php_shim::implode(", ", &available), ), code: 0, }, @@ -206,7 +198,7 @@ impl Color { return Self::degrade_hex_color_to_ansi(r, g, b).to_string(); } - shirabe_php_shim::sprintf("8;2;%d;%d;%d", &[r.into(), g.into(), b.into()]) + format!("8;2;{};{};{}", r, g, b) } fn degrade_hex_color_to_ansi(r: i64, g: i64, b: i64) -> i64 { diff --git a/crates/shirabe-external-packages/src/symfony/console/cursor.rs b/crates/shirabe-external-packages/src/symfony/console/cursor.rs index 9016fab..8474f85 100644 --- a/crates/shirabe-external-packages/src/symfony/console/cursor.rs +++ b/crates/shirabe-external-packages/src/symfony/console/cursor.rs @@ -31,10 +31,7 @@ impl Cursor { pub fn move_up(&self, lines: i64) -> &Self { self.output.borrow().write( - &[shirabe_php_shim::sprintf( - "\x1b[%dA", - &[shirabe_php_shim::PhpMixed::Int(lines)], - )], + &[format!("\x1b[{}A", shirabe_php_shim::PhpMixed::Int(lines),)], false, output_interface::OUTPUT_NORMAL, ); @@ -44,10 +41,7 @@ impl Cursor { pub fn move_down(&self, lines: i64) -> &Self { self.output.borrow().write( - &[shirabe_php_shim::sprintf( - "\x1b[%dB", - &[shirabe_php_shim::PhpMixed::Int(lines)], - )], + &[format!("\x1b[{}B", shirabe_php_shim::PhpMixed::Int(lines),)], false, output_interface::OUTPUT_NORMAL, ); @@ -57,9 +51,9 @@ impl Cursor { pub fn move_right(&self, columns: i64) -> &Self { self.output.borrow().write( - &[shirabe_php_shim::sprintf( - "\x1b[%dC", - &[shirabe_php_shim::PhpMixed::Int(columns)], + &[format!( + "\x1b[{}C", + shirabe_php_shim::PhpMixed::Int(columns), )], false, output_interface::OUTPUT_NORMAL, @@ -70,9 +64,9 @@ impl Cursor { pub fn move_left(&self, columns: i64) -> &Self { self.output.borrow().write( - &[shirabe_php_shim::sprintf( - "\x1b[%dD", - &[shirabe_php_shim::PhpMixed::Int(columns)], + &[format!( + "\x1b[{}D", + shirabe_php_shim::PhpMixed::Int(columns), )], false, output_interface::OUTPUT_NORMAL, @@ -83,10 +77,7 @@ impl Cursor { pub fn move_to_column(&self, column: i64) -> &Self { self.output.borrow().write( - &[shirabe_php_shim::sprintf( - "\x1b[%dG", - &[shirabe_php_shim::PhpMixed::Int(column)], - )], + &[format!("\x1b[{}G", shirabe_php_shim::PhpMixed::Int(column),)], false, output_interface::OUTPUT_NORMAL, ); @@ -96,12 +87,10 @@ impl Cursor { pub fn move_to_position(&self, column: i64, row: i64) -> &Self { self.output.borrow().write( - &[shirabe_php_shim::sprintf( - "\x1b[%d;%dH", - &[ - shirabe_php_shim::PhpMixed::Int(row + 1), - shirabe_php_shim::PhpMixed::Int(column), - ], + &[format!( + "\x1b[{};{}H", + shirabe_php_shim::PhpMixed::Int(row + 1), + shirabe_php_shim::PhpMixed::Int(column), )], false, output_interface::OUTPUT_NORMAL, @@ -243,11 +232,9 @@ impl Cursor { None, ); - shirabe_php_shim::shell_exec(&shirabe_php_shim::sprintf( - "stty %s", - &[shirabe_php_shim::PhpMixed::String( - stty_mode.unwrap_or_default(), - )], + shirabe_php_shim::shell_exec(&format!( + "stty {}", + shirabe_php_shim::PhpMixed::String(stty_mode.unwrap_or_default(),), )); let mut row: i64 = 0; 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::>>()? @@ -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( - " %s %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 , 2 spaces after - 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!( + " {} {}{}{}", + PhpMixed::String(argument.get_name().to_string()), + PhpMixed::String(shirabe_php_shim::str_repeat(" ", spacing_width as usize)), + // + 4 = 2 spaces before , 2 spaces after + 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( - " %s %s%s%s%s", - &[ - PhpMixed::String(synopsis), - PhpMixed::String(shirabe_php_shim::str_repeat(" ", spacing_width as usize)), - // + 4 = 2 spaces before , 2 spaces after - 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() { - " (multiple values allowed)".to_string() - } else { - String::new() - }), - ], + &format!( + " {} {}{}{}{}", + PhpMixed::String(synopsis), + PhpMixed::String(shirabe_php_shim::str_repeat(" ", spacing_width as usize)), + // + 4 = 2 spaces before , 2 spaces after + 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() { + " (multiple values allowed)".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!( + "{:Available commands for the \"%s\" namespace:", - &[PhpMixed::String(described_namespace.clone())], + &format!( + "Available commands for the \"{}\" namespace:", + PhpMixed::String(described_namespace.clone()), ), &options, ); @@ -412,20 +402,18 @@ impl TextDescriptor { String::new() }; self.write_text( - &shirabe_php_shim::sprintf( - " %s%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!( + " {}{}{}", + PhpMixed::String(name.clone()), + PhpMixed::String(shirabe_php_shim::str_repeat( + " ", + spacing_width as usize, + )), + PhpMixed::String(format!( + "{}{}", + command_aliases, + command.get_description() + )), ), &options, ); diff --git a/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter.rs b/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter.rs index 4a451d9..3efdbaa 100644 --- a/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter.rs +++ b/crates/shirabe-external-packages/src/symfony/console/formatter/output_formatter.rs @@ -243,9 +243,9 @@ impl OutputFormatterInterface for OutputFormatter { if !self.has_style(name) { return Err(anyhow::anyhow!(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "Undefined style: \"%s\".", - &[shirabe_php_shim::PhpMixed::String(name.to_string())], + message: format!( + "Undefined style: \"{}\".", + shirabe_php_shim::PhpMixed::String(name.to_string()), ), code: 0, }, diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/debug_formatter_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/debug_formatter_helper.rs index 26ad169..170c557 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/debug_formatter_helper.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/debug_formatter_helper.rs @@ -51,13 +51,11 @@ impl DebugFormatterHelper { }, ); - shirabe_php_shim::sprintf( - "%s %s %s\n", - &[ - shirabe_php_shim::PhpMixed::String(self.get_border(id)), - shirabe_php_shim::PhpMixed::String(prefix.to_string()), - shirabe_php_shim::PhpMixed::String(message.to_string()), - ], + format!( + "{} {} {}\n", + shirabe_php_shim::PhpMixed::String(self.get_border(id)), + shirabe_php_shim::PhpMixed::String(prefix.to_string()), + shirabe_php_shim::PhpMixed::String(message.to_string()), ) } @@ -78,24 +76,20 @@ impl DebugFormatterHelper { self.started.get_mut(id).unwrap().out = false; } if !self.started[id].err { - message.push_str(&shirabe_php_shim::sprintf( - "%s %s ", - &[ - shirabe_php_shim::PhpMixed::String(self.get_border(id)), - shirabe_php_shim::PhpMixed::String(error_prefix.to_string()), - ], + message.push_str(&format!( + "{} {} ", + shirabe_php_shim::PhpMixed::String(self.get_border(id)), + shirabe_php_shim::PhpMixed::String(error_prefix.to_string()), )); self.started.get_mut(id).unwrap().err = true; } message.push_str(&shirabe_php_shim::str_replace( "\n", - &shirabe_php_shim::sprintf( - "\n%s %s ", - &[ - shirabe_php_shim::PhpMixed::String(self.get_border(id)), - shirabe_php_shim::PhpMixed::String(error_prefix.to_string()), - ], + &format!( + "\n{} {} ", + shirabe_php_shim::PhpMixed::String(self.get_border(id)), + shirabe_php_shim::PhpMixed::String(error_prefix.to_string()), ), buffer, )); @@ -105,24 +99,20 @@ impl DebugFormatterHelper { self.started.get_mut(id).unwrap().err = false; } if !self.started[id].out { - message.push_str(&shirabe_php_shim::sprintf( - "%s %s ", - &[ - shirabe_php_shim::PhpMixed::String(self.get_border(id)), - shirabe_php_shim::PhpMixed::String(prefix.to_string()), - ], + message.push_str(&format!( + "{} {} ", + shirabe_php_shim::PhpMixed::String(self.get_border(id)), + shirabe_php_shim::PhpMixed::String(prefix.to_string()), )); self.started.get_mut(id).unwrap().out = true; } message.push_str(&shirabe_php_shim::str_replace( "\n", - &shirabe_php_shim::sprintf( - "\n%s %s ", - &[ - shirabe_php_shim::PhpMixed::String(self.get_border(id)), - shirabe_php_shim::PhpMixed::String(prefix.to_string()), - ], + &format!( + "\n{} {} ", + shirabe_php_shim::PhpMixed::String(self.get_border(id)), + shirabe_php_shim::PhpMixed::String(prefix.to_string()), ), buffer, )); @@ -140,25 +130,21 @@ impl DebugFormatterHelper { }; if successful { - return shirabe_php_shim::sprintf( - "%s%s %s %s\n", - &[ - shirabe_php_shim::PhpMixed::String(trailing_eol.to_string()), - shirabe_php_shim::PhpMixed::String(self.get_border(id)), - shirabe_php_shim::PhpMixed::String(prefix.to_string()), - shirabe_php_shim::PhpMixed::String(message.to_string()), - ], - ); - } - - let message = shirabe_php_shim::sprintf( - "%s%s %s %s\n", - &[ + return format!( + "{}{} {} {}\n", shirabe_php_shim::PhpMixed::String(trailing_eol.to_string()), shirabe_php_shim::PhpMixed::String(self.get_border(id)), shirabe_php_shim::PhpMixed::String(prefix.to_string()), shirabe_php_shim::PhpMixed::String(message.to_string()), - ], + ); + } + + let message = format!( + "{}{} {} {}\n", + shirabe_php_shim::PhpMixed::String(trailing_eol.to_string()), + shirabe_php_shim::PhpMixed::String(self.get_border(id)), + shirabe_php_shim::PhpMixed::String(prefix.to_string()), + shirabe_php_shim::PhpMixed::String(message.to_string()), ); if let Some(session) = self.started.get_mut(id) { @@ -170,11 +156,11 @@ impl DebugFormatterHelper { } fn get_border(&self, id: &str) -> String { - shirabe_php_shim::sprintf( - " ", - &[shirabe_php_shim::PhpMixed::String( + format!( + " ", + shirabe_php_shim::PhpMixed::String( COLORS[self.started[id].border as usize].to_string(), - )], + ), ) } } diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/descriptor_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/descriptor_helper.rs index 64c166c..333af92 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/descriptor_helper.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/descriptor_helper.rs @@ -85,9 +85,9 @@ impl DescriptorHelper { if !self.descriptors.contains_key(&format) { return Err(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "Unsupported format \"%s\".", - &[shirabe_php_shim::PhpMixed::String(format.clone())], + message: format!( + "Unsupported format \"{}\".", + shirabe_php_shim::PhpMixed::String(format.clone()), ), code: 0, }, 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; } diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/helper.rs index b599f11..3122f82 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/helper.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/helper.rs @@ -110,31 +110,18 @@ impl Helper { pub fn format_memory(memory: i64) -> String { if memory >= 1024 * 1024 * 1024 { - return shirabe_php_shim::sprintf( - "%.1f GiB", - &[shirabe_php_shim::PhpMixed::Float( - memory as f64 / 1024.0 / 1024.0 / 1024.0, - )], - ); + return format!("{:.1} GiB", memory as f64 / 1024.0 / 1024.0 / 1024.0,); } if memory >= 1024 * 1024 { - return shirabe_php_shim::sprintf( - "%.1f MiB", - &[shirabe_php_shim::PhpMixed::Float( - memory as f64 / 1024.0 / 1024.0, - )], - ); + return format!("{:.1} MiB", memory as f64 / 1024.0 / 1024.0,); } if memory >= 1024 { - return shirabe_php_shim::sprintf( - "%d KiB", - &[shirabe_php_shim::PhpMixed::Int(memory / 1024)], - ); + return format!("{} KiB", shirabe_php_shim::PhpMixed::Int(memory / 1024),); } - shirabe_php_shim::sprintf("%d B", &[shirabe_php_shim::PhpMixed::Int(memory)]) + format!("{} B", shirabe_php_shim::PhpMixed::Int(memory)) } /// @deprecated since Symfony 5.3 diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/helper_set.rs b/crates/shirabe-external-packages/src/symfony/console/helper/helper_set.rs index a7ef820..292a7a4 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/helper_set.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/helper_set.rs @@ -60,9 +60,9 @@ impl HelperSet { if !self.has(name) { return Err(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "The helper \"%s\" is not defined.", - &[shirabe_php_shim::PhpMixed::String(name.to_string())], + message: format!( + "The helper \"{}\" is not defined.", + shirabe_php_shim::PhpMixed::String(name.to_string()), ), code: 0, }, diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/process_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/process_helper.rs index 7652cac..bd26003 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/process_helper.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/process_helper.rs @@ -95,11 +95,9 @@ impl ProcessHelper { } None => { anyhow::bail!(shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "Invalid command provided to \"%s()\": the command should be an array whose first element is either the path to the binary to run or a \"Process\" object.", - &[shirabe_php_shim::PhpMixed::String( - "ProcessHelper::run".to_string() - )], + message: format!( + "Invalid command provided to \"{}()\": the command should be an array whose first element is either the path to the binary to run or a \"Process\" object.", + shirabe_php_shim::PhpMixed::String("ProcessHelper::run".to_string()), ), code: 0, }); @@ -130,12 +128,12 @@ impl ProcessHelper { let message = if process.is_successful() { "Command ran successfully".to_string() } else { - shirabe_php_shim::sprintf( - "%s Command did not run successfully", - &[match process.get_exit_code() { + format!( + "{} Command did not run successfully", + match process.get_exit_code() { Some(code) => shirabe_php_shim::PhpMixed::Int(code), None => shirabe_php_shim::PhpMixed::Null, - }], + }, ) }; let stopped = Self::formatter_stop( @@ -151,11 +149,9 @@ impl ProcessHelper { if !process.is_successful() && error.is_some() { output.borrow().writeln( - &[shirabe_php_shim::sprintf( - "%s", - &[shirabe_php_shim::PhpMixed::String( - self.escape_string(error.unwrap()), - )], + &[format!( + "{}", + shirabe_php_shim::PhpMixed::String(self.escape_string(error.unwrap()),), )], output_interface::OUTPUT_NORMAL, ); diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs b/crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs index bd6fe86..f14e53a 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs @@ -815,9 +815,9 @@ impl ProgressBar { shirabe_php_shim::PhpMixed::String(s) => s, shirabe_php_shim::PhpMixed::Int(i) => i.to_string(), shirabe_php_shim::PhpMixed::Float(f) => { - shirabe_php_shim::sprintf("%s", &[shirabe_php_shim::PhpMixed::Float(f)]) + format!("{}", shirabe_php_shim::PhpMixed::Float(f)) } - other => shirabe_php_shim::sprintf("%s", &[other]), + other => format!("{}", other), }) }; diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs index 7ddb620..dcd761c 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs @@ -301,9 +301,10 @@ impl QuestionHelper { let padding = shirabe_php_shim::str_repeat(" ", (max_width - Helper::width(key)) as usize); - messages.push(shirabe_php_shim::sprintf( - &format!(" [<{tag}>%s{padding}] %s"), - &[PhpMixed::String(key.clone()), (**value).clone()], + messages.push(format!( + " [<{tag}>{}{padding}] {}", + PhpMixed::String(key.clone()), + (**value).clone(), )); } 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()), ); } diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/table.rs b/crates/shirabe-external-packages/src/symfony/console/helper/table.rs index 6f52458..5189efd 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/table.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/table.rs @@ -119,10 +119,7 @@ impl Table { Ok(Err(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "Style \"%s\" is not defined.", - &[PhpMixed::from(name)], - ), + message: format!("Style \"{}\" is not defined.", PhpMixed::from(name),), code: 0, }, ))) @@ -271,12 +268,10 @@ impl Table { ) -> anyhow::Result> { if !Self::output_is_console_section(&self.output) { return Ok(Err(RuntimeException(shirabe_php_shim::RuntimeException { - message: shirabe_php_shim::sprintf( - "Output should be an instance of \"%s\" when calling \"%s\".", - &[ - PhpMixed::from("Symfony\\Component\\Console\\Output\\ConsoleSectionOutput"), - PhpMixed::from("Symfony\\Component\\Console\\Helper\\Table::appendRow"), - ], + message: format!( + "Output should be an instance of \"{}\" when calling \"{}\".", + PhpMixed::from("Symfony\\Component\\Console\\Output\\ConsoleSectionOutput"), + PhpMixed::from("Symfony\\Component\\Console\\Helper\\Table::appendRow"), ), code: 0, }))); @@ -1239,10 +1234,7 @@ impl Table { Ok(Err(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "Style \"%s\" is not defined.", - &[PhpMixed::from(name_str)], - ), + message: format!("Style \"{}\" is not defined.", PhpMixed::from(name_str),), code: 0, }, ))) diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/table_cell.rs b/crates/shirabe-external-packages/src/symfony/console/helper/table_cell.rs index d8d8339..13ac96f 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/table_cell.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/table_cell.rs @@ -36,9 +36,9 @@ impl TableCell { if !diff.is_empty() { return Err(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "The TableCell does not support the following options: '%s'.", - &[shirabe_php_shim::PhpMixed::String(diff.join("', '"))], + message: format!( + "The TableCell does not support the following options: '{}'.", + shirabe_php_shim::PhpMixed::String(diff.join("', '")), ), code: 0, }, diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/table_cell_style.rs b/crates/shirabe-external-packages/src/symfony/console/helper/table_cell_style.rs index 9d41c45..a738670 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/table_cell_style.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/table_cell_style.rs @@ -52,9 +52,9 @@ impl TableCellStyle { if !diff.is_empty() { return Err(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "The TableCellStyle does not support the following options: '%s'.", - &[shirabe_php_shim::PhpMixed::String(diff.join("', '"))], + message: format!( + "The TableCellStyle does not support the following options: '{}'.", + shirabe_php_shim::PhpMixed::String(diff.join("', '")), ), code: 0, }, @@ -69,11 +69,9 @@ impl TableCellStyle { if align_map(&align).is_none() { return Err(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "Wrong align value. Value must be following: '%s'.", - &[shirabe_php_shim::PhpMixed::String( - align_map_keys().join("', '"), - )], + message: format!( + "Wrong align value. Value must be following: '{}'.", + shirabe_php_shim::PhpMixed::String(align_map_keys().join("', '"),), ), code: 0, }, diff --git a/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs b/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs index e9cb8d3..765f601 100644 --- a/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs +++ b/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs @@ -148,10 +148,7 @@ impl ArgvInput { } }; return Err(RuntimeException(shirabe_php_shim::RuntimeException { - message: shirabe_php_shim::sprintf( - "The \"-%s\" option does not exist.", - &[PhpMixed::String(bad)], - ), + message: format!("The \"-{}\" option does not exist.", PhpMixed::String(bad),), code: 0, }) .into()); @@ -251,17 +248,15 @@ impl ArgvInput { Some(symfony_command_name) if !matches!(symfony_command_name, PhpMixed::Null) => { - shirabe_php_shim::sprintf( - "Too many arguments to \"%s\" command, expected arguments \"%s\".", - &[ - symfony_command_name.clone(), - PhpMixed::String(shirabe_php_shim::implode("\" \"", &names)), - ], + format!( + "Too many arguments to \"{}\" command, expected arguments \"{}\".", + symfony_command_name.clone(), + PhpMixed::String(shirabe_php_shim::implode("\" \"", &names)), ) } - _ => shirabe_php_shim::sprintf( - "Too many arguments, expected arguments \"%s\".", - &[PhpMixed::String(shirabe_php_shim::implode("\" \"", &names))], + _ => format!( + "Too many arguments, expected arguments \"{}\".", + PhpMixed::String(shirabe_php_shim::implode("\" \"", &names)), ), } } else if symfony_command_name @@ -269,17 +264,15 @@ impl ArgvInput { .map(|n| !matches!(n, PhpMixed::Null)) .unwrap_or(false) { - shirabe_php_shim::sprintf( - "No arguments expected for \"%s\" command, got \"%s\".", - &[ - symfony_command_name.clone().unwrap(), - PhpMixed::String(token.to_string()), - ], + format!( + "No arguments expected for \"{}\" command, got \"{}\".", + symfony_command_name.clone().unwrap(), + PhpMixed::String(token.to_string()), ) } else { - shirabe_php_shim::sprintf( - "No arguments expected, got \"%s\".", - &[PhpMixed::String(token.to_string())], + format!( + "No arguments expected, got \"{}\".", + PhpMixed::String(token.to_string()), ) }; @@ -295,9 +288,9 @@ impl ArgvInput { fn add_short_option(&mut self, shortcut: &str, value: PhpMixed) -> anyhow::Result<()> { if !self.inner.definition.has_shortcut(shortcut) { return Err(RuntimeException(shirabe_php_shim::RuntimeException { - message: shirabe_php_shim::sprintf( - "The \"-%s\" option does not exist.", - &[PhpMixed::String(shortcut.to_string())], + message: format!( + "The \"-{}\" option does not exist.", + PhpMixed::String(shortcut.to_string()), ), code: 0, }) @@ -320,9 +313,9 @@ impl ArgvInput { if !self.inner.definition.has_option(name) { if !self.inner.definition.has_negation(name) { return Err(RuntimeException(shirabe_php_shim::RuntimeException { - message: shirabe_php_shim::sprintf( - "The \"--%s\" option does not exist.", - &[PhpMixed::String(name.to_string())], + message: format!( + "The \"--{}\" option does not exist.", + PhpMixed::String(name.to_string()), ), code: 0, }) @@ -332,9 +325,9 @@ impl ArgvInput { let option_name = self.inner.definition.negation_to_name(name)?; if !matches!(value, PhpMixed::Null) { return Err(RuntimeException(shirabe_php_shim::RuntimeException { - message: shirabe_php_shim::sprintf( - "The \"--%s\" option does not accept a value.", - &[PhpMixed::String(name.to_string())], + message: format!( + "The \"--{}\" option does not accept a value.", + PhpMixed::String(name.to_string()), ), code: 0, }) @@ -351,9 +344,9 @@ impl ArgvInput { if !matches!(value, PhpMixed::Null) && !option.accept_value() { return Err(RuntimeException(shirabe_php_shim::RuntimeException { - message: shirabe_php_shim::sprintf( - "The \"--%s\" option does not accept a value.", - &[PhpMixed::String(name.to_string())], + message: format!( + "The \"--{}\" option does not accept a value.", + PhpMixed::String(name.to_string()), ), code: 0, }) @@ -379,9 +372,9 @@ impl ArgvInput { if matches!(value, PhpMixed::Null) { if option.is_value_required() { return Err(RuntimeException(shirabe_php_shim::RuntimeException { - message: shirabe_php_shim::sprintf( - "The \"--%s\" option requires a value.", - &[PhpMixed::String(name.to_string())], + message: format!( + "The \"--{}\" option requires a value.", + PhpMixed::String(name.to_string()), ), code: 0, }) diff --git a/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs b/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs index 17c8aa8..ccc1916 100644 --- a/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs +++ b/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs @@ -206,9 +206,9 @@ impl ArrayInput { if !self.inner.definition.has_shortcut(shortcut) { return Err(InvalidOptionException(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "The \"-%s\" option does not exist.", - &[PhpMixed::String(shortcut.to_string())], + message: format!( + "The \"-{}\" option does not exist.", + PhpMixed::String(shortcut.to_string()), ), code: 0, }, @@ -233,9 +233,9 @@ impl ArrayInput { if !self.inner.definition.has_negation(name) { return Err(InvalidOptionException(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "The \"--%s\" option does not exist.", - &[PhpMixed::String(name.to_string())], + message: format!( + "The \"--{}\" option does not exist.", + PhpMixed::String(name.to_string()), ), code: 0, }, @@ -257,9 +257,9 @@ impl ArrayInput { if option.is_value_required() { return Err(InvalidOptionException(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "The \"--%s\" option requires a value.", - &[PhpMixed::String(name.to_string())], + message: format!( + "The \"--{}\" option requires a value.", + PhpMixed::String(name.to_string()), ), code: 0, }, @@ -282,10 +282,7 @@ impl ArrayInput { if !self.inner.definition.has_argument(name) { return Err( InvalidArgumentException(shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "The \"%s\" argument does not exist.", - &[name.clone()], - ), + message: format!("The \"{}\" argument does not exist.", name.clone(),), code: 0, }) .into(), diff --git a/crates/shirabe-external-packages/src/symfony/console/input/input.rs b/crates/shirabe-external-packages/src/symfony/console/input/input.rs index 4c878bc..2c9a3a6 100644 --- a/crates/shirabe-external-packages/src/symfony/console/input/input.rs +++ b/crates/shirabe-external-packages/src/symfony/console/input/input.rs @@ -79,12 +79,9 @@ impl Input { if missing_arguments.len() > 0 { return Err(RuntimeException(shirabe_php_shim::RuntimeException { - message: shirabe_php_shim::sprintf( - "Not enough arguments (missing: \"%s\").", - &[PhpMixed::String(shirabe_php_shim::implode( - ", ", - &missing_arguments, - ))], + message: format!( + "Not enough arguments (missing: \"{}\").", + PhpMixed::String(shirabe_php_shim::implode(", ", &missing_arguments,)), ), code: 0, }) @@ -116,9 +113,9 @@ impl Input { { return Err( InvalidArgumentException(shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "The \"%s\" argument does not exist.", - &[PhpMixed::String(name.to_string())], + message: format!( + "The \"{}\" argument does not exist.", + PhpMixed::String(name.to_string()), ), code: 0, }) @@ -143,9 +140,9 @@ impl Input { { return Err( InvalidArgumentException(shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "The \"%s\" argument does not exist.", - &[PhpMixed::String(name.to_string())], + message: format!( + "The \"{}\" argument does not exist.", + PhpMixed::String(name.to_string()), ), code: 0, }) @@ -183,9 +180,9 @@ impl Input { if !self.definition.has_option(name) { return Err( InvalidArgumentException(shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "The \"%s\" option does not exist.", - &[PhpMixed::String(name.to_string())], + message: format!( + "The \"{}\" option does not exist.", + PhpMixed::String(name.to_string()), ), code: 0, }) @@ -210,9 +207,9 @@ impl Input { } else if !self.definition.has_option(name) { return Err( InvalidArgumentException(shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "The \"%s\" option does not exist.", - &[PhpMixed::String(name.to_string())], + message: format!( + "The \"{}\" option does not exist.", + PhpMixed::String(name.to_string()), ), code: 0, }) diff --git a/crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs b/crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs index 5a3eef5..917f02a 100644 --- a/crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs +++ b/crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs @@ -90,9 +90,9 @@ impl InputDefinition { if self.arguments.contains_key(argument.get_name()) { return Err(LogicException(shirabe_php_shim::LogicException { - message: shirabe_php_shim::sprintf( - "An argument with name \"%s\" already exists.", - &[PhpMixed::String(argument.get_name().to_string())], + message: format!( + "An argument with name \"{}\" already exists.", + PhpMixed::String(argument.get_name().to_string()), ), code: 0, }) @@ -101,12 +101,10 @@ impl InputDefinition { if let Some(last_array_argument) = &self.last_array_argument { return Err(LogicException(shirabe_php_shim::LogicException { - message: shirabe_php_shim::sprintf( - "Cannot add a required argument \"%s\" after an array argument \"%s\".", - &[ - PhpMixed::String(argument.get_name().to_string()), - PhpMixed::String(last_array_argument.get_name().to_string()), - ], + message: format!( + "Cannot add a required argument \"{}\" after an array argument \"{}\".", + PhpMixed::String(argument.get_name().to_string()), + PhpMixed::String(last_array_argument.get_name().to_string()), ), code: 0, }) @@ -116,12 +114,10 @@ impl InputDefinition { if argument.is_required() { if let Some(last_optional_argument) = &self.last_optional_argument { return Err(LogicException(shirabe_php_shim::LogicException { - message: shirabe_php_shim::sprintf( - "Cannot add a required argument \"%s\" after an optional one \"%s\".", - &[ - PhpMixed::String(argument.get_name().to_string()), - PhpMixed::String(last_optional_argument.get_name().to_string()), - ], + message: format!( + "Cannot add a required argument \"{}\" after an optional one \"{}\".", + PhpMixed::String(argument.get_name().to_string()), + PhpMixed::String(last_optional_argument.get_name().to_string()), ), code: 0, }) @@ -150,10 +146,7 @@ impl InputDefinition { if !self.has_argument(name) { return Err( InvalidArgumentException(shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "The \"%s\" argument does not exist.", - &[name.clone()], - ), + message: format!("The \"{}\" argument does not exist.", name.clone(),), code: 0, }) .into(), @@ -240,9 +233,9 @@ impl InputDefinition { if let Some(existing) = self.options.get(option.get_name()) { if !option.equals(existing) { return Err(LogicException(shirabe_php_shim::LogicException { - message: shirabe_php_shim::sprintf( - "An option named \"%s\" already exists.", - &[PhpMixed::String(option.get_name().to_string())], + message: format!( + "An option named \"{}\" already exists.", + PhpMixed::String(option.get_name().to_string()), ), code: 0, }) @@ -251,9 +244,9 @@ impl InputDefinition { } if self.negations.contains_key(option.get_name()) { return Err(LogicException(shirabe_php_shim::LogicException { - message: shirabe_php_shim::sprintf( - "An option named \"%s\" already exists.", - &[PhpMixed::String(option.get_name().to_string())], + message: format!( + "An option named \"{}\" already exists.", + PhpMixed::String(option.get_name().to_string()), ), code: 0, }) @@ -265,9 +258,9 @@ impl InputDefinition { if let Some(existing_name) = self.shortcuts.get(&shortcut) { if !option.equals(&self.options[existing_name]) { return Err(LogicException(shirabe_php_shim::LogicException { - message: shirabe_php_shim::sprintf( - "An option with shortcut \"%s\" already exists.", - &[PhpMixed::String(shortcut.clone())], + message: format!( + "An option with shortcut \"{}\" already exists.", + PhpMixed::String(shortcut.clone()), ), code: 0, }) @@ -290,9 +283,9 @@ impl InputDefinition { let negated_name = format!("no-{}", option.get_name()); if self.options.contains_key(&negated_name) { return Err(LogicException(shirabe_php_shim::LogicException { - message: shirabe_php_shim::sprintf( - "An option named \"%s\" already exists.", - &[PhpMixed::String(negated_name.clone())], + message: format!( + "An option named \"{}\" already exists.", + PhpMixed::String(negated_name.clone()), ), code: 0, }) @@ -310,9 +303,9 @@ impl InputDefinition { if !self.has_option(name) { return Err( InvalidArgumentException(shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "The \"--%s\" option does not exist.", - &[PhpMixed::String(name.to_string())], + message: format!( + "The \"--{}\" option does not exist.", + PhpMixed::String(name.to_string()), ), code: 0, }) @@ -365,9 +358,9 @@ impl InputDefinition { match self.shortcuts.get(shortcut) { None => Err( InvalidArgumentException(shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "The \"-%s\" option does not exist.", - &[PhpMixed::String(shortcut.to_string())], + message: format!( + "The \"-{}\" option does not exist.", + PhpMixed::String(shortcut.to_string()), ), code: 0, }) @@ -382,9 +375,9 @@ impl InputDefinition { match self.negations.get(negation) { None => Err( InvalidArgumentException(shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "The \"--%s\" option does not exist.", - &[PhpMixed::String(negation.to_string())], + message: format!( + "The \"--{}\" option does not exist.", + PhpMixed::String(negation.to_string()), ), code: 0, }) @@ -404,46 +397,39 @@ impl InputDefinition { for option in self.get_options().values() { let mut value = String::new(); if option.accept_value() { - value = shirabe_php_shim::sprintf( - " %s%s%s", - &[ - PhpMixed::String(if option.is_value_optional() { - "[".to_string() - } else { - String::new() - }), - PhpMixed::String(shirabe_php_shim::strtoupper(option.get_name())), - PhpMixed::String(if option.is_value_optional() { - "]".to_string() - } else { - String::new() - }), - ], + value = format!( + " {}{}{}", + PhpMixed::String(if option.is_value_optional() { + "[".to_string() + } else { + String::new() + }), + PhpMixed::String(shirabe_php_shim::strtoupper(option.get_name())), + PhpMixed::String(if option.is_value_optional() { + "]".to_string() + } else { + String::new() + }), ); } let shortcut = match option.get_shortcut() { Some(shortcut) => { - shirabe_php_shim::sprintf("-%s|", &[PhpMixed::String(shortcut.to_string())]) + format!("-{}|", PhpMixed::String(shortcut.to_string())) } None => String::new(), }; let negation = if option.is_negatable() { - shirabe_php_shim::sprintf( - "|--no-%s", - &[PhpMixed::String(option.get_name().to_string())], - ) + format!("|--no-{}", PhpMixed::String(option.get_name().to_string()),) } else { String::new() }; - elements.push(shirabe_php_shim::sprintf( - "[%s--%s%s%s]", - &[ - PhpMixed::String(shortcut), - PhpMixed::String(option.get_name().to_string()), - PhpMixed::String(value), - PhpMixed::String(negation), - ], + elements.push(format!( + "[{}--{}{}{}]", + PhpMixed::String(shortcut), + PhpMixed::String(option.get_name().to_string()), + PhpMixed::String(value), + PhpMixed::String(negation), )); } } diff --git a/crates/shirabe-external-packages/src/symfony/console/input/string_input.rs b/crates/shirabe-external-packages/src/symfony/console/input/string_input.rs index aad1d86..bbc9e86 100644 --- a/crates/shirabe-external-packages/src/symfony/console/input/string_input.rs +++ b/crates/shirabe-external-packages/src/symfony/console/input/string_input.rs @@ -102,13 +102,9 @@ impl StringInput { // should never happen return Err( InvalidArgumentException(shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "Unable to parse input near \"... %s ...\".", - &[PhpMixed::String(shirabe_php_shim::substr( - input, - cursor, - Some(10), - ))], + message: format!( + "Unable to parse input near \"... {} ...\".", + PhpMixed::String(shirabe_php_shim::substr(input, cursor, Some(10),)), ), code: 0, }) diff --git a/crates/shirabe-external-packages/src/symfony/console/output/console_section_output.rs b/crates/shirabe-external-packages/src/symfony/console/output/console_section_output.rs index 586752d..514b05d 100644 --- a/crates/shirabe-external-packages/src/symfony/console/output/console_section_output.rs +++ b/crates/shirabe-external-packages/src/symfony/console/output/console_section_output.rs @@ -128,9 +128,9 @@ impl ConsoleSectionOutput { if number_of_lines_to_clear > 0 { // move cursor up n lines self.inner.do_write( - &shirabe_php_shim::sprintf( - "\x1b[%dA", - &[shirabe_php_shim::PhpMixed::Int(number_of_lines_to_clear)], + &format!( + "\x1b[{}A", + shirabe_php_shim::PhpMixed::Int(number_of_lines_to_clear), ), false, ); diff --git a/crates/shirabe-external-packages/src/symfony/console/output/trimmed_buffer_output.rs b/crates/shirabe-external-packages/src/symfony/console/output/trimmed_buffer_output.rs index e603999..8319678 100644 --- a/crates/shirabe-external-packages/src/symfony/console/output/trimmed_buffer_output.rs +++ b/crates/shirabe-external-packages/src/symfony/console/output/trimmed_buffer_output.rs @@ -21,15 +21,13 @@ impl TrimmedBufferOutput { if max_length <= 0 { return Err(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "\"%s()\" expects a strictly positive maxLength. Got %d.", - &[ - shirabe_php_shim::PhpMixed::String( - "Symfony\\Component\\Console\\Output\\TrimmedBufferOutput::__construct" - .to_string(), - ), - shirabe_php_shim::PhpMixed::Int(max_length), - ], + message: format!( + "\"{}()\" expects a strictly positive maxLength. Got {}.", + shirabe_php_shim::PhpMixed::String( + "Symfony\\Component\\Console\\Output\\TrimmedBufferOutput::__construct" + .to_string(), + ), + shirabe_php_shim::PhpMixed::Int(max_length), ), code: 0, }, diff --git a/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs b/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs index 7ad29c8..9250fa4 100644 --- a/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs +++ b/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs @@ -155,11 +155,9 @@ impl ChoiceQuestion { if results.len() > 1 { return Err(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: shirabe_php_shim::sprintf( - "The provided answer is ambiguous. Value should be one of \"%s\".", - &[PhpMixed::String(shirabe_php_shim::implode( - "\" or \"", &results, - ))], + message: format!( + "The provided answer is ambiguous. Value should be one of \"{}\".", + PhpMixed::String(shirabe_php_shim::implode("\" or \"", &results,)), ), code: 0, }, 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( - "%s", - &[PhpMixed::String( - OutputFormatter::escape_trailing_backslash(message), - )], + Box::new(PhpMixed::String(format!( + "{}", + PhpMixed::String(OutputFormatter::escape_trailing_backslash(message),), ))), - Box::new(PhpMixed::String(shirabe_php_shim::sprintf( - "%s", - &[PhpMixed::String(shirabe_php_shim::str_repeat( + Box::new(PhpMixed::String(format!( + "{}", + 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( - "%s", - &[PhpMixed::String( - OutputFormatter::escape_trailing_backslash(message), - )], + Box::new(PhpMixed::String(format!( + "{}", + PhpMixed::String(OutputFormatter::escape_trailing_backslash(message),), ))), - Box::new(PhpMixed::String(shirabe_php_shim::sprintf( - "%s", - &[PhpMixed::String(shirabe_php_shim::str_repeat( + Box::new(PhpMixed::String(format!( + "{}", + 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) { self.auto_prepend_text(); let elements: Vec = 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); } } -- cgit v1.3.1