aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/repository
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/src/repository
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/src/repository')
-rw-r--r--crates/shirabe/src/repository/platform_repository.rs12
-rw-r--r--crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs206
-rw-r--r--crates/shirabe/src/repository/vcs/github_driver.rs42
-rw-r--r--crates/shirabe/src/repository/vcs/gitlab_driver.rs21
4 files changed, 128 insertions, 153 deletions
diff --git a/crates/shirabe/src/repository/platform_repository.rs b/crates/shirabe/src/repository/platform_repository.rs
index 932584c..d9954af 100644
--- a/crates/shirabe/src/repository/platform_repository.rs
+++ b/crates/shirabe/src/repository/platform_repository.rs
@@ -1342,13 +1342,11 @@ impl PlatformRepository {
.get_constant("RD_KAFKA_VERSION", None)
.as_int()
.unwrap_or(0);
- let version_built = sprintf(
- "%d.%d.%d",
- &[
- PhpMixed::Int((lib_rd_kafka_version_int & 0x7F000000) >> 24),
- PhpMixed::Int((lib_rd_kafka_version_int & 0x00FF0000) >> 16),
- PhpMixed::Int((lib_rd_kafka_version_int & 0x0000FF00) >> 8),
- ],
+ let version_built = format!(
+ "{}.{}.{}",
+ PhpMixed::Int((lib_rd_kafka_version_int & 0x7F000000) >> 24),
+ PhpMixed::Int((lib_rd_kafka_version_int & 0x00FF0000) >> 16),
+ PhpMixed::Int((lib_rd_kafka_version_int & 0x0000FF00) >> 8),
);
self.add_library(
&mut libraries,
diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
index b33aa05..9c285e0 100644
--- a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
+++ b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
@@ -95,9 +95,9 @@ impl GitBitbucketDriver {
.unwrap_or(false)
{
return Err(InvalidArgumentException {
- message: sprintf(
- "The Bitbucket repository URL %s is invalid. It must be the HTTPS URL of a Bitbucket repository.",
- &[PhpMixed::String(self.inner.url.clone())],
+ message: format!(
+ "The Bitbucket repository URL {} is invalid. It must be the HTTPS URL of a Bitbucket repository.",
+ PhpMixed::String(self.inner.url.clone()),
),
code: 0,
}
@@ -154,24 +154,22 @@ impl GitBitbucketDriver {
///
/// @phpstan-impure
fn get_repo_data(&mut self) -> Result<bool> {
- let resource = sprintf(
- "https://api.bitbucket.org/2.0/repositories/%s/%s?%s",
- &[
- PhpMixed::String(self.owner.clone()),
- PhpMixed::String(self.repository.clone()),
- PhpMixed::String(http_build_query_mixed(
- &{
- let mut m: IndexMap<String, PhpMixed> = IndexMap::new();
- m.insert(
- "fields".to_string(),
- PhpMixed::String("-project,-owner".to_string()),
- );
- m
- },
- "",
- "&",
- )),
- ],
+ let resource = format!(
+ "https://api.bitbucket.org/2.0/repositories/{}/{}?{}",
+ PhpMixed::String(self.owner.clone()),
+ PhpMixed::String(self.repository.clone()),
+ PhpMixed::String(http_build_query_mixed(
+ &{
+ let mut m: IndexMap<String, PhpMixed> = IndexMap::new();
+ m.insert(
+ "fields".to_string(),
+ PhpMixed::String("-project,-owner".to_string()),
+ );
+ m
+ },
+ "",
+ "&",
+ )),
);
let repo_data = self
@@ -358,28 +356,24 @@ impl GitBitbucketDriver {
if let PhpMixed::Array(support_map) = support_entry {
support_map.insert(
"source".to_string(),
- Box::new(PhpMixed::String(sprintf(
- "https://%s/%s/%s/src",
- &[
- PhpMixed::String(self.inner.origin_url.clone()),
- PhpMixed::String(self.owner.clone()),
- PhpMixed::String(self.repository.clone()),
- ],
+ Box::new(PhpMixed::String(format!(
+ "https://{}/{}/{}/src",
+ PhpMixed::String(self.inner.origin_url.clone()),
+ PhpMixed::String(self.owner.clone()),
+ PhpMixed::String(self.repository.clone()),
))),
);
}
} else if let PhpMixed::Array(support_map) = support_entry {
support_map.insert(
"source".to_string(),
- Box::new(PhpMixed::String(sprintf(
- "https://%s/%s/%s/src/%s/?at=%s",
- &[
- PhpMixed::String(self.inner.origin_url.clone()),
- PhpMixed::String(self.owner.clone()),
- PhpMixed::String(self.repository.clone()),
- PhpMixed::String(hash.unwrap()),
- PhpMixed::String(label.clone()),
- ],
+ Box::new(PhpMixed::String(format!(
+ "https://{}/{}/{}/src/{}/?at={}",
+ PhpMixed::String(self.inner.origin_url.clone()),
+ PhpMixed::String(self.owner.clone()),
+ PhpMixed::String(self.repository.clone()),
+ PhpMixed::String(hash.unwrap()),
+ PhpMixed::String(label.clone()),
))),
);
}
@@ -398,13 +392,11 @@ impl GitBitbucketDriver {
if let PhpMixed::Array(support_map) = support_entry {
support_map.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()),
))),
);
}
@@ -444,14 +436,12 @@ impl GitBitbucketDriver {
}
}
- let resource = sprintf(
- "https://api.bitbucket.org/2.0/repositories/%s/%s/src/%s/%s",
- &[
- PhpMixed::String(self.owner.clone()),
- PhpMixed::String(self.repository.clone()),
- PhpMixed::String(identifier),
- PhpMixed::String(file.to_string()),
- ],
+ let resource = format!(
+ "https://api.bitbucket.org/2.0/repositories/{}/{}/src/{}/{}",
+ PhpMixed::String(self.owner.clone()),
+ PhpMixed::String(self.repository.clone()),
+ PhpMixed::String(identifier),
+ PhpMixed::String(file.to_string()),
);
Ok(self
@@ -474,13 +464,11 @@ impl GitBitbucketDriver {
}
}
- let resource = sprintf(
- "https://api.bitbucket.org/2.0/repositories/%s/%s/commit/%s?fields=date",
- &[
- PhpMixed::String(self.owner.clone()),
- PhpMixed::String(self.repository.clone()),
- PhpMixed::String(identifier),
- ],
+ let resource = format!(
+ "https://api.bitbucket.org/2.0/repositories/{}/{}/commit/{}?fields=date",
+ PhpMixed::String(self.owner.clone()),
+ PhpMixed::String(self.repository.clone()),
+ PhpMixed::String(identifier),
);
let commit = self
.fetch_with_oauth_credentials(&resource, false)?
@@ -517,13 +505,11 @@ impl GitBitbucketDriver {
return fallback.get_dist(identifier).ok().flatten();
}
- let url = sprintf(
- "https://bitbucket.org/%s/%s/get/%s.zip",
- &[
- PhpMixed::String(self.owner.clone()),
- PhpMixed::String(self.repository.clone()),
- PhpMixed::String(identifier.to_string()),
- ],
+ let url = format!(
+ "https://bitbucket.org/{}/{}/get/{}.zip",
+ PhpMixed::String(self.owner.clone()),
+ PhpMixed::String(self.repository.clone()),
+ PhpMixed::String(identifier.to_string()),
);
let mut m: IndexMap<String, String> = IndexMap::new();
@@ -542,28 +528,26 @@ impl GitBitbucketDriver {
if self.tags.is_none() {
let mut tags: IndexMap<String, String> = IndexMap::new();
- let mut resource = sprintf(
- "%s?%s",
- &[
- PhpMixed::String(self.tags_url.clone()),
- PhpMixed::String(http_build_query_mixed(
- &{
- let mut m: IndexMap<String, PhpMixed> = IndexMap::new();
- m.insert("pagelen".to_string(), PhpMixed::Int(100));
- m.insert(
- "fields".to_string(),
- PhpMixed::String("values.name,values.target.hash,next".to_string()),
- );
- m.insert(
- "sort".to_string(),
- PhpMixed::String("-target.date".to_string()),
- );
- m
- },
- "",
- "&",
- )),
- ],
+ let mut resource = format!(
+ "{}?{}",
+ PhpMixed::String(self.tags_url.clone()),
+ PhpMixed::String(http_build_query_mixed(
+ &{
+ let mut m: IndexMap<String, PhpMixed> = IndexMap::new();
+ m.insert("pagelen".to_string(), PhpMixed::Int(100));
+ m.insert(
+ "fields".to_string(),
+ PhpMixed::String("values.name,values.target.hash,next".to_string()),
+ );
+ m.insert(
+ "sort".to_string(),
+ PhpMixed::String("-target.date".to_string()),
+ );
+ m
+ },
+ "",
+ "&",
+ )),
);
let mut has_next = true;
while has_next {
@@ -623,30 +607,28 @@ impl GitBitbucketDriver {
if self.branches.is_none() {
let mut branches: IndexMap<String, String> = IndexMap::new();
- let mut resource = sprintf(
- "%s?%s",
- &[
- PhpMixed::String(self.branches_url.clone()),
- PhpMixed::String(http_build_query_mixed(
- &{
- let mut m: IndexMap<String, PhpMixed> = IndexMap::new();
- m.insert("pagelen".to_string(), PhpMixed::Int(100));
- m.insert(
- "fields".to_string(),
- PhpMixed::String(
- "values.name,values.target.hash,values.heads,next".to_string(),
- ),
- );
- m.insert(
- "sort".to_string(),
- PhpMixed::String("-target.date".to_string()),
- );
- m
- },
- "",
- "&",
- )),
- ],
+ let mut resource = format!(
+ "{}?{}",
+ PhpMixed::String(self.branches_url.clone()),
+ PhpMixed::String(http_build_query_mixed(
+ &{
+ let mut m: IndexMap<String, PhpMixed> = IndexMap::new();
+ m.insert("pagelen".to_string(), PhpMixed::Int(100));
+ m.insert(
+ "fields".to_string(),
+ PhpMixed::String(
+ "values.name,values.target.hash,values.heads,next".to_string(),
+ ),
+ );
+ m.insert(
+ "sort".to_string(),
+ PhpMixed::String("-target.date".to_string()),
+ );
+ m
+ },
+ "",
+ "&",
+ )),
);
let mut has_next = true;
while has_next {
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(
- "<error>GitHub API limit (%d calls/hr) is exhausted. You are already authorized so you have to wait until %s before doing more requests</error>",
- &[
- rate_limit.get("limit").cloned().unwrap_or(PhpMixed::Null),
- rate_limit.get("reset").cloned().unwrap_or(PhpMixed::Null),
- ],
+ &format!(
+ "<error>GitHub API limit ({} calls/hr) is exhausted. You are already authorized so you have to wait until {} before doing more requests</error>",
+ rate_limit.get("limit").cloned().unwrap_or(PhpMixed::Null),
+ rate_limit.get("reset").cloned().unwrap_or(PhpMixed::Null),
),
true,
io_interface::NORMAL,
diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs
index 8ab30d4..bc47db8 100644
--- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs
+++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs
@@ -88,9 +88,9 @@ impl GitLabDriver {
.unwrap_or(false)
{
return Err(InvalidArgumentException {
- message: sprintf(
- "The GitLab repository URL %s is invalid. It must be the HTTP URL of a GitLab project.",
- &[PhpMixed::String(self.inner.url.clone())],
+ message: format!(
+ "The GitLab repository URL {} is invalid. It must be the HTTP URL of a GitLab project.",
+ PhpMixed::String(self.inner.url.clone()),
),
code: 0,
}
@@ -366,9 +366,10 @@ impl GitLabDriver {
}) {
support.insert(
"source".to_string(),
- Box::new(PhpMixed::String(sprintf(
- "%s/-/tree/%s",
- &[PhpMixed::String(web_url), PhpMixed::String(label_str)],
+ Box::new(PhpMixed::String(format!(
+ "{}/-/tree/{}",
+ PhpMixed::String(web_url),
+ PhpMixed::String(label_str),
))),
);
}
@@ -396,9 +397,9 @@ impl GitLabDriver {
}) {
support.insert(
"issues".to_string(),
- Box::new(PhpMixed::String(sprintf(
- "%s/-/issues",
- &[PhpMixed::String(web_url)],
+ Box::new(PhpMixed::String(format!(
+ "{}/-/issues",
+ PhpMixed::String(web_url),
))),
);
}
@@ -617,7 +618,7 @@ impl GitLabDriver {
]),
true,
) {
- format!("%{}", sprintf("%02X", &[PhpMixed::Int(ord(&character))]))
+ format!("%{}", format!("{:02X}", ord(&character)))
} else {
character
};