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) --- crates/shirabe/src/repository/vcs/github_driver.rs | 42 ++++++++++------------ 1 file changed, 18 insertions(+), 24 deletions(-) (limited to 'crates/shirabe/src/repository/vcs/github_driver.rs') diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs index aa1e135..5fb3439 100644 --- a/crates/shirabe/src/repository/vcs/github_driver.rs +++ b/crates/shirabe/src/repository/vcs/github_driver.rs @@ -82,9 +82,9 @@ impl GitHubDriver { .unwrap_or(false) { return Err(InvalidArgumentException { - message: sprintf( - "The GitHub repository URL %s is invalid.", - &[PhpMixed::String(self.inner.url.clone())], + message: format!( + "The GitHub repository URL {} is invalid.", + PhpMixed::String(self.inner.url.clone()), ), code: 0, } @@ -366,14 +366,12 @@ impl GitHubDriver { }) { support.insert( "source".to_string(), - Box::new(PhpMixed::String(sprintf( - "https://%s/%s/%s/tree/%s", - &[ - PhpMixed::String(self.inner.origin_url.clone()), - PhpMixed::String(self.owner.clone()), - PhpMixed::String(self.repository.clone()), - PhpMixed::String(label_str), - ], + Box::new(PhpMixed::String(format!( + "https://{}/{}/{}/tree/{}", + PhpMixed::String(self.inner.origin_url.clone()), + PhpMixed::String(self.owner.clone()), + PhpMixed::String(self.repository.clone()), + PhpMixed::String(label_str), ))), ); } @@ -390,13 +388,11 @@ impl GitHubDriver { }) { support.insert( "issues".to_string(), - Box::new(PhpMixed::String(sprintf( - "https://%s/%s/%s/issues", - &[ - PhpMixed::String(self.inner.origin_url.clone()), - PhpMixed::String(self.owner.clone()), - PhpMixed::String(self.repository.clone()), - ], + Box::new(PhpMixed::String(format!( + "https://{}/{}/{}/issues", + PhpMixed::String(self.inner.origin_url.clone()), + PhpMixed::String(self.owner.clone()), + PhpMixed::String(self.repository.clone()), ))), ); } @@ -1169,12 +1165,10 @@ impl GitHubDriver { e.get_headers().map(|h| h.as_slice()).unwrap_or(&[]), ); self.inner.io.write_error3( - &sprintf( - "GitHub API limit (%d calls/hr) is exhausted. You are already authorized so you have to wait until %s before doing more requests", - &[ - rate_limit.get("limit").cloned().unwrap_or(PhpMixed::Null), - rate_limit.get("reset").cloned().unwrap_or(PhpMixed::Null), - ], + &format!( + "GitHub API limit ({} calls/hr) is exhausted. You are already authorized so you have to wait until {} before doing more requests", + rate_limit.get("limit").cloned().unwrap_or(PhpMixed::Null), + rate_limit.get("reset").cloned().unwrap_or(PhpMixed::Null), ), true, io_interface::NORMAL, -- cgit v1.3.1