diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-06 06:25:10 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-06 06:25:30 +0900 |
| commit | 791ef1cd465597ff43dab4216c4b00e9e4160da8 (patch) | |
| tree | ec6c3bc45f81576146325350faa6dcea638987b4 /crates/shirabe/src/repository | |
| parent | a86bbd67954f7bbc38bb09138edb335d82666526 (diff) | |
| download | php-shirabe-791ef1cd465597ff43dab4216c4b00e9e4160da8.tar.gz php-shirabe-791ef1cd465597ff43dab4216c4b00e9e4160da8.tar.zst php-shirabe-791ef1cd465597ff43dab4216c4b00e9e4160da8.zip | |
refactor(php-shim): split in_array into strict and loose variants
Diffstat (limited to 'crates/shirabe/src/repository')
7 files changed, 64 insertions, 96 deletions
diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs index c83ffcd9..833be0af 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, json_decode, - parse_url_all, php_regex, realpath, strtolower, strtr, urlencode, var_export, + UnexpectedValueException, extension_loaded, hash, http_build_query, in_array_strict, + 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,12 @@ 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( + && in_array_strict( match status_code { Some(c) => PhpMixed::Int(c), None => PhpMixed::Null, }, - &PhpMixed::List(vec![PhpMixed::Int(404), PhpMixed::Int(499)]), - true, + &[PhpMixed::Int(404), PhpMixed::Int(499)], ) { let mut p: IndexMap<String, PhpMixed> = IndexMap::new(); diff --git a/crates/shirabe/src/repository/filesystem_repository.rs b/crates/shirabe/src/repository/filesystem_repository.rs index 7ecd0664..47241bde 100644 --- a/crates/shirabe/src/repository/filesystem_repository.rs +++ b/crates/shirabe/src/repository/filesystem_repository.rs @@ -20,8 +20,8 @@ use crate::util::Platform; use indexmap::IndexMap; use shirabe_php_shim::{ Exception, InvalidArgumentException, LogicException, PhpMixed, UnexpectedValueException, - array_flip, dirname, get_class_err, get_debug_type, in_array, is_array, is_null, is_string, - ksort, realpath, str_repeat, usort, var_export, + array_flip, dirname, get_class_err, get_debug_type, in_array_strict, is_array, is_null, + is_string, ksort, realpath, str_repeat, usort, var_export, }; use shirabe_semver::constraint::AnyConstraint; @@ -281,17 +281,15 @@ impl FilesystemRepository { // only write to the files the names which are really installed, as we receive the full list // of dev package names before they get installed during composer install - if in_array( - PhpMixed::String(package.get_name().to_string()), - &PhpMixed::List( - self.inner - .dev_package_names - .borrow() - .iter() - .map(|s| PhpMixed::String(s.clone())) - .collect(), - ), - true, + if in_array_strict( + package.get_name().to_string(), + &self + .inner + .dev_package_names + .borrow() + .iter() + .map(|s| PhpMixed::String(s.clone())) + .collect::<Vec<_>>(), ) && let Some(PhpMixed::List(list)) = data.get_mut("dev-package-names") { list.push(PhpMixed::String(package.get_name().to_string())); diff --git a/crates/shirabe/src/repository/platform_repository.rs b/crates/shirabe/src/repository/platform_repository.rs index f0d8b46e..3f22954c 100644 --- a/crates/shirabe/src/repository/platform_repository.rs +++ b/crates/shirabe/src/repository/platform_repository.rs @@ -23,8 +23,8 @@ use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_external_packages::composer::xdebug_handler::XdebugHandler; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, UnexpectedValueException, array_map_str_fn, - array_slice_strs, explode, get_class, implode, in_array, is_string, php_regex, str_replace, - str_starts_with, strpos, strtolower, var_export, + array_slice_strs, explode, get_class, implode, in_array_strict, is_string, php_regex, + str_replace, str_starts_with, strpos, strtolower, var_export, }; use shirabe_semver::constraint::SimpleConstraint; use std::sync::{LazyLock, Mutex}; @@ -322,16 +322,12 @@ impl PlatformRepository { } // Check for Xdebug in a restarted process - if !in_array( - PhpMixed::String("xdebug".to_string()), - &PhpMixed::Array( - loaded_extensions - .iter() - .enumerate() - .map(|(i, s)| (i.to_string(), PhpMixed::String(s.clone()))) - .collect(), - ), - true, + if !in_array_strict( + "xdebug".to_string(), + &loaded_extensions + .iter() + .map(|s| PhpMixed::String(s.clone())) + .collect::<Vec<_>>(), ) && let Some(xdebug_pretty_version) = XdebugHandler::get_skipped_version() && !xdebug_pretty_version.is_empty() { diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs index 87cf7c44..6b62d818 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, is_array, - php_regex, strpos, + array_search_mixed, extension_loaded, http_build_query_mixed, implode, in_array_strict, + is_array, php_regex, strpos, }; #[derive(Debug)] @@ -697,11 +697,7 @@ impl GitBitbucketDriver { { let te = &e; let code = te.get_code(); - let in_set = in_array( - PhpMixed::Int(code), - &PhpMixed::List(vec![PhpMixed::Int(403), PhpMixed::Int(404)]), - true, - ); + let in_set = in_array_strict(code, &[PhpMixed::Int(403), PhpMixed::Int(404)]); if in_set || (401 == code && strpos(te.get_message(), "Could not authenticate against") diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs index c7b84e51..d656ae61 100644 --- a/crates/shirabe/src/repository/vcs/github_driver.rs +++ b/crates/shirabe/src/repository/vcs/github_driver.rs @@ -17,7 +17,7 @@ use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_php_shim::{ InvalidArgumentException, PhpMixed, RuntimeException, array_diff, array_key_exists, array_map, - array_search_mixed, base64_decode, basename, empty, explode, extension_loaded, in_array, + array_search_mixed, base64_decode, basename, empty, explode, extension_loaded, in_array_loose, parse_url_all, php_regex, strpos, strtolower, substr, trim, urlencode, }; @@ -966,14 +966,9 @@ impl GitHubDriver { .cloned() .unwrap_or_default() }); - if !in_array( - PhpMixed::String(strtolower(&Preg::replace( - php_regex!(r"{^www\.}i"), - "", - &origin_url, - ))), - &config.borrow().get("github-domains"), - false, + if !in_array_loose( + strtolower(&Preg::replace(php_regex!(r"{^www\.}i"), "", &origin_url)), + config.borrow().get("github-domains").values(), ) { return Ok(false); } diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs index 35d0b5ca..8f49e8ef 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, is_array, - is_string, ord, php_regex, strpos, strtolower, + array_shift, ctype_alnum, empty, explode, extension_loaded, implode, in_array_loose, + in_array_strict, is_array, is_string, ord, php_regex, strpos, strtolower, }; /// Driver for GitLab API, use the Git driver for local checkouts. @@ -115,13 +115,12 @@ impl GitLabDriver { .get(&CaptureKey::ByName("scheme".to_string())) .cloned() .unwrap_or_default(); - self.scheme = if in_array( - PhpMixed::String(scheme_match.clone()), - &PhpMixed::List(vec![ + self.scheme = if in_array_strict( + scheme_match.clone(), + &[ PhpMixed::String("https".to_string()), PhpMixed::String("http".to_string()), - ]), - true, + ], ) { scheme_match } else if self @@ -159,14 +158,13 @@ impl GitLabDriver { .filter(|_| is_string(&protocol_value)) { // https treated as a synonym for http. - if !in_array( - PhpMixed::String(protocol.to_string()), - &PhpMixed::List(vec![ + if !in_array_strict( + protocol.to_string(), + &[ PhpMixed::String("git".to_string()), PhpMixed::String("http".to_string()), PhpMixed::String("https".to_string()), - ]), - true, + ], ) { return Err(RuntimeException { message: "gitlab-protocol must be one of git, http.".to_string(), @@ -604,13 +602,12 @@ impl GitLabDriver { for byte in &bytes { let character = byte.to_string(); let final_character = if !ctype_alnum(&character) - && !in_array( - PhpMixed::String(character.clone()), - &PhpMixed::List(vec![ + && !in_array_strict( + character.clone(), + &[ PhpMixed::String("-".to_string()), PhpMixed::String("_".to_string()), - ]), - true, + ], ) { format!("%{:02X}", ord(&character)) } else { @@ -1066,20 +1063,16 @@ impl GitLabDriver { ) -> Option<String> { let mut guessed_domain = strtolower(&guessed_domain); - if in_array( - PhpMixed::String(guessed_domain.clone()), - configured_domains, - false, - ) || (port_number.is_some() - && in_array( - PhpMixed::String(format!( - "{}:{}", - guessed_domain, - port_number.as_deref().unwrap_or("") - )), - configured_domains, - false, - )) + if in_array_loose(guessed_domain.clone(), configured_domains.values()) + || (port_number.is_some() + && in_array_loose( + format!( + "{}:{}", + guessed_domain, + port_number.as_deref().unwrap_or("") + ), + configured_domains.values(), + )) { if let Some(ref port) = port_number { return Some(format!("{}:{}", guessed_domain, port)); @@ -1095,16 +1088,12 @@ impl GitLabDriver { while let Some(part) = array_shift(url_parts) { guessed_domain.push_str(&format!("/{}", part)); - if in_array( - PhpMixed::String(guessed_domain.clone()), - configured_domains, - false, - ) || (port_number.is_some() - && in_array( - PhpMixed::String(Preg::replace(php_regex!(r"{:\d+}"), "", &guessed_domain)), - configured_domains, - false, - )) + if in_array_loose(guessed_domain.clone(), configured_domains.values()) + || (port_number.is_some() + && in_array_loose( + Preg::replace(php_regex!(r"{:\d+}"), "", &guessed_domain), + configured_domains.values(), + )) { return Some(guessed_domain); } diff --git a/crates/shirabe/src/repository/vcs_repository.rs b/crates/shirabe/src/repository/vcs_repository.rs index 059d4dbd..c8790f81 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, php_regex, str_replace, strpos, + InvalidArgumentException, PhpClass, PhpMixed, in_array_strict, php_regex, str_replace, strpos, }; use shirabe_semver::constraint::SimpleConstraint; @@ -1030,14 +1030,9 @@ impl VcsRepository { } fn should_rethrow_transport_exception(&self, e: &TransportException) -> bool { - in_array( - PhpMixed::Int(e.get_code()), - &PhpMixed::List(vec![ - PhpMixed::Int(401), - PhpMixed::Int(403), - PhpMixed::Int(429), - ]), - true, + in_array_strict( + e.get_code(), + &[PhpMixed::Int(401), PhpMixed::Int(403), PhpMixed::Int(429)], ) || e.get_code() >= 500 } } |
