aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/repository
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-06 06:36:42 +0900
committernsfisis <nsfisis@gmail.com>2026-08-06 06:36:42 +0900
commit70e463708b461efd61a611061cfee0539d28645a (patch)
tree267066f1a6ac872d256de99a4ffafb1adf31f311 /crates/shirabe/src/repository
parent791ef1cd465597ff43dab4216c4b00e9e4160da8 (diff)
downloadphp-shirabe-70e463708b461efd61a611061cfee0539d28645a.tar.gz
php-shirabe-70e463708b461efd61a611061cfee0539d28645a.tar.zst
php-shirabe-70e463708b461efd61a611061cfee0539d28645a.zip
refactor: replace literal-list in_array_strict with matches!
Call sites whose haystack was an inline array of literals (or a local built solely to feed one) had to wrap both sides in PhpMixed just to compare, allocating a String per element on every call. matches! does the same test against the underlying &str/i64/Option directly, so the PhpMixed round trip and its .to_string()/.clone()/.iter().map() conversions are gone. Sites whose haystack is a runtime value or a named constant array are left on in_array_strict: inlining a named constant would duplicate its contents at the call site. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/repository')
-rw-r--r--crates/shirabe/src/repository/composer_repository.rs12
-rw-r--r--crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs6
-rw-r--r--crates/shirabe/src/repository/vcs/gitlab_driver.rs39
-rw-r--r--crates/shirabe/src/repository/vcs_repository.rs7
4 files changed, 18 insertions, 46 deletions
diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs
index 833be0af..59e1d520 100644
--- a/crates/shirabe/src/repository/composer_repository.rs
+++ b/crates/shirabe/src/repository/composer_repository.rs
@@ -40,8 +40,8 @@ use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_metadata_minifier::MetadataMinifier;
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PHP_EOL, PhpMixed, RuntimeException,
- UnexpectedValueException, extension_loaded, hash, http_build_query, in_array_strict,
- json_decode, parse_url_all, php_regex, realpath, strtolower, strtr, urlencode, var_export,
+ UnexpectedValueException, extension_loaded, hash, http_build_query, json_decode, parse_url_all,
+ php_regex, realpath, strtolower, strtr, urlencode, var_export,
};
use shirabe_semver::CompilingMatcher;
use shirabe_semver::constraint::AnyConstraint;
@@ -1441,13 +1441,7 @@ impl ComposerRepository {
if let Some(te) = e.downcast_ref::<TransportException>() {
let status_code = te.get_status_code();
if self.lazy_providers_url.is_some()
- && in_array_strict(
- match status_code {
- Some(c) => PhpMixed::Int(c),
- None => PhpMixed::Null,
- },
- &[PhpMixed::Int(404), PhpMixed::Int(499)],
- )
+ && matches!(status_code, Some(404 | 499))
{
let mut p: IndexMap<String, PhpMixed> = IndexMap::new();
p.insert("packages".to_string(), PhpMixed::Array(IndexMap::new()));
diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
index 6b62d818..8fe93018 100644
--- a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
+++ b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
@@ -18,8 +18,8 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_key_exists,
- array_search_mixed, extension_loaded, http_build_query_mixed, implode, in_array_strict,
- is_array, php_regex, strpos,
+ array_search_mixed, extension_loaded, http_build_query_mixed, implode, is_array, php_regex,
+ strpos,
};
#[derive(Debug)]
@@ -697,7 +697,7 @@ impl GitBitbucketDriver {
{
let te = &e;
let code = te.get_code();
- let in_set = in_array_strict(code, &[PhpMixed::Int(403), PhpMixed::Int(404)]);
+ let in_set = matches!(code, 403 | 404);
if in_set
|| (401 == code
&& strpos(te.get_message(), "Could not authenticate against")
diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs
index 8f49e8ef..5fe513f6 100644
--- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs
+++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs
@@ -18,8 +18,8 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_search_mixed,
- array_shift, ctype_alnum, empty, explode, extension_loaded, implode, in_array_loose,
- in_array_strict, is_array, is_string, ord, php_regex, strpos, strtolower,
+ array_shift, ctype_alnum, empty, explode, extension_loaded, implode, in_array_loose, is_array,
+ is_string, ord, php_regex, strpos, strtolower,
};
/// Driver for GitLab API, use the Git driver for local checkouts.
@@ -115,13 +115,7 @@ impl GitLabDriver {
.get(&CaptureKey::ByName("scheme".to_string()))
.cloned()
.unwrap_or_default();
- self.scheme = if in_array_strict(
- scheme_match.clone(),
- &[
- PhpMixed::String("https".to_string()),
- PhpMixed::String("http".to_string()),
- ],
- ) {
+ self.scheme = if matches!(scheme_match.as_str(), "https" | "http") {
scheme_match
} else if self
.inner
@@ -158,14 +152,7 @@ impl GitLabDriver {
.filter(|_| is_string(&protocol_value))
{
// https treated as a synonym for http.
- if !in_array_strict(
- protocol.to_string(),
- &[
- PhpMixed::String("git".to_string()),
- PhpMixed::String("http".to_string()),
- PhpMixed::String("https".to_string()),
- ],
- ) {
+ if !matches!(protocol, "git" | "http" | "https") {
return Err(RuntimeException {
message: "gitlab-protocol must be one of git, http.".to_string(),
code: 0,
@@ -601,18 +588,12 @@ impl GitLabDriver {
let bytes: Vec<char> = string.chars().collect();
for byte in &bytes {
let character = byte.to_string();
- let final_character = if !ctype_alnum(&character)
- && !in_array_strict(
- character.clone(),
- &[
- PhpMixed::String("-".to_string()),
- PhpMixed::String("_".to_string()),
- ],
- ) {
- format!("%{:02X}", ord(&character))
- } else {
- character
- };
+ let final_character =
+ if !ctype_alnum(&character) && !matches!(character.as_str(), "-" | "_") {
+ format!("%{:02X}", ord(&character))
+ } else {
+ character
+ };
encoded.push_str(&final_character);
}
diff --git a/crates/shirabe/src/repository/vcs_repository.rs b/crates/shirabe/src/repository/vcs_repository.rs
index c8790f81..521d7aea 100644
--- a/crates/shirabe/src/repository/vcs_repository.rs
+++ b/crates/shirabe/src/repository/vcs_repository.rs
@@ -29,7 +29,7 @@ use crate::util::Url;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
- InvalidArgumentException, PhpClass, PhpMixed, in_array_strict, php_regex, str_replace, strpos,
+ InvalidArgumentException, PhpClass, PhpMixed, php_regex, str_replace, strpos,
};
use shirabe_semver::constraint::SimpleConstraint;
@@ -1030,10 +1030,7 @@ impl VcsRepository {
}
fn should_rethrow_transport_exception(&self, e: &TransportException) -> bool {
- in_array_strict(
- e.get_code(),
- &[PhpMixed::Int(401), PhpMixed::Int(403), PhpMixed::Int(429)],
- ) || e.get_code() >= 500
+ matches!(e.get_code(), 401 | 403 | 429) || e.get_code() >= 500
}
}