aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util
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/util
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/util')
-rw-r--r--crates/shirabe/src/util/auth_helper.rs28
-rw-r--r--crates/shirabe/src/util/http/curl_downloader.rs18
-rw-r--r--crates/shirabe/src/util/platform.rs16
3 files changed, 18 insertions, 44 deletions
diff --git a/crates/shirabe/src/util/auth_helper.rs b/crates/shirabe/src/util/auth_helper.rs
index 80852bb2..c779a1bb 100644
--- a/crates/shirabe/src/util/auth_helper.rs
+++ b/crates/shirabe/src/util/auth_helper.rs
@@ -249,13 +249,9 @@ impl AuthHelper {
.and_then(|a| a.get("password"))
.and_then(|v| v.clone())
.unwrap_or_default();
- if in_array_strict(
- password,
- &[
- PhpMixed::String("gitlab-ci-token".to_string()),
- PhpMixed::String("private-token".to_string()),
- PhpMixed::String("oauth2".to_string()),
- ],
+ if matches!(
+ password.as_str(),
+ "gitlab-ci-token" | "private-token" | "oauth2"
) {
return Err(TransportException::new(
format!("Invalid credentials for '{}', aborting.", url),
@@ -520,13 +516,9 @@ impl AuthHelper {
authentication_display_message =
Some("Using GitHub token authentication".to_string());
}
- } else if in_array_strict(
- password.clone(),
- &[
- PhpMixed::String("oauth2".to_string()),
- PhpMixed::String("private-token".to_string()),
- PhpMixed::String("gitlab-ci-token".to_string()),
- ],
+ } else if matches!(
+ password.as_str(),
+ "oauth2" | "private-token" | "gitlab-ci-token"
) && in_array_strict(origin.to_string(), &{
let gitlab_domains = self.config.borrow_mut().get("gitlab-domains");
match &gitlab_domains {
@@ -593,13 +585,7 @@ impl AuthHelper {
.insert(origin.to_string(), display_message.clone());
}
}
- } else if in_array_strict(
- origin.to_string(),
- &[
- PhpMixed::String("api.bitbucket.org".to_string()),
- PhpMixed::String("api.github.com".to_string()),
- ],
- ) {
+ } else if matches!(origin, "api.bitbucket.org" | "api.github.com") {
return self.add_authentication_options(options, &str_replace("api.", "", origin), url);
}
diff --git a/crates/shirabe/src/util/http/curl_downloader.rs b/crates/shirabe/src/util/http/curl_downloader.rs
index 64ff42a6..604dae77 100644
--- a/crates/shirabe/src/util/http/curl_downloader.rs
+++ b/crates/shirabe/src/util/http/curl_downloader.rs
@@ -413,13 +413,7 @@ impl CurlDownloader {
.and_then(|v| v.as_int())
.unwrap_or(0);
if Self::method_is_get(options)
- && in_array_strict(
- status_code,
- &[423, 425, 500, 502, 503, 504, 507, 510]
- .iter()
- .map(|c| PhpMixed::Int(*c))
- .collect::<Vec<_>>(),
- )
+ && matches!(status_code, 423 | 425 | 500 | 502 | 503 | 504 | 507 | 510)
&& retries < self.max_retries
{
self.io.write_error3(
@@ -820,16 +814,14 @@ impl CurlDownloader {
}
let mut details = String::new();
- if in_array_strict(
+ if matches!(
response
.inner
.get_header("content-type")
.unwrap_or_default()
- .to_lowercase(),
- &[
- PhpMixed::String("application/json".to_string()),
- PhpMixed::String("application/json; charset=utf-8".to_string()),
- ],
+ .to_lowercase()
+ .as_str(),
+ "application/json" | "application/json; charset=utf-8"
) {
let body = response.inner.get_body().unwrap_or("");
details = format!(
diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs
index 9ebf4f4f..a71fea92 100644
--- a/crates/shirabe/src/util/platform.rs
+++ b/crates/shirabe/src/util/platform.rs
@@ -5,10 +5,9 @@ use crate::util::Silencer;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
PHP_ENV, PHP_SERVER, PhpMixed, PhpResource, RuntimeException, defined, file_exists,
- file_get_contents, fstat, function_exists, getcwd, getenv, in_array_strict, ini_get, is_array,
- is_readable, mb_strlen, php_os_family, php_regex, posix_geteuid, posix_getpwuid, posix_getuid,
- posix_isatty, putenv, putenv_clear, realpath, stream_isatty, stripos, strlen, strtoupper,
- substr, usleep,
+ file_get_contents, fstat, function_exists, getcwd, getenv, ini_get, is_array, is_readable,
+ mb_strlen, php_os_family, php_regex, posix_geteuid, posix_getpwuid, posix_getuid, posix_isatty,
+ putenv, putenv_clear, realpath, stream_isatty, stripos, strlen, strtoupper, substr, usleep,
};
use std::sync::Mutex;
@@ -280,12 +279,9 @@ impl Platform {
// detect msysgit/mingw and assume this is a tty because detection
// does not work correctly, see https://github.com/composer/composer/issues/9690
- if in_array_strict(
- strtoupper(&Self::get_env("MSYSTEM").unwrap_or_default()),
- &[
- PhpMixed::String("MINGW32".to_string()),
- PhpMixed::String("MINGW64".to_string()),
- ],
+ if matches!(
+ strtoupper(&Self::get_env("MSYSTEM").unwrap_or_default()).as_str(),
+ "MINGW32" | "MINGW64"
) {
return true;
}