aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/shirabe-class-map-generator/src/class_map_generator.rs9
-rw-r--r--crates/shirabe/src/command/config_command.rs134
-rw-r--r--crates/shirabe/src/command/update_command.rs12
-rw-r--r--crates/shirabe/src/config.rs69
-rw-r--r--crates/shirabe/src/console/application.rs43
-rw-r--r--crates/shirabe/src/dependency_resolver/problem.rs20
-rw-r--r--crates/shirabe/src/downloader/file_downloader.rs15
-rw-r--r--crates/shirabe/src/package/alias_package.rs12
-rw-r--r--crates/shirabe/src/package/locker.rs20
-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
-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
16 files changed, 118 insertions, 342 deletions
diff --git a/crates/shirabe-class-map-generator/src/class_map_generator.rs b/crates/shirabe-class-map-generator/src/class_map_generator.rs
index 57a21508..9fa37246 100644
--- a/crates/shirabe-class-map-generator/src/class_map_generator.rs
+++ b/crates/shirabe-class-map-generator/src/class_map_generator.rs
@@ -73,14 +73,7 @@ impl ClassMapGenerator {
namespace: Option<String>,
excluded_dirs: Vec<String>,
) -> anyhow::Result<()> {
- if !in_array_strict(
- autoload_type.to_string(),
- &[
- PhpMixed::String("psr-0".to_string()),
- PhpMixed::String("psr-4".to_string()),
- PhpMixed::String("classmap".to_string()),
- ],
- ) {
+ if !matches!(autoload_type, "psr-0" | "psr-4" | "classmap") {
return Err(anyhow::anyhow!(InvalidArgumentException {
message: "$autoloadType must be one of: \"psr-0\", \"psr-4\" or \"classmap\""
.to_string(),
diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs
index 02e26582..c4409f20 100644
--- a/crates/shirabe/src/command/config_command.rs
+++ b/crates/shirabe/src/command/config_command.rs
@@ -525,15 +525,7 @@ impl Command for ConfigCommand {
let values: Vec<String> = setting_values; // what the user is trying to add/change
let boolean_validator = |val: &PhpMixed| -> bool {
- in_array_strict(
- val.as_string().unwrap_or(""),
- &[
- PhpMixed::String("true".to_string()),
- PhpMixed::String("false".to_string()),
- PhpMixed::String("1".to_string()),
- PhpMixed::String("0".to_string()),
- ],
- )
+ matches!(val.as_string().unwrap_or(""), "true" | "false" | "1" | "0")
};
let boolean_normalizer = |val: &PhpMixed| -> PhpMixed {
let s = val.as_string().unwrap_or("");
@@ -883,13 +875,8 @@ impl Command for ConfigCommand {
}
// handle unsetting extra/suggest
- if in_array_strict(
- setting_key.as_str(),
- &[
- PhpMixed::String("suggest".to_string()),
- PhpMixed::String("extra".to_string()),
- ],
- ) && input.borrow().get_option("unset")?.as_bool() == Some(true)
+ if matches!(setting_key.as_str(), "suggest" | "extra")
+ && input.borrow().get_option("unset")?.as_bool() == Some(true)
{
self.config_source
.borrow_mut()
@@ -944,12 +931,9 @@ impl Command for ConfigCommand {
}
// handle audit.ignore and audit.ignore-abandoned with --merge support
- if in_array_strict(
+ if matches!(
setting_key.as_str(),
- &[
- PhpMixed::String("audit.ignore".to_string()),
- PhpMixed::String("audit.ignore-abandoned".to_string()),
- ],
+ "audit.ignore" | "audit.ignore-abandoned"
) {
if input.borrow().get_option("unset")?.as_bool() == Some(true) {
self.config_source
@@ -1094,14 +1078,9 @@ impl Command for ConfigCommand {
.as_mut()
.unwrap()
.add_config_setting(&key, PhpMixed::Array(obj));
- } else if in_array_strict(
+ } else if matches!(
matches[1].as_str(),
- &[
- PhpMixed::String("github-oauth".to_string()),
- PhpMixed::String("gitlab-oauth".to_string()),
- PhpMixed::String("gitlab-token".to_string()),
- PhpMixed::String("bearer".to_string()),
- ],
+ "github-oauth" | "gitlab-oauth" | "gitlab-token" | "bearer"
) {
if 1 != values.len() {
return Err(RuntimeException {
@@ -1417,15 +1396,7 @@ impl ConfigCommand {
let raw_contents_arr = raw_contents.as_array().cloned().unwrap_or_default();
let mut k = k;
for (key, value) in &contents_arr {
- if k.is_none()
- && !in_array_strict(
- key.as_str(),
- &[
- PhpMixed::String("config".to_string()),
- PhpMixed::String("repositories".to_string()),
- ],
- )
- {
+ if k.is_none() && !matches!(key.as_str(), "config" | "repositories") {
continue;
}
@@ -1671,14 +1642,9 @@ pub type ValidatorFn = Box<dyn Fn(&PhpMixed) -> PhpMixed>;
pub type NormalizerFn = Box<dyn Fn(&PhpMixed) -> PhpMixed>;
fn boolean_validator(val: &PhpMixed) -> PhpMixed {
- PhpMixed::Bool(in_array_strict(
+ PhpMixed::Bool(matches!(
val.as_string().unwrap_or(""),
- &[
- PhpMixed::String("true".to_string()),
- PhpMixed::String("false".to_string()),
- PhpMixed::String("1".to_string()),
- PhpMixed::String("0".to_string()),
- ],
+ "true" | "false" | "1" | "0"
))
}
@@ -1715,13 +1681,9 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
"preferred-install".to_string(),
(
Box::new(|val| {
- PhpMixed::Bool(in_array_strict(
+ PhpMixed::Bool(matches!(
val.as_string().unwrap_or(""),
- &[
- PhpMixed::String("auto".to_string()),
- PhpMixed::String("source".to_string()),
- PhpMixed::String("dist".to_string()),
- ],
+ "auto" | "source" | "dist"
))
}),
Box::new(|val| val.clone()),
@@ -1731,13 +1693,9 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
"gitlab-protocol".to_string(),
(
Box::new(|val| {
- PhpMixed::Bool(in_array_strict(
+ PhpMixed::Bool(matches!(
val.as_string().unwrap_or(""),
- &[
- PhpMixed::String("git".to_string()),
- PhpMixed::String("http".to_string()),
- PhpMixed::String("https".to_string()),
- ],
+ "git" | "http" | "https"
))
}),
Box::new(|val| val.clone()),
@@ -1747,13 +1705,9 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
"store-auths".to_string(),
(
Box::new(|val| {
- PhpMixed::Bool(in_array_strict(
+ PhpMixed::Bool(matches!(
val.as_string().unwrap_or(""),
- &[
- PhpMixed::String("true".to_string()),
- PhpMixed::String("false".to_string()),
- PhpMixed::String("prompt".to_string()),
- ],
+ "true" | "false" | "prompt"
))
}),
Box::new(|val| {
@@ -1889,15 +1843,9 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
"discard-changes".to_string(),
(
Box::new(|val| {
- PhpMixed::Bool(in_array_strict(
+ PhpMixed::Bool(matches!(
val.as_string().unwrap_or(""),
- &[
- PhpMixed::String("stash".to_string()),
- PhpMixed::String("true".to_string()),
- PhpMixed::String("false".to_string()),
- PhpMixed::String("1".to_string()),
- PhpMixed::String("0".to_string()),
- ],
+ "stash" | "true" | "false" | "1" | "0"
))
}),
Box::new(|val| {
@@ -1959,16 +1907,9 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
"bump-after-update".to_string(),
(
Box::new(|val| {
- PhpMixed::Bool(in_array_strict(
+ PhpMixed::Bool(matches!(
val.as_string().unwrap_or(""),
- &[
- PhpMixed::String("dev".to_string()),
- PhpMixed::String("no-dev".to_string()),
- PhpMixed::String("true".to_string()),
- PhpMixed::String("false".to_string()),
- PhpMixed::String("1".to_string()),
- PhpMixed::String("0".to_string()),
- ],
+ "dev" | "no-dev" | "true" | "false" | "1" | "0"
))
}),
Box::new(|val| {
@@ -2037,15 +1978,9 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
"platform-check".to_string(),
(
Box::new(|val| {
- PhpMixed::Bool(in_array_strict(
+ PhpMixed::Bool(matches!(
val.as_string().unwrap_or(""),
- &[
- PhpMixed::String("php-only".to_string()),
- PhpMixed::String("true".to_string()),
- PhpMixed::String("false".to_string()),
- PhpMixed::String("1".to_string()),
- PhpMixed::String("0".to_string()),
- ],
+ "php-only" | "true" | "false" | "1" | "0"
))
}),
Box::new(|val| {
@@ -2062,13 +1997,9 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
"use-parent-dir".to_string(),
(
Box::new(|val| {
- PhpMixed::Bool(in_array_strict(
+ PhpMixed::Bool(matches!(
val.as_string().unwrap_or(""),
- &[
- PhpMixed::String("true".to_string()),
- PhpMixed::String("false".to_string()),
- PhpMixed::String("prompt".to_string()),
- ],
+ "true" | "false" | "prompt"
))
}),
Box::new(|val| {
@@ -2085,13 +2016,9 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
"audit.abandoned".to_string(),
(
Box::new(|val| {
- PhpMixed::Bool(in_array_strict(
+ PhpMixed::Bool(matches!(
val.as_string().unwrap_or(""),
- &[
- PhpMixed::String(Auditor::ABANDONED_IGNORE.to_string()),
- PhpMixed::String(Auditor::ABANDONED_REPORT.to_string()),
- PhpMixed::String(Auditor::ABANDONED_FAIL.to_string()),
- ],
+ Auditor::ABANDONED_IGNORE | Auditor::ABANDONED_REPORT | Auditor::ABANDONED_FAIL
))
}),
Box::new(|val| val.clone()),
@@ -2177,14 +2104,9 @@ fn build_multi_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
}
if let Some(list) = vals.as_list() {
for val in list {
- if !in_array_strict(
+ if !matches!(
val.as_string().unwrap_or(""),
- &[
- PhpMixed::String("low".to_string()),
- PhpMixed::String("medium".to_string()),
- PhpMixed::String("high".to_string()),
- PhpMixed::String("critical".to_string()),
- ],
+ "low" | "medium" | "high" | "critical"
) {
return PhpMixed::String(
"valid severities include: low, medium, high, critical".to_string(),
diff --git a/crates/shirabe/src/command/update_command.rs b/crates/shirabe/src/command/update_command.rs
index e9bf34a9..1885e8eb 100644
--- a/crates/shirabe/src/command/update_command.rs
+++ b/crates/shirabe/src/command/update_command.rs
@@ -34,8 +34,7 @@ use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
use shirabe_php_shim::{
InvalidArgumentException, PhpMixed, RuntimeException, array_filter, array_intersect,
- array_keys, array_merge_map, array_search_in_vec, impl_php_class, in_array_strict, php_regex,
- strtolower,
+ array_keys, array_merge_map, array_search_in_vec, impl_php_class, php_regex, strtolower,
};
use shirabe_semver::Intervals;
use shirabe_semver::constraint::MultiConstraint;
@@ -334,14 +333,7 @@ impl Command for UpdateCommand {
// the arguments lock/nothing/mirrors are not package names but trigger a mirror update instead
// they are further mutually exclusive with listing actual package names
let filtered_packages: Vec<String> = array_filter(&packages, |package: &String| -> bool {
- !in_array_strict(
- package.clone(),
- &[
- PhpMixed::String("lock".to_string()),
- PhpMixed::String("nothing".to_string()),
- PhpMixed::String("mirrors".to_string()),
- ],
- )
+ !matches!(package.as_str(), "lock" | "nothing" | "mirrors")
});
let update_mirrors = input
.borrow()
diff --git a/crates/shirabe/src/config.rs b/crates/shirabe/src/config.rs
index 5d0e1220..154fbd05 100644
--- a/crates/shirabe/src/config.rs
+++ b/crates/shirabe/src/config.rs
@@ -306,28 +306,24 @@ impl Config {
};
for (key, val_box) in &config_section_map {
let val = val_box.clone();
- if in_array_strict(
- key.clone(),
- &[
- PhpMixed::String("bitbucket-oauth".to_string()),
- PhpMixed::String("github-oauth".to_string()),
- PhpMixed::String("gitlab-oauth".to_string()),
- PhpMixed::String("gitlab-token".to_string()),
- PhpMixed::String("http-basic".to_string()),
- PhpMixed::String("bearer".to_string()),
- PhpMixed::String("client-certificate".to_string()),
- PhpMixed::String("forgejo-token".to_string()),
- ],
+ if matches!(
+ key.as_str(),
+ "bitbucket-oauth"
+ | "github-oauth"
+ | "gitlab-oauth"
+ | "gitlab-token"
+ | "http-basic"
+ | "bearer"
+ | "client-certificate"
+ | "forgejo-token"
) && self.config.contains_key(key)
{
let existing = self.config.get(key).cloned().unwrap_or(PhpMixed::Null);
self.config
.insert(key.clone(), array_merge(existing, val.clone()));
self.set_source_of_config_value(&val, key, source);
- } else if in_array_strict(
- key.clone(),
- &[PhpMixed::String("allow-plugins".to_string())],
- ) && self.config.contains_key(key)
+ } else if key == "allow-plugins"
+ && self.config.contains_key(key)
&& is_array(self.config.get(key).unwrap_or(&PhpMixed::Null))
&& is_array(&val)
{
@@ -339,13 +335,8 @@ impl Config {
array_merge(array_merge(val.clone(), existing), val.clone()),
);
self.set_source_of_config_value(&val, key, source);
- } else if in_array_strict(
- key.clone(),
- &[
- PhpMixed::String("gitlab-domains".to_string()),
- PhpMixed::String("github-domains".to_string()),
- ],
- ) && self.config.contains_key(key)
+ } else if matches!(key.as_str(), "gitlab-domains" | "github-domains")
+ && self.config.contains_key(key)
{
let existing = self.config.get(key).cloned().unwrap_or(PhpMixed::Null);
let merged = array_merge(existing, val.clone());
@@ -768,16 +759,7 @@ impl Config {
let env = self.get_composer_env("COMPOSER_DISCARD_CHANGES");
if !matches!(env, PhpMixed::Bool(false)) {
let env_str = env.as_string().unwrap_or("").to_string();
- if !in_array_strict(
- env_str.clone(),
- &[
- PhpMixed::String("stash".to_string()),
- PhpMixed::String("true".to_string()),
- PhpMixed::String("false".to_string()),
- PhpMixed::String("1".to_string()),
- PhpMixed::String("0".to_string()),
- ],
- ) {
+ if !matches!(env_str.as_str(), "stash" | "true" | "false" | "1" | "0") {
return Err(RuntimeException {
message: format!(
"Invalid value for COMPOSER_DISCARD_CHANGES: {}. Expected 1, 0, true, false or stash",
@@ -897,13 +879,7 @@ impl Config {
self.get_composer_env("COMPOSER_SECURITY_BLOCKING_ABANDONED");
if !matches!(block_abandoned_env, PhpMixed::Bool(false)) {
let env_str = block_abandoned_env.as_string().unwrap_or("").to_string();
- if !in_array_strict(
- env_str.clone(),
- &[
- PhpMixed::String("0".to_string()),
- PhpMixed::String("1".to_string()),
- ],
- ) {
+ if !matches!(env_str.as_str(), "0" | "1") {
return Err(RuntimeException {
message: format!(
"Invalid value for COMPOSER_SECURITY_BLOCKING_ABANDONED: {}. Expected 0 or 1.",
@@ -1083,18 +1059,7 @@ impl Config {
let hostname = parse_url(url, PHP_URL_HOST)
.as_string()
.map(|s| s.to_string());
- if in_array_strict(
- scheme
- .clone()
- .map(PhpMixed::String)
- .unwrap_or(PhpMixed::Null),
- &[
- PhpMixed::String("http".to_string()),
- PhpMixed::String("git".to_string()),
- PhpMixed::String("ftp".to_string()),
- PhpMixed::String("svn".to_string()),
- ],
- ) {
+ if matches!(scheme.as_deref(), Some("http" | "git" | "ftp" | "svn")) {
if self.get_with_flags("secure-http", 0)?.as_bool() == Some(true) {
if scheme.as_deref() == Some("svn") {
if in_array_strict(
diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs
index 5dff0e61..d6a287c2 100644
--- a/crates/shirabe/src/console/application.rs
+++ b/crates/shirabe/src/console/application.rs
@@ -97,10 +97,10 @@ use shirabe_php_shim::{
LogicException as ShimLogicException, PHP_VERSION, PHP_VERSION_ID, PhpMixed, RuntimeException,
bin2hex, chdir, date_default_timezone_get, date_default_timezone_set, defined, dirname,
disk_free_space, extension_loaded, file_exists, file_get_contents, file_put_contents,
- function_exists, getcwd, getmypid, glob, in_array_strict, ini_set, is_array, is_dir, is_file,
- is_string, is_subclass_of, json_decode, memory_get_peak_usage, memory_get_usage, microtime,
- php_regex, php_uname, posix_getuid, random_bytes, realpath, restore_error_handler, round,
- str_contains, str_replace, strpos, strtoupper, sys_get_temp_dir, time, unlink,
+ function_exists, getcwd, getmypid, glob, ini_set, is_array, is_dir, is_file, is_string,
+ is_subclass_of, json_decode, memory_get_peak_usage, memory_get_usage, microtime, php_regex,
+ php_uname, posix_getuid, random_bytes, realpath, restore_error_handler, round, str_contains,
+ str_replace, strpos, strtoupper, sys_get_temp_dir, time, unlink,
};
/// The PHP `Composer\Console\Application` and `Symfony\Component\Console\Application` are
@@ -2067,28 +2067,20 @@ impl ApplicationHandle {
}
// prompt user for dir change if no composer.json is present in current dir
- let no_composer_json_commands = vec![
- "".to_string(),
- "list".to_string(),
- "init".to_string(),
- "about".to_string(),
- "help".to_string(),
- "diagnose".to_string(),
- "self-update".to_string(),
- "global".to_string(),
- "create-project".to_string(),
- "outdated".to_string(),
- ];
let use_parent_dir_if_no_json_available =
application.borrow().get_use_parent_dir_config_value();
- let no_composer_json_commands_pm: Vec<PhpMixed> = no_composer_json_commands
- .iter()
- .map(|s| PhpMixed::String(s.clone()))
- .collect();
if new_work_dir.is_none()
- && !in_array_strict(
+ && !matches!(
command_name.as_deref().unwrap_or(""),
- &no_composer_json_commands_pm,
+ "" | "list"
+ | "init"
+ | "about"
+ | "help"
+ | "diagnose"
+ | "self-update"
+ | "global"
+ | "create-project"
+ | "outdated"
)
&& !file_exists(Factory::get_composer_file().unwrap_or_default())
&& use_parent_dir_if_no_json_available.as_bool() != Some(false)
@@ -2180,16 +2172,11 @@ impl ApplicationHandle {
// avoid loading plugins/initializing the Composer instance earlier than necessary if no plugin command is needed
// if showing the version, we never need plugin commands
- let mnp_list = vec![
- PhpMixed::String("".to_string()),
- PhpMixed::String("list".to_string()),
- PhpMixed::String("help".to_string()),
- ];
let may_need_plugin_command = !input
.borrow()
.has_parameter_option(PhpMixed::from(vec!["--version", "-V"]), false)
&& (command_name.is_none()
- || in_array_strict(command_name.as_deref().unwrap_or(""), &mnp_list)
+ || matches!(command_name.as_deref().unwrap_or(""), "" | "list" | "help")
|| (command_name.as_deref() == Some("_complete") && !is_non_allowed_root));
let may_need_script_command = may_need_plugin_command
diff --git a/crates/shirabe/src/dependency_resolver/problem.rs b/crates/shirabe/src/dependency_resolver/problem.rs
index b3da1e09..09adafea 100644
--- a/crates/shirabe/src/dependency_resolver/problem.rs
+++ b/crates/shirabe/src/dependency_resolver/problem.rs
@@ -13,8 +13,8 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::symfony::console::formatter::OutputFormatter;
use shirabe_php_shim::{
- LogicException, PhpMixed, defined, extension_loaded, implode, in_array_strict, loosely_compare,
- php_regex, phpversion, spl_object_hash, sprintf, str_replace, str_starts_with, stripos, strpos,
+ LogicException, PhpMixed, defined, extension_loaded, implode, loosely_compare, php_regex,
+ phpversion, spl_object_hash, sprintf, str_replace, str_starts_with, stripos, strpos,
strtolower, substr, substr_count, version_compare,
};
use shirabe_semver::constraint::AnyConstraint;
@@ -211,7 +211,6 @@ impl Problem {
let mut templates: IndexMap<String, IndexMap<String, IndexMap<String, String>>> =
IndexMap::new();
let parser = VersionParser::new();
- let deduplicatable_rule_types = [rule::RULE_PACKAGE_REQUIRES, rule::RULE_PACKAGE_CONFLICT];
for rule in rules {
let rule_ref = rule.borrow();
let mut message = rule_ref.get_pretty_string(
@@ -223,12 +222,9 @@ impl Problem {
learned_pool,
)?;
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- let matched = if in_array_strict(
+ let matched = if matches!(
rule_ref.get_reason(),
- &deduplicatable_rule_types
- .iter()
- .map(|t| PhpMixed::Int(*t))
- .collect::<Vec<_>>(),
+ rule::RULE_PACKAGE_REQUIRES | rule::RULE_PACKAGE_CONFLICT
) {
Preg::is_match3(
php_regex!(
@@ -964,13 +960,7 @@ impl Problem {
&& c.get_version() == "dev-master"
{
for candidate in &packages {
- if in_array_strict(
- candidate.get_version().to_string(),
- &[
- PhpMixed::String("dev-default".to_string()),
- PhpMixed::String("dev-main".to_string()),
- ],
- ) {
+ if matches!(candidate.get_version().as_str(), "dev-default" | "dev-main") {
suffix = format!(
" Perhaps dev-master was renamed to {}?",
candidate.get_pretty_version()
diff --git a/crates/shirabe/src/downloader/file_downloader.rs b/crates/shirabe/src/downloader/file_downloader.rs
index c6ee3a20..c5dfc5f7 100644
--- a/crates/shirabe/src/downloader/file_downloader.rs
+++ b/crates/shirabe/src/downloader/file_downloader.rs
@@ -28,8 +28,8 @@ use indexmap::IndexMap;
use shirabe_php_shim::{
DIRECTORY_SEPARATOR, InvalidArgumentException, PATHINFO_BASENAME, PATHINFO_EXTENSION,
PHP_URL_PATH, PhpMixed, RuntimeException, UnexpectedValueException, array_search, file_exists,
- filesize, get_class, hash, hash_file, in_array_strict, is_dir, is_executable, parse_url,
- pathinfo, realpath, rtrim, spl_object_hash, strlen, strpos, strtr, trim, umask, usleep,
+ filesize, get_class, hash, hash_file, is_dir, is_executable, parse_url, pathinfo, realpath,
+ rtrim, spl_object_hash, strlen, strpos, strtr, trim, umask, usleep,
};
use std::sync::{LazyLock, Mutex};
@@ -338,16 +338,7 @@ impl DownloaderInterface for FileDownloader {
if let Some(te) = e.downcast_ref::<TransportException>() {
// if we got an http response with a proper code, then requesting again will probably not help, abort
- if 0 != te.get_code()
- && !in_array_strict(
- te.get_code(),
- &[
- PhpMixed::Int(500),
- PhpMixed::Int(502),
- PhpMixed::Int(503),
- PhpMixed::Int(504),
- ],
- )
+ if 0 != te.get_code() && !matches!(te.get_code(), 500 | 502 | 503 | 504)
{
retries = 0;
}
diff --git a/crates/shirabe/src/package/alias_package.rs b/crates/shirabe/src/package/alias_package.rs
index fb775130..088cd6ab 100644
--- a/crates/shirabe/src/package/alias_package.rs
+++ b/crates/shirabe/src/package/alias_package.rs
@@ -11,7 +11,7 @@ use crate::repository::RepositoryInterfaceWeakHandle;
use chrono::{DateTime, Utc};
use indexmap::IndexMap;
use indexmap::IndexSet;
-use shirabe_php_shim::{LogicException, PhpMixed, in_array_strict};
+use shirabe_php_shim::{LogicException, PhpMixed};
use shirabe_semver::constraint::SimpleConstraint;
#[derive(Debug, Clone)]
@@ -131,13 +131,9 @@ impl AliasPackage {
pretty_version = self.alias_of.get_pretty_version();
}
- if in_array_strict(
- link_type.to_string(),
- &[
- PhpMixed::String(Link::TYPE_CONFLICT.to_string()),
- PhpMixed::String(Link::TYPE_PROVIDE.to_string()),
- PhpMixed::String(Link::TYPE_REPLACE.to_string()),
- ],
+ if matches!(
+ link_type,
+ Link::TYPE_CONFLICT | Link::TYPE_PROVIDE | Link::TYPE_REPLACE
) {
let mut new_links: Vec<Link> = vec![];
for link in links.values() {
diff --git a/crates/shirabe/src/package/locker.rs b/crates/shirabe/src/package/locker.rs
index 10350d78..a4d28861 100644
--- a/crates/shirabe/src/package/locker.rs
+++ b/crates/shirabe/src/package/locker.rs
@@ -29,7 +29,7 @@ use shirabe_external_packages::seld::json_lint::ParsingException;
use shirabe_php_shim::{
DATE_RFC3339, LogicException, PhpMixed, RuntimeException, array_intersect, array_keys,
array_map, array_merge, file_get_contents, filemtime, function_exists, hash, in_array_loose,
- in_array_strict, is_int, ksort, php_regex, realpath, strcmp, strtolower, touch2, trim, usort,
+ is_int, ksort, php_regex, realpath, strcmp, strtolower, touch2, trim, usort,
};
/// Reads/writes project lockfile (composer.lock).
@@ -476,18 +476,12 @@ impl Locker {
let aliases: Vec<IndexMap<String, PhpMixed>> = array_map(
|alias: &IndexMap<String, PhpMixed>| {
let mut alias = alias.clone();
- let version = alias
- .get("version")
- .and_then(|v| v.as_string())
- .unwrap_or("")
- .to_string();
- if in_array_strict(
- version,
- &[
- PhpMixed::String("dev-master".to_string()),
- PhpMixed::String("dev-trunk".to_string()),
- PhpMixed::String("dev-default".to_string()),
- ],
+ if matches!(
+ alias
+ .get("version")
+ .and_then(|v| v.as_string())
+ .unwrap_or(""),
+ "dev-master" | "dev-trunk" | "dev-default"
) {
alias.insert(
"version".to_string(),
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
}
}
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;
}