aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-class-map-generator/src
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-class-map-generator/src
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-class-map-generator/src')
-rw-r--r--crates/shirabe-class-map-generator/src/class_map_generator.rs2
-rw-r--r--crates/shirabe-class-map-generator/src/php_file_parser.rs23
2 files changed, 15 insertions, 10 deletions
diff --git a/crates/shirabe-class-map-generator/src/class_map_generator.rs b/crates/shirabe-class-map-generator/src/class_map_generator.rs
index f33c93c..391bee9 100644
--- a/crates/shirabe-class-map-generator/src/class_map_generator.rs
+++ b/crates/shirabe-class-map-generator/src/class_map_generator.rs
@@ -29,7 +29,7 @@ impl ClassMapGenerator {
.map(|w| preg_quote(w, None))
.collect();
let stream_wrappers_regex =
- sprintf("{^(?:%s)://}", &[PhpMixed::String(implode("|", &wrappers))]);
+ format!("{{^(?:{})://}}", PhpMixed::String(implode("|", &wrappers)));
ClassMapGenerator {
extensions,
diff --git a/crates/shirabe-class-map-generator/src/php_file_parser.rs b/crates/shirabe-class-map-generator/src/php_file_parser.rs
index d196f8b..84fb418 100644
--- a/crates/shirabe-class-map-generator/src/php_file_parser.rs
+++ b/crates/shirabe-class-map-generator/src/php_file_parser.rs
@@ -27,24 +27,29 @@ impl PhpFileParser {
// Use @ here instead of Silencer to actively suppress 'unhelpful' output
let contents = php_strip_whitespace(path);
if contents.is_empty() {
- let message: &str;
+ let message: String;
if !file_exists(path) {
- message = "File at \"%s\" does not exist, check your classmap definitions";
+ message = format!(
+ "File at \"{}\" does not exist, check your classmap definitions",
+ path
+ );
} else if !Self::is_readable(path) {
- message = "File at \"%s\" is not readable, check its permissions";
+ message = format!(
+ "File at \"{}\" is not readable, check its permissions",
+ path
+ );
} else if trim(file_get_contents(path).unwrap_or_default().as_str(), None).is_empty() {
// The input file was really empty and thus contains no classes
return Ok(vec![]);
} else {
- message =
- "File at \"%s\" could not be parsed as PHP, it may be binary or corrupted";
+ message = format!(
+ "File at \"{}\" could not be parsed as PHP, it may be binary or corrupted",
+ path
+ );
}
let error = error_get_last();
- let mut message = sprintf(
- message,
- &[shirabe_php_shim::PhpMixed::String(path.to_string())],
- );
+ let mut message = message;
if let Some(error) = error
&& let Some(err_msg) = error.get("message")
{