diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-02 05:33:48 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-02 05:34:48 +0900 |
| commit | f6767e4fd477cf0a66017f5ff2783aa919beac86 (patch) | |
| tree | 317eb04175149203ced69b3af13ad0a3612a52a1 /crates | |
| parent | 3b22fd4ede833b19c4113f88363021d00090d927 (diff) | |
| download | php-shirabe-f6767e4fd477cf0a66017f5ff2783aa919beac86.tar.gz php-shirabe-f6767e4fd477cf0a66017f5ff2783aa919beac86.tar.zst php-shirabe-f6767e4fd477cf0a66017f5ff2783aa919beac86.zip | |
refactor(auditor): build the summary line with format! instead of sprintf
The two summary templates are compile-time constants, so the runtime
sprintf shim is unnecessary; carry the tag and the "ignored " prefix
through the passes list instead of pre-built template strings.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/shirabe/src/advisory/auditor.rs | 32 | ||||
| -rw-r--r-- | crates/shirabe/src/util/process_executor.rs | 12 |
2 files changed, 10 insertions, 34 deletions
diff --git a/crates/shirabe/src/advisory/auditor.rs b/crates/shirabe/src/advisory/auditor.rs index 41cef838..e0bb374c 100644 --- a/crates/shirabe/src/advisory/auditor.rs +++ b/crates/shirabe/src/advisory/auditor.rs @@ -16,7 +16,7 @@ use shirabe_external_packages::composer::pcre::Preg; use shirabe_external_packages::symfony::console::formatter::OutputFormatter; use shirabe_php_shim::{ DATE_ATOM, InvalidArgumentException, PhpMixed, array_all, array_any, array_key_exists, - array_keys, array_reduce, get_class, sprintf, str_starts_with, + array_keys, array_reduce, get_class, str_starts_with, }; /// Shape of the `--format=json` audit output. @@ -198,22 +198,13 @@ impl Auditor { if affected_packages_count > 0 || !ignored_advisories.is_empty() { let passes: Vec<( &IndexMap<String, Vec<std::rc::Rc<AnySecurityAdvisory>>>, - String, + &str, + &str, )> = vec![ - ( - &ignored_advisories, - "<info>Found %d ignored security vulnerability advisor%s affecting %d package%s%s</info>" - .to_string(), - ), - ( - &advisories, - format!( - "<{ew}>Found %d security vulnerability advisor%s affecting %d package%s%s</{ew}>", - ew = error_or_warn - ), - ), + (&ignored_advisories, "info", "ignored "), + (&advisories, error_or_warn, ""), ]; - for (advisories_to_output, message) in passes { + for (advisories_to_output, tag, ignored) in passes { let (pkg_count, total_advisory_count) = self.count_advisories(advisories_to_output); if pkg_count > 0 { let plurality = if total_advisory_count == 1 { @@ -223,15 +214,8 @@ impl Auditor { }; let pkg_plurality = if pkg_count == 1 { "" } else { "s" }; let punctuation = if format == "summary" { "." } else { ":" }; - io.write_error(&sprintf( - &message, - &[ - PhpMixed::Int(total_advisory_count), - PhpMixed::String(plurality.to_string()), - PhpMixed::Int(pkg_count), - PhpMixed::String(pkg_plurality.to_string()), - PhpMixed::String(punctuation.to_string()), - ], + io.write_error(&format!( + "<{tag}>Found {total_advisory_count} {ignored}security vulnerability advisor{plurality} affecting {pkg_count} package{pkg_plurality}{punctuation}</{tag}>" )); self.output_advisories(io, advisories_to_output, format)?; } diff --git a/crates/shirabe/src/util/process_executor.rs b/crates/shirabe/src/util/process_executor.rs index 738da143..7e6011cd 100644 --- a/crates/shirabe/src/util/process_executor.rs +++ b/crates/shirabe/src/util/process_executor.rs @@ -15,9 +15,8 @@ use shirabe_external_packages::symfony::process::exception::ProcessSignaledExcep use shirabe_external_packages::symfony::process::exception::RuntimeException as SymfonyProcessRuntimeException; use shirabe_php_shim::{ LogicException, PHP_EOL, PhpMixed, RuntimeException, array_intersect, array_map, - call_user_func, escapeshellarg, explode, implode, in_array, is_array, is_dir, is_numeric, - is_string, php_regex, rtrim, sprintf, str_replace, strcspn, strlen, strpbrk, strtolower, - strtr_array, substr_replace, trim, + escapeshellarg, explode, implode, in_array, is_array, is_dir, is_numeric, is_string, php_regex, + rtrim, str_replace, strcspn, strlen, strpbrk, strtolower, strtr_array, substr_replace, trim, }; use std::sync::{LazyLock, Mutex}; @@ -1204,10 +1203,3 @@ impl ToTimeoutSeconds for PhpMixed { self.as_int().unwrap_or(0) } } - -// Suppress unused-import warnings. -#[allow(dead_code)] -const _USE_PARITY: () = { - let _ = call_user_func::<PhpMixed>; - let _ = sprintf; -}; |
