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/src/command/init_command.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/src/command/init_command.rs')
| -rw-r--r-- | crates/shirabe/src/command/init_command.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs index aea9faf..205494c 100644 --- a/crates/shirabe/src/command/init_command.rs +++ b/crates/shirabe/src/command/init_command.rs @@ -906,9 +906,9 @@ impl InitCommand { if !Preg::is_match(r"{^[^/][A-Za-z0-9\-_/]+/$}", &value_or_default).unwrap_or(false) { return Err(InvalidArgumentException { - message: sprintf( - "The src folder name \"%s\" is invalid. Please add a relative path with tailing forward slash. [A-Za-z0-9_-/]+/", - &[PhpMixed::String(value_or_default.clone())], + message: format!( + "The src folder name \"{}\" is invalid. Please add a relative path with tailing forward slash. [A-Za-z0-9_-/]+/", + PhpMixed::String(value_or_default.clone()), ), code: 0, } @@ -1057,9 +1057,9 @@ impl InitCommand { return false; } - let pattern = sprintf( - "{^/?%s(/\\*?)?$}", - &[PhpMixed::String(preg_quote(vendor, None))], + let pattern = format!( + "{{^/?{}(/\\*?)?$}}", + PhpMixed::String(preg_quote(vendor, None)), ); let lines = file(ignore_file, FILE_IGNORE_NEW_LINES).unwrap_or_default(); @@ -1240,9 +1240,10 @@ impl InitCommand { } if let (Some(name), Some(email)) = (author_name, author_email) { - return Some(sprintf( - "%s <%s>", - &[PhpMixed::String(name), PhpMixed::String(email)], + return Some(format!( + "{} <{}>", + PhpMixed::String(name), + PhpMixed::String(email), )); } |
