aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-06 06:25:10 +0900
committernsfisis <nsfisis@gmail.com>2026-08-06 06:25:30 +0900
commit791ef1cd465597ff43dab4216c4b00e9e4160da8 (patch)
treeec6c3bc45f81576146325350faa6dcea638987b4 /crates/shirabe
parenta86bbd67954f7bbc38bb09138edb335d82666526 (diff)
downloadphp-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')
-rw-r--r--crates/shirabe/src/command/audit_command.rs13
-rw-r--r--crates/shirabe/src/command/base_command.rs4
-rw-r--r--crates/shirabe/src/command/config_command.rs281
-rw-r--r--crates/shirabe/src/command/package_discovery_trait.rs32
-rw-r--r--crates/shirabe/src/command/search_command.rs11
-rw-r--r--crates/shirabe/src/command/show_command.rs84
-rw-r--r--crates/shirabe/src/command/suggests_command.rs4
-rw-r--r--crates/shirabe/src/command/update_command.rs11
-rw-r--r--crates/shirabe/src/config.rs85
-rw-r--r--crates/shirabe/src/console/application.rs27
-rw-r--r--crates/shirabe/src/dependency_resolver/pool_builder.rs18
-rw-r--r--crates/shirabe/src/dependency_resolver/problem.rs26
-rw-r--r--crates/shirabe/src/downloader/download_manager.rs17
-rw-r--r--crates/shirabe/src/downloader/file_downloader.rs13
-rw-r--r--crates/shirabe/src/downloader/git_downloader.rs6
-rw-r--r--crates/shirabe/src/io/base_io.rs50
-rw-r--r--crates/shirabe/src/io/console_io.rs4
-rw-r--r--crates/shirabe/src/json/json_manipulator.rs24
-rw-r--r--crates/shirabe/src/package/alias_package.rs11
-rw-r--r--crates/shirabe/src/package/locker.rs22
-rw-r--r--crates/shirabe/src/repository/composer_repository.rs9
-rw-r--r--crates/shirabe/src/repository/filesystem_repository.rs24
-rw-r--r--crates/shirabe/src/repository/platform_repository.rs20
-rw-r--r--crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs10
-rw-r--r--crates/shirabe/src/repository/vcs/github_driver.rs13
-rw-r--r--crates/shirabe/src/repository/vcs/gitlab_driver.rs71
-rw-r--r--crates/shirabe/src/repository/vcs_repository.rs13
-rw-r--r--crates/shirabe/src/util/auth_helper.rs60
-rw-r--r--crates/shirabe/src/util/git.rs29
-rw-r--r--crates/shirabe/src/util/github.rs8
-rw-r--r--crates/shirabe/src/util/gitlab.rs14
-rw-r--r--crates/shirabe/src/util/http/curl_downloader.rs50
-rw-r--r--crates/shirabe/src/util/platform.rs11
-rw-r--r--crates/shirabe/src/util/process_executor.rs20
-rw-r--r--crates/shirabe/src/util/url.rs18
35 files changed, 495 insertions, 618 deletions
diff --git a/crates/shirabe/src/command/audit_command.rs b/crates/shirabe/src/command/audit_command.rs
index 27d594e7..082afdc2 100644
--- a/crates/shirabe/src/command/audit_command.rs
+++ b/crates/shirabe/src/command/audit_command.rs
@@ -17,7 +17,8 @@ use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
use shirabe_php_shim::{
- InvalidArgumentException, PhpMixed, UnexpectedValueException, impl_php_class, implode, in_array,
+ InvalidArgumentException, PhpMixed, UnexpectedValueException, impl_php_class, implode,
+ in_array_strict,
};
#[derive(Debug)]
@@ -165,10 +166,12 @@ impl Command for AuditCommand {
.as_string()
.map(|s| s.to_string());
if abandoned.is_some()
- && !in_array(
- PhpMixed::String(abandoned.clone().unwrap()),
- &PhpMixed::from(Auditor::ABANDONEDS.to_vec()),
- true,
+ && !in_array_strict(
+ abandoned.clone().unwrap(),
+ &Auditor::ABANDONEDS
+ .iter()
+ .map(|s| PhpMixed::String(s.to_string()))
+ .collect::<Vec<_>>(),
)
{
return Err(InvalidArgumentException {
diff --git a/crates/shirabe/src/command/base_command.rs b/crates/shirabe/src/command/base_command.rs
index 41b8d0f8..7a66862e 100644
--- a/crates/shirabe/src/command/base_command.rs
+++ b/crates/shirabe/src/command/base_command.rs
@@ -28,7 +28,7 @@ use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpClass, PhpMixed, RuntimeException,
- UnexpectedValueException, count, explode, in_array, is_string,
+ UnexpectedValueException, count, explode, in_array_strict, is_string,
};
pub const SUCCESS: i64 = 0;
@@ -663,7 +663,7 @@ impl BaseCommand for BaseCommandData {
.iter()
.map(|s| PhpMixed::String(s.to_string()))
.collect();
- if !in_array(val.clone(), &PhpMixed::List(formats), true) {
+ if !in_array_strict(val.clone(), &formats) {
return Err(InvalidArgumentException {
message: format!(
"--{} must be one of {}.",
diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs
index 129b6614..02e26582 100644
--- a/crates/shirabe/src/command/config_command.rs
+++ b/crates/shirabe/src/command/config_command.rs
@@ -24,9 +24,9 @@ use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
use shirabe_php_shim::{
InvalidArgumentException, PhpMixed, RuntimeException, array_is_list, array_merge,
- escapeshellcmd, exec, explode, file_exists, impl_php_class, implode, in_array, is_array,
- is_bool, is_dir, is_numeric, is_object, is_string, json_encode, php_regex, str_replace, strpos,
- strtolower, system, touch, var_export,
+ escapeshellcmd, exec, explode, file_exists, impl_php_class, implode, in_array_loose,
+ in_array_strict, is_array, is_bool, is_dir, is_numeric, is_object, is_string, json_encode,
+ php_regex, str_replace, strpos, strtolower, system, touch, var_export,
};
use shirabe_semver::VersionParser;
@@ -470,7 +470,13 @@ impl Command for ConfigCommand {
.as_array()
.and_then(|a| a.get(&setting_key))
.is_some()
- && in_array(setting_key.as_str().into(), &properties.into(), true)
+ && in_array_strict(
+ setting_key.as_str(),
+ &properties
+ .iter()
+ .map(|s| PhpMixed::String(s.to_string()))
+ .collect::<Vec<_>>(),
+ )
{
value = raw_data
.as_array()
@@ -519,16 +525,14 @@ 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(
- val.as_string().unwrap_or("").into(),
- &vec![
- "true".to_string(),
- "false".to_string(),
- "1".to_string(),
- "0".to_string(),
- ]
- .into(),
- true,
+ 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()),
+ ],
)
};
let boolean_normalizer = |val: &PhpMixed| -> PhpMixed {
@@ -879,10 +883,12 @@ impl Command for ConfigCommand {
}
// handle unsetting extra/suggest
- if in_array(
- setting_key.as_str().into(),
- &vec!["suggest".to_string(), "extra".to_string()].into(),
- true,
+ 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)
{
self.config_source
@@ -938,14 +944,12 @@ impl Command for ConfigCommand {
}
// handle audit.ignore and audit.ignore-abandoned with --merge support
- if in_array(
- setting_key.as_str().into(),
- &vec![
- "audit.ignore".to_string(),
- "audit.ignore-abandoned".to_string(),
- ]
- .into(),
- true,
+ if in_array_strict(
+ setting_key.as_str(),
+ &[
+ PhpMixed::String("audit.ignore".to_string()),
+ PhpMixed::String("audit.ignore-abandoned".to_string()),
+ ],
) {
if input.borrow().get_option("unset")?.as_bool() == Some(true) {
self.config_source
@@ -1090,16 +1094,14 @@ impl Command for ConfigCommand {
.as_mut()
.unwrap()
.add_config_setting(&key, PhpMixed::Array(obj));
- } else if in_array(
- matches[1].as_str().into(),
- &vec![
- "github-oauth".to_string(),
- "gitlab-oauth".to_string(),
- "gitlab-token".to_string(),
- "bearer".to_string(),
- ]
- .into(),
- true,
+ } else if in_array_strict(
+ 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()),
+ ],
) {
if 1 != values.len() {
return Err(RuntimeException {
@@ -1416,10 +1418,12 @@ impl ConfigCommand {
let mut k = k;
for (key, value) in &contents_arr {
if k.is_none()
- && !in_array(
- key.as_str().into(),
- &vec!["config".to_string(), "repositories".to_string()].into(),
- true,
+ && !in_array_strict(
+ key.as_str(),
+ &[
+ PhpMixed::String("config".to_string()),
+ PhpMixed::String("repositories".to_string()),
+ ],
)
{
continue;
@@ -1667,16 +1671,14 @@ 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(
- val.as_string().unwrap_or("").into(),
- &vec![
- "true".to_string(),
- "false".to_string(),
- "1".to_string(),
- "0".to_string(),
- ]
- .into(),
- true,
+ 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()),
+ ],
))
}
@@ -1713,10 +1715,13 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
"preferred-install".to_string(),
(
Box::new(|val| {
- PhpMixed::Bool(in_array(
- val.as_string().unwrap_or("").into(),
- &vec!["auto".to_string(), "source".to_string(), "dist".to_string()].into(),
- true,
+ PhpMixed::Bool(in_array_strict(
+ val.as_string().unwrap_or(""),
+ &[
+ PhpMixed::String("auto".to_string()),
+ PhpMixed::String("source".to_string()),
+ PhpMixed::String("dist".to_string()),
+ ],
))
}),
Box::new(|val| val.clone()),
@@ -1726,10 +1731,13 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
"gitlab-protocol".to_string(),
(
Box::new(|val| {
- PhpMixed::Bool(in_array(
- val.as_string().unwrap_or("").into(),
- &vec!["git".to_string(), "http".to_string(), "https".to_string()].into(),
- true,
+ PhpMixed::Bool(in_array_strict(
+ val.as_string().unwrap_or(""),
+ &[
+ PhpMixed::String("git".to_string()),
+ PhpMixed::String("http".to_string()),
+ PhpMixed::String("https".to_string()),
+ ],
))
}),
Box::new(|val| val.clone()),
@@ -1739,15 +1747,13 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
"store-auths".to_string(),
(
Box::new(|val| {
- PhpMixed::Bool(in_array(
- val.as_string().unwrap_or("").into(),
- &vec![
- "true".to_string(),
- "false".to_string(),
- "prompt".to_string(),
- ]
- .into(),
- true,
+ PhpMixed::Bool(in_array_strict(
+ val.as_string().unwrap_or(""),
+ &[
+ PhpMixed::String("true".to_string()),
+ PhpMixed::String("false".to_string()),
+ PhpMixed::String("prompt".to_string()),
+ ],
))
}),
Box::new(|val| {
@@ -1866,16 +1872,14 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
"bin-compat".to_string(),
(
Box::new(|val| {
- PhpMixed::Bool(in_array(
- val.as_string().unwrap_or("").into(),
- &vec![
- "auto".to_string(),
- "full".to_string(),
- "proxy".to_string(),
- "symlink".to_string(),
- ]
- .into(),
- false,
+ PhpMixed::Bool(in_array_loose(
+ val.as_string().unwrap_or(""),
+ &[
+ PhpMixed::String("auto".to_string()),
+ PhpMixed::String("full".to_string()),
+ PhpMixed::String("proxy".to_string()),
+ PhpMixed::String("symlink".to_string()),
+ ],
))
}),
Box::new(|val| val.clone()),
@@ -1885,17 +1889,15 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
"discard-changes".to_string(),
(
Box::new(|val| {
- PhpMixed::Bool(in_array(
- val.as_string().unwrap_or("").into(),
- &vec![
- "stash".to_string(),
- "true".to_string(),
- "false".to_string(),
- "1".to_string(),
- "0".to_string(),
- ]
- .into(),
- true,
+ PhpMixed::Bool(in_array_strict(
+ 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()),
+ ],
))
}),
Box::new(|val| {
@@ -1957,18 +1959,16 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
"bump-after-update".to_string(),
(
Box::new(|val| {
- PhpMixed::Bool(in_array(
- val.as_string().unwrap_or("").into(),
- &vec![
- "dev".to_string(),
- "no-dev".to_string(),
- "true".to_string(),
- "false".to_string(),
- "1".to_string(),
- "0".to_string(),
- ]
- .into(),
- true,
+ PhpMixed::Bool(in_array_strict(
+ 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()),
+ ],
))
}),
Box::new(|val| {
@@ -2037,17 +2037,15 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
"platform-check".to_string(),
(
Box::new(|val| {
- PhpMixed::Bool(in_array(
- val.as_string().unwrap_or("").into(),
- &vec![
- "php-only".to_string(),
- "true".to_string(),
- "false".to_string(),
- "1".to_string(),
- "0".to_string(),
- ]
- .into(),
- true,
+ PhpMixed::Bool(in_array_strict(
+ 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()),
+ ],
))
}),
Box::new(|val| {
@@ -2064,15 +2062,13 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
"use-parent-dir".to_string(),
(
Box::new(|val| {
- PhpMixed::Bool(in_array(
- val.as_string().unwrap_or("").into(),
- &vec![
- "true".to_string(),
- "false".to_string(),
- "prompt".to_string(),
- ]
- .into(),
- true,
+ PhpMixed::Bool(in_array_strict(
+ val.as_string().unwrap_or(""),
+ &[
+ PhpMixed::String("true".to_string()),
+ PhpMixed::String("false".to_string()),
+ PhpMixed::String("prompt".to_string()),
+ ],
))
}),
Box::new(|val| {
@@ -2089,15 +2085,13 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
"audit.abandoned".to_string(),
(
Box::new(|val| {
- PhpMixed::Bool(in_array(
- val.as_string().unwrap_or("").into(),
- &vec![
- Auditor::ABANDONED_IGNORE.to_string(),
- Auditor::ABANDONED_REPORT.to_string(),
- Auditor::ABANDONED_FAIL.to_string(),
- ]
- .into(),
- true,
+ PhpMixed::Bool(in_array_strict(
+ 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()),
+ ],
))
}),
Box::new(|val| val.clone()),
@@ -2131,10 +2125,13 @@ fn build_multi_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
}
if let Some(list) = vals.as_list() {
for val in list {
- if !in_array(
- val.as_string().unwrap_or("").into(),
- &vec!["git".to_string(), "https".to_string(), "ssh".to_string()].into(),
- false,
+ if !in_array_loose(
+ val.as_string().unwrap_or(""),
+ &[
+ PhpMixed::String("git".to_string()),
+ PhpMixed::String("https".to_string()),
+ PhpMixed::String("ssh".to_string()),
+ ],
) {
return PhpMixed::String(
"valid protocols include: git, https, ssh".to_string(),
@@ -2180,16 +2177,14 @@ fn build_multi_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
}
if let Some(list) = vals.as_list() {
for val in list {
- if !in_array(
- val.as_string().unwrap_or("").into(),
- &vec![
- "low".to_string(),
- "medium".to_string(),
- "high".to_string(),
- "critical".to_string(),
- ]
- .into(),
- true,
+ if !in_array_strict(
+ 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()),
+ ],
) {
return PhpMixed::String(
"valid severities include: low, medium, high, critical".to_string(),
diff --git a/crates/shirabe/src/command/package_discovery_trait.rs b/crates/shirabe/src/command/package_discovery_trait.rs
index a1faff35..5c921e95 100644
--- a/crates/shirabe/src/command/package_discovery_trait.rs
+++ b/crates/shirabe/src/command/package_discovery_trait.rs
@@ -24,7 +24,7 @@ use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
use shirabe_php_shim::{
Exception, InvalidArgumentException, LogicException, PHP_EOL, PhpMixed, array_keys,
- array_slice, asort, explode, file_get_contents, implode, in_array, is_array, is_file,
+ array_slice, asort, explode, file_get_contents, implode, in_array_strict, is_array, is_file,
is_numeric, json_decode, levenshtein, php_regex, strlen, strpos, trim,
};
@@ -239,15 +239,12 @@ pub trait PackageDiscoveryTrait: BaseCommand {
if !matches.is_empty() {
// Remove existing packages from search results.
matches.retain(|found_package| {
- !in_array(
- PhpMixed::String(found_package.name.clone()),
- &PhpMixed::List(
- existing_packages
- .iter()
- .map(|s| PhpMixed::String(s.clone()))
- .collect(),
- ),
- true,
+ !in_array_strict(
+ found_package.name.clone(),
+ &existing_packages
+ .iter()
+ .map(|s| PhpMixed::String(s.clone()))
+ .collect::<Vec<_>>(),
)
});
// PHP: $matches = array_values($matches); — already a Vec in Rust
@@ -661,15 +658,12 @@ pub trait PackageDiscoveryTrait: BaseCommand {
// Check for similar names/typos
let similar = self.find_similar(name)?;
if !similar.is_empty() {
- if in_array(
- PhpMixed::String(name.to_string()),
- &PhpMixed::List(
- similar
- .iter()
- .map(|s| PhpMixed::String(s.clone()))
- .collect(),
- ),
- true,
+ if in_array_strict(
+ name.to_string(),
+ &similar
+ .iter()
+ .map(|s| PhpMixed::String(s.clone()))
+ .collect::<Vec<_>>(),
) {
return Err(InvalidArgumentException {
message: format!(
diff --git a/crates/shirabe/src/command/search_command.rs b/crates/shirabe/src/command/search_command.rs
index b0eabf80..0b675109 100644
--- a/crates/shirabe/src/command/search_command.rs
+++ b/crates/shirabe/src/command/search_command.rs
@@ -19,7 +19,7 @@ use shirabe_external_packages::symfony::console::formatter::OutputFormatter;
use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
use shirabe_php_shim::{
- InvalidArgumentException, PhpMixed, impl_php_class, implode, in_array, preg_quote, substr,
+ InvalidArgumentException, PhpMixed, impl_php_class, implode, in_array_loose, preg_quote, substr,
};
#[derive(Debug)]
@@ -120,13 +120,12 @@ impl Command for SearchCommand {
.as_string()
.map(|s| s.to_string())
.unwrap_or_else(|| "text".to_string());
- if !in_array(
- PhpMixed::String(format.clone()),
- &PhpMixed::List(vec![
+ if !in_array_loose(
+ format.clone(),
+ &[
PhpMixed::String("text".to_string()),
PhpMixed::String("json".to_string()),
- ]),
- false,
+ ],
) {
io.write_error(&format!(
"Unsupported format \"{}\". See help for supported formats.",
diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs
index 77d81858..fb663d86 100644
--- a/crates/shirabe/src/command/show_command.rs
+++ b/crates/shirabe/src/command/show_command.rs
@@ -44,8 +44,8 @@ use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
use shirabe_php_shim::{
DATE_ATOM, InvalidArgumentException, LogicException, PhpMixed, UnexpectedValueException,
- array_search, date, date_format_to_strftime, extension_loaded, impl_php_class, in_array,
- php_regex, realpath, strtolower, version_compare,
+ array_search, date, date_format_to_strftime, extension_loaded, impl_php_class, in_array_loose,
+ in_array_strict, php_regex, realpath, strtolower, version_compare,
};
use shirabe_semver::Semver;
use shirabe_semver::constraint::AnyConstraint;
@@ -303,13 +303,12 @@ impl Command for ShowCommand {
.as_string()
.unwrap_or("text")
.to_string();
- if !in_array(
- PhpMixed::String(format.clone()),
- &PhpMixed::List(vec![
+ if !in_array_loose(
+ format.clone(),
+ &[
PhpMixed::String("text".to_string()),
PhpMixed::String("json".to_string()),
- ]),
- false,
+ ],
) {
self.get_io().write_error(&format!(
"Unsupported format \"{}\". See help for supported formats.",
@@ -628,15 +627,13 @@ impl Command for ShowCommand {
if let Some(ref pkg) = matched_package
&& input.borrow().get_option("direct")?.as_bool() == Some(true)
- && !in_array(
- PhpMixed::String(pkg.get_name()),
- &PhpMixed::List(
- self.get_root_requires()
- .into_iter()
- .map(PhpMixed::String)
- .collect(),
- ),
- true,
+ && !in_array_strict(
+ pkg.get_name(),
+ &self
+ .get_root_requires()
+ .into_iter()
+ .map(PhpMixed::String)
+ .collect::<Vec<_>>(),
)
{
return Err(InvalidArgumentException {
@@ -798,15 +795,12 @@ impl Command for ShowCommand {
});
let mut array_tree: Vec<IndexMap<String, PhpMixed>> = Vec::new();
for package in packages.iter() {
- if in_array(
- PhpMixed::String(package.get_name()),
- &PhpMixed::List(
- root_requires
- .iter()
- .map(|s| PhpMixed::String(s.clone()))
- .collect(),
- ),
- true,
+ if in_array_strict(
+ package.get_name(),
+ &root_requires
+ .iter()
+ .map(|s| PhpMixed::String(s.clone()))
+ .collect::<Vec<_>>(),
) {
array_tree.push(self.generate_package_tree(
package.clone(),
@@ -911,12 +905,12 @@ impl Command for ShowCommand {
if matches_filter {
let matches_list = match &package_list_filter {
None => true,
- Some(list) => in_array(
- PhpMixed::String(p.get_name()),
- &PhpMixed::List(
- list.iter().map(|s| PhpMixed::String(s.clone())).collect(),
- ),
- true,
+ Some(list) => in_array_strict(
+ p.get_name(),
+ &list
+ .iter()
+ .map(|s| PhpMixed::String(s.clone()))
+ .collect::<Vec<_>>(),
),
};
if matches_list {
@@ -1075,15 +1069,13 @@ impl Command for ShowCommand {
);
package_view_data.insert(
"direct-dependency".to_string(),
- PhpMixed::Bool(in_array(
- PhpMixed::String(package.get_name()),
- &PhpMixed::List(
- self.get_root_requires()
- .into_iter()
- .map(PhpMixed::String)
- .collect(),
- ),
- true,
+ PhpMixed::Bool(in_array_strict(
+ package.get_name(),
+ &self
+ .get_root_requires()
+ .into_iter()
+ .map(PhpMixed::String)
+ .collect::<Vec<_>>(),
)),
);
if format != "json"
@@ -2581,11 +2573,7 @@ impl ShowCommand {
.unwrap_or("")
.to_string();
- let circular_warn = if in_array(
- PhpMixed::String(require_name.clone()),
- &PhpMixed::List(current_tree.to_vec()),
- true,
- ) {
+ let circular_warn = if in_array_strict(require_name.clone(), &current_tree) {
"(circular dependency aborted here)"
} else {
""
@@ -2635,11 +2623,7 @@ impl ShowCommand {
PhpMixed::String(require.get_pretty_constraint().to_string()),
);
- if !in_array(
- PhpMixed::String(require_name.clone()),
- &PhpMixed::List(current_tree.to_vec()),
- true,
- ) {
+ if !in_array_strict(require_name.clone(), &current_tree) {
current_tree.push(PhpMixed::String(require_name.clone()));
let deep_children = self.add_tree(
require_name,
diff --git a/crates/shirabe/src/command/suggests_command.rs b/crates/shirabe/src/command/suggests_command.rs
index 89df4546..5c73da9b 100644
--- a/crates/shirabe/src/command/suggests_command.rs
+++ b/crates/shirabe/src/command/suggests_command.rs
@@ -15,7 +15,7 @@ use indexmap::IndexMap;
use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
-use shirabe_php_shim::{PhpMixed, empty, impl_php_class, in_array};
+use shirabe_php_shim::{PhpMixed, empty, impl_php_class, in_array_loose};
#[derive(Debug)]
pub struct SuggestsCommand {
@@ -169,7 +169,7 @@ impl Command for SuggestsCommand {
composer.get_package().clone().into();
packages.push(root_pkg_as_base);
for package in &packages {
- if !empty(&filter) && !in_array(PhpMixed::String(package.get_name()), &filter, false) {
+ if !empty(&filter) && !in_array_loose(package.get_name(), filter.values()) {
continue;
}
reporter.add_suggestions_from_package(package.clone());
diff --git a/crates/shirabe/src/command/update_command.rs b/crates/shirabe/src/command/update_command.rs
index e5602763..e9bf34a9 100644
--- a/crates/shirabe/src/command/update_command.rs
+++ b/crates/shirabe/src/command/update_command.rs
@@ -34,7 +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, php_regex,
+ array_keys, array_merge_map, array_search_in_vec, impl_php_class, in_array_strict, php_regex,
strtolower,
};
use shirabe_semver::Intervals;
@@ -334,14 +334,13 @@ 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(
- PhpMixed::String(package.clone()),
- &PhpMixed::List(vec![
+ !in_array_strict(
+ package.clone(),
+ &[
PhpMixed::String("lock".to_string()),
PhpMixed::String("nothing".to_string()),
PhpMixed::String("mirrors".to_string()),
- ]),
- true,
+ ],
)
});
let update_mirrors = input
diff --git a/crates/shirabe/src/config.rs b/crates/shirabe/src/config.rs
index f33aa24e..5d0e1220 100644
--- a/crates/shirabe/src/config.rs
+++ b/crates/shirabe/src/config.rs
@@ -11,9 +11,9 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
E_USER_DEPRECATED, PHP_URL_HOST, PHP_URL_SCHEME, PhpMixed, RuntimeException, array_key_exists,
- array_merge, array_search_mixed, array_unique, empty, filter_var_url, implode, in_array,
- intval, is_array, is_string, parse_url, php_regex, php_to_string, rtrim, strtolower,
- strtoupper, strtr, substr, trigger_error,
+ array_merge, array_search_mixed, array_unique, empty, filter_var_url, implode, in_array_loose,
+ in_array_strict, intval, is_array, is_string, parse_url, php_regex, php_to_string, rtrim,
+ strtolower, strtoupper, strtr, substr, trigger_error,
};
use crate::advisory::Auditor;
@@ -306,9 +306,9 @@ impl Config {
};
for (key, val_box) in &config_section_map {
let val = val_box.clone();
- if in_array(
- PhpMixed::String(key.clone()),
- &PhpMixed::List(vec![
+ if in_array_strict(
+ key.clone(),
+ &[
PhpMixed::String("bitbucket-oauth".to_string()),
PhpMixed::String("github-oauth".to_string()),
PhpMixed::String("gitlab-oauth".to_string()),
@@ -317,18 +317,16 @@ impl Config {
PhpMixed::String("bearer".to_string()),
PhpMixed::String("client-certificate".to_string()),
PhpMixed::String("forgejo-token".to_string()),
- ]),
- true,
+ ],
) && 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(
- PhpMixed::String(key.clone()),
- &PhpMixed::List(vec![PhpMixed::String("allow-plugins".to_string())]),
- true,
+ } else if in_array_strict(
+ key.clone(),
+ &[PhpMixed::String("allow-plugins".to_string())],
) && self.config.contains_key(key)
&& is_array(self.config.get(key).unwrap_or(&PhpMixed::Null))
&& is_array(&val)
@@ -341,13 +339,12 @@ impl Config {
array_merge(array_merge(val.clone(), existing), val.clone()),
);
self.set_source_of_config_value(&val, key, source);
- } else if in_array(
- PhpMixed::String(key.clone()),
- &PhpMixed::List(vec![
+ } else if in_array_strict(
+ key.clone(),
+ &[
PhpMixed::String("gitlab-domains".to_string()),
PhpMixed::String("github-domains".to_string()),
- ]),
- true,
+ ],
) && self.config.contains_key(key)
{
let existing = self.config.get(key).cloned().unwrap_or(PhpMixed::Null);
@@ -738,15 +735,14 @@ impl Config {
other => other.as_string().unwrap_or("").to_string(),
};
- if !in_array(
- PhpMixed::String(value.clone()),
- &PhpMixed::List(vec![
+ if !in_array_loose(
+ value.clone(),
+ &[
PhpMixed::String("auto".to_string()),
PhpMixed::String("full".to_string()),
PhpMixed::String("proxy".to_string()),
PhpMixed::String("symlink".to_string()),
- ]),
- false,
+ ],
) {
return Err(RuntimeException {
message: format!(
@@ -772,16 +768,15 @@ 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(
- PhpMixed::String(env_str.clone()),
- &PhpMixed::List(vec![
+ 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()),
- ]),
- true,
+ ],
) {
return Err(RuntimeException {
message: format!(
@@ -876,15 +871,12 @@ impl Config {
let abandoned_env_str = abandoned_env.as_string().unwrap_or("").to_string();
let valid_choices: Vec<String> =
Auditor::ABANDONEDS.iter().map(|s| s.to_string()).collect();
- if !in_array(
- PhpMixed::String(abandoned_env_str.clone()),
- &PhpMixed::List(
- valid_choices
- .iter()
- .map(|s| PhpMixed::String(s.clone()))
- .collect(),
- ),
- true,
+ if !in_array_strict(
+ abandoned_env_str.clone(),
+ &valid_choices
+ .iter()
+ .map(|s| PhpMixed::String(s.clone()))
+ .collect::<Vec<_>>(),
) {
return Err(RuntimeException {
message: format!(
@@ -905,13 +897,12 @@ 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(
- PhpMixed::String(env_str.clone()),
- &PhpMixed::List(vec![
+ if !in_array_strict(
+ env_str.clone(),
+ &[
PhpMixed::String("0".to_string()),
PhpMixed::String("1".to_string()),
- ]),
- true,
+ ],
) {
return Err(RuntimeException {
message: format!(
@@ -1092,25 +1083,23 @@ impl Config {
let hostname = parse_url(url, PHP_URL_HOST)
.as_string()
.map(|s| s.to_string());
- if in_array(
+ if in_array_strict(
scheme
.clone()
.map(PhpMixed::String)
.unwrap_or(PhpMixed::Null),
- &PhpMixed::List(vec![
+ &[
PhpMixed::String("http".to_string()),
PhpMixed::String("git".to_string()),
PhpMixed::String("ftp".to_string()),
PhpMixed::String("svn".to_string()),
- ]),
- true,
+ ],
) {
if self.get_with_flags("secure-http", 0)?.as_bool() == Some(true) {
if scheme.as_deref() == Some("svn") {
- if in_array(
+ if in_array_strict(
hostname.map(PhpMixed::String).unwrap_or(PhpMixed::Null),
- &self.get_with_flags("secure-svn-domains", 0)?,
- true,
+ self.get_with_flags("secure-svn-domains", 0)?.values(),
) {
return Ok(());
}
diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs
index c6674c77..5dff0e61 100644
--- a/crates/shirabe/src/console/application.rs
+++ b/crates/shirabe/src/console/application.rs
@@ -97,7 +97,7 @@ 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, ini_set, is_array, is_dir, is_file,
+ 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,
@@ -2081,17 +2081,14 @@ impl ApplicationHandle {
];
let use_parent_dir_if_no_json_available =
application.borrow().get_use_parent_dir_config_value();
- let no_composer_json_commands_pm = PhpMixed::List(
- no_composer_json_commands
- .iter()
- .map(|s| PhpMixed::String(s.clone()))
- .collect(),
- );
+ 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(
- command_name.as_deref().unwrap_or("").into(),
+ && !in_array_strict(
+ command_name.as_deref().unwrap_or(""),
&no_composer_json_commands_pm,
- true,
)
&& !file_exists(Factory::get_composer_file().unwrap_or_default())
&& use_parent_dir_if_no_json_available.as_bool() != Some(false)
@@ -2183,20 +2180,16 @@ 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 = PhpMixed::List(vec![
+ 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(
- command_name.as_deref().unwrap_or("").into(),
- &mnp_list,
- true,
- )
+ || in_array_strict(command_name.as_deref().unwrap_or(""), &mnp_list)
|| (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/pool_builder.rs b/crates/shirabe/src/dependency_resolver/pool_builder.rs
index c56090f5..137a36ba 100644
--- a/crates/shirabe/src/dependency_resolver/pool_builder.rs
+++ b/crates/shirabe/src/dependency_resolver/pool_builder.rs
@@ -21,8 +21,8 @@ use crate::repository::RootPackageRepository;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
- LogicException, PhpMixed, array_flip_strings, array_map, in_array, microtime, number_format,
- round, strpos,
+ LogicException, PhpMixed, array_flip_strings, array_map, in_array_strict, microtime,
+ number_format, round, strpos,
};
use shirabe_semver::CompilingMatcher;
use shirabe_semver::Intervals;
@@ -540,25 +540,23 @@ impl PoolBuilder {
.insert(pkg_version.clone(), package.clone());
let pkg_type_mixed: PhpMixed = pkg_type.clone().into();
- let ignored_mixed: PhpMixed = self
+ let ignored_mixed: Vec<PhpMixed> = self
.ignored_types
.iter()
.cloned()
.map(PhpMixed::from)
- .collect::<Vec<_>>()
- .into();
- if in_array(pkg_type_mixed.clone(), &ignored_mixed, true)
+ .collect();
+ if in_array_strict(pkg_type_mixed.clone(), &ignored_mixed)
|| (self.allowed_types.is_some() && {
- let allowed_mixed: PhpMixed = self
+ let allowed_mixed: Vec<PhpMixed> = self
.allowed_types
.as_ref()
.unwrap()
.iter()
.cloned()
.map(PhpMixed::from)
- .collect::<Vec<_>>()
- .into();
- !in_array(pkg_type_mixed.clone(), &allowed_mixed, true)
+ .collect();
+ !in_array_strict(pkg_type_mixed.clone(), &allowed_mixed)
})
{
continue;
diff --git a/crates/shirabe/src/dependency_resolver/problem.rs b/crates/shirabe/src/dependency_resolver/problem.rs
index 40f21d19..b3da1e09 100644
--- a/crates/shirabe/src/dependency_resolver/problem.rs
+++ b/crates/shirabe/src/dependency_resolver/problem.rs
@@ -13,7 +13,7 @@ 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, loosely_compare,
+ 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,
strtolower, substr, substr_count, version_compare,
};
@@ -223,15 +223,12 @@ impl Problem {
learned_pool,
)?;
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- let matched = if in_array(
- PhpMixed::Int(rule_ref.get_reason()),
- &PhpMixed::List(
- deduplicatable_rule_types
- .iter()
- .map(|t| PhpMixed::Int(*t))
- .collect(),
- ),
- true,
+ let matched = if in_array_strict(
+ rule_ref.get_reason(),
+ &deduplicatable_rule_types
+ .iter()
+ .map(|t| PhpMixed::Int(*t))
+ .collect::<Vec<_>>(),
) {
Preg::is_match3(
php_regex!(
@@ -967,13 +964,12 @@ impl Problem {
&& c.get_version() == "dev-master"
{
for candidate in &packages {
- if in_array(
- PhpMixed::String(candidate.get_version().to_string()),
- &PhpMixed::List(vec![
+ if in_array_strict(
+ candidate.get_version().to_string(),
+ &[
PhpMixed::String("dev-default".to_string()),
PhpMixed::String("dev-main".to_string()),
- ]),
- true,
+ ],
) {
suffix = format!(
" Perhaps dev-master was renamed to {}?",
diff --git a/crates/shirabe/src/downloader/download_manager.rs b/crates/shirabe/src/downloader/download_manager.rs
index ea3fed41..7ff21a25 100644
--- a/crates/shirabe/src/downloader/download_manager.rs
+++ b/crates/shirabe/src/downloader/download_manager.rs
@@ -11,7 +11,7 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_keys,
- array_reverse, array_shift, dirname, implode, in_array, preg_quote, rtrim, str_replace,
+ array_reverse, array_shift, dirname, implode, in_array_strict, preg_quote, rtrim, str_replace,
strtolower, usort,
};
@@ -487,15 +487,12 @@ impl DownloadManager {
if let Some(prev) = prev_package {
// if we are updating, we want to keep the same source as the previously installed package (if available in the new one)
let prev_source = prev.get_installation_source();
- if in_array(
- PhpMixed::String(prev_source.clone().unwrap_or_default()),
- &PhpMixed::List(
- sources
- .iter()
- .map(|s| PhpMixed::String(s.clone()))
- .collect(),
- ),
- true,
+ if in_array_strict(
+ prev_source.clone().unwrap_or_default(),
+ &sources
+ .iter()
+ .map(|s| PhpMixed::String(s.clone()))
+ .collect::<Vec<_>>(),
)
// unless the previous package was stable dist (by default) and the new package is dev, then we allow the new default to take over
&& !(!prev.is_dev()
diff --git a/crates/shirabe/src/downloader/file_downloader.rs b/crates/shirabe/src/downloader/file_downloader.rs
index 48925b4b..c6ee3a20 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, is_dir, is_executable, parse_url, pathinfo,
- realpath, rtrim, spl_object_hash, strlen, strpos, strtr, trim, umask, usleep,
+ 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,
};
use std::sync::{LazyLock, Mutex};
@@ -339,15 +339,14 @@ 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(
- PhpMixed::Int(te.get_code()),
- &PhpMixed::List(vec![
+ && !in_array_strict(
+ te.get_code(),
+ &[
PhpMixed::Int(500),
PhpMixed::Int(502),
PhpMixed::Int(503),
PhpMixed::Int(504),
- ]),
- true,
+ ],
)
{
retries = 0;
diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs
index e9c70da3..0becf427 100644
--- a/crates/shirabe/src/downloader/git_downloader.rs
+++ b/crates/shirabe/src/downloader/git_downloader.rs
@@ -19,8 +19,8 @@ use crate::util::Url;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
- PhpMixed, RuntimeException, array_map, basename, dirname, implode, in_array, is_dir, php_regex,
- preg_quote, realpath, rtrim, strlen, strpos, substr, trim, version_compare,
+ PhpMixed, RuntimeException, array_map, basename, dirname, implode, in_array_strict, is_dir,
+ php_regex, preg_quote, realpath, rtrim, strlen, strpos, substr, trim, version_compare,
};
#[derive(Debug)]
@@ -537,7 +537,7 @@ impl GitDownloader {
.cloned()
.unwrap_or_default();
let mut push_url = format!("git@{}:{}/{}.git", m1, m2, m3);
- if !in_array(PhpMixed::String("ssh".to_string()), &protocols, true) {
+ if !in_array_strict("ssh".to_string(), protocols.values()) {
push_url = format!("https://{}/{}/{}.git", m1, m2, m3);
}
let cmd = vec![
diff --git a/crates/shirabe/src/io/base_io.rs b/crates/shirabe/src/io/base_io.rs
index 126c1201..5dd7682f 100644
--- a/crates/shirabe/src/io/base_io.rs
+++ b/crates/shirabe/src/io/base_io.rs
@@ -10,7 +10,8 @@ use shirabe_external_packages::composer::pcre::Preg;
use shirabe_external_packages::psr::log::LogLevel;
use shirabe_php_shim::{
JSON_INVALID_UTF8_IGNORE, JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE, PhpMixed,
- UnexpectedValueException, array_merge, in_array, json_encode_ex, php_regex,
+ UnexpectedValueException, array_merge, in_array_loose, in_array_strict, json_encode_ex,
+ php_regex,
};
fn log_context(context: &[(&str, &str)]) -> IndexMap<String, PhpMixed> {
@@ -116,10 +117,12 @@ pub trait BaseIO: IOInterface {
let token_str = token.as_string().unwrap_or("").to_string();
let github_domains = config.get("github-domains");
if domain != "github.com"
- && !in_array(
- PhpMixed::String(domain.clone()),
- &github_domains.clone().unwrap_or(PhpMixed::List(vec![])),
- true,
+ && !in_array_strict(
+ domain.clone(),
+ github_domains
+ .clone()
+ .unwrap_or(PhpMixed::List(vec![]))
+ .values(),
)
{
<Self as BaseIO>::debug(
@@ -162,10 +165,12 @@ pub trait BaseIO: IOInterface {
for (domain, token) in map.clone() {
let gitlab_domains = config.get("gitlab-domains");
if domain != "gitlab.com"
- && !in_array(
- PhpMixed::String(domain.clone()),
- &gitlab_domains.clone().unwrap_or(PhpMixed::List(vec![])),
- true,
+ && !in_array_strict(
+ domain.clone(),
+ gitlab_domains
+ .clone()
+ .unwrap_or(PhpMixed::List(vec![]))
+ .values(),
)
{
<Self as BaseIO>::debug(
@@ -203,10 +208,12 @@ pub trait BaseIO: IOInterface {
for (domain, token) in map.clone() {
let gitlab_domains = config.get("gitlab-domains");
if domain != "gitlab.com"
- && !in_array(
- PhpMixed::String(domain.clone()),
- &gitlab_domains.clone().unwrap_or(PhpMixed::List(vec![])),
- true,
+ && !in_array_strict(
+ domain.clone(),
+ gitlab_domains
+ .clone()
+ .unwrap_or(PhpMixed::List(vec![]))
+ .values(),
)
{
<Self as BaseIO>::debug(
@@ -252,10 +259,12 @@ pub trait BaseIO: IOInterface {
if let Some(map) = forgejo_token.as_opt().and_then(|v| v.as_array()) {
for (domain, cred) in map.clone() {
let forgejo_domains = config.get("forgejo-domains");
- if !in_array(
- PhpMixed::String(domain.clone()),
- &forgejo_domains.clone().unwrap_or(PhpMixed::List(vec![])),
- true,
+ if !in_array_strict(
+ domain.clone(),
+ forgejo_domains
+ .clone()
+ .unwrap_or(PhpMixed::List(vec![]))
+ .values(),
) {
<Self as BaseIO>::debug(
self,
@@ -461,15 +470,14 @@ pub trait BaseIO: IOInterface {
}
let level_str = level.as_string().unwrap_or("");
- if in_array(
+ if in_array_loose(
level.clone(),
- &PhpMixed::List(vec![
+ &[
PhpMixed::String(LogLevel::EMERGENCY.to_string()),
PhpMixed::String(LogLevel::ALERT.to_string()),
PhpMixed::String(LogLevel::CRITICAL.to_string()),
PhpMixed::String(LogLevel::ERROR.to_string()),
- ]),
- false,
+ ],
) {
self.write_error3(
&format!("<error>{}</error>", message_str),
diff --git a/crates/shirabe/src/io/console_io.rs b/crates/shirabe/src/io/console_io.rs
index 83e84fd3..12b70318 100644
--- a/crates/shirabe/src/io/console_io.rs
+++ b/crates/shirabe/src/io/console_io.rs
@@ -24,7 +24,7 @@ use shirabe_external_packages::symfony::console::question::ChoiceQuestion;
use shirabe_external_packages::symfony::console::question::Question;
use shirabe_external_packages::symfony::console::question::QuestionInterface;
use shirabe_php_shim::{
- PhpMixed, array_search, implode, in_array, is_array, is_string, microtime, str_repeat,
+ PhpMixed, array_search, implode, in_array_strict, is_array, is_string, microtime, str_repeat,
strip_tags, strlen,
};
@@ -614,7 +614,7 @@ impl IOInterfaceImmutable for ConsoleIO {
_ => vec![],
};
for (index, choice) in &choice_list {
- if in_array(choice.clone(), &PhpMixed::List(result_list.clone()), true) {
+ if in_array_strict(choice.clone(), &result_list) {
results.push(index.clone());
}
}
diff --git a/crates/shirabe/src/json/json_manipulator.rs b/crates/shirabe/src/json/json_manipulator.rs
index 48500de2..eec823b6 100644
--- a/crates/shirabe/src/json/json_manipulator.rs
+++ b/crates/shirabe/src/json/json_manipulator.rs
@@ -7,9 +7,9 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, addcslashes, array_key_exists, array_keys,
- array_reverse, empty, explode, implode, in_array, is_array, is_int, is_numeric, json_decode,
- php_regex, php_truthy, preg_quote, rtrim, str_contains, str_repeat, str_replace, strlen,
- strnatcmp, strpos, substr, trim, uksort,
+ array_reverse, empty, explode, implode, in_array_loose, is_array, is_int, is_numeric,
+ json_decode, php_regex, php_truthy, preg_quote, rtrim, str_contains, str_repeat, str_replace,
+ strlen, strnatcmp, strpos, substr, trim, uksort,
};
#[derive(Debug)]
@@ -660,14 +660,13 @@ impl JsonManipulator {
let mut name_owned = name.to_string();
let mut sub_name: Option<String> = None;
- if in_array(
- PhpMixed::String(main_node.to_string()),
- &PhpMixed::List(vec![
+ if in_array_loose(
+ main_node.to_string(),
+ &[
PhpMixed::String("config".to_string()),
PhpMixed::String("extra".to_string()),
PhpMixed::String("scripts".to_string()),
- ]),
- false,
+ ],
) && strpos(name, ".").is_some()
{
let parts = explode(".", name);
@@ -866,14 +865,13 @@ impl JsonManipulator {
let mut name_owned = name.to_string();
let mut sub_name: Option<String> = None;
- if in_array(
- PhpMixed::String(main_node.to_string()),
- &PhpMixed::List(vec![
+ if in_array_loose(
+ main_node.to_string(),
+ &[
PhpMixed::String("config".to_string()),
PhpMixed::String("extra".to_string()),
PhpMixed::String("scripts".to_string()),
- ]),
- false,
+ ],
) && strpos(name, ".").is_some()
{
let parts = explode(".", name);
diff --git a/crates/shirabe/src/package/alias_package.rs b/crates/shirabe/src/package/alias_package.rs
index 8073f3ff..fb775130 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};
+use shirabe_php_shim::{LogicException, PhpMixed, in_array_strict};
use shirabe_semver::constraint::SimpleConstraint;
#[derive(Debug, Clone)]
@@ -131,14 +131,13 @@ impl AliasPackage {
pretty_version = self.alias_of.get_pretty_version();
}
- if in_array(
- PhpMixed::String(link_type.to_string()),
- &PhpMixed::List(vec![
+ 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()),
- ]),
- true,
+ ],
) {
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 f06f2bdc..10350d78 100644
--- a/crates/shirabe/src/package/locker.rs
+++ b/crates/shirabe/src/package/locker.rs
@@ -28,8 +28,8 @@ use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
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, is_int,
- ksort, php_regex, realpath, strcmp, strtolower, touch2, trim, usort,
+ 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,
};
/// Reads/writes project lockfile (composer.lock).
@@ -481,14 +481,13 @@ impl Locker {
.and_then(|v| v.as_string())
.unwrap_or("")
.to_string();
- if in_array(
- PhpMixed::String(version),
- &PhpMixed::List(vec![
+ if in_array_strict(
+ version,
+ &[
PhpMixed::String("dev-master".to_string()),
PhpMixed::String("dev-trunk".to_string()),
PhpMixed::String("dev-default".to_string()),
- ]),
- true,
+ ],
) {
alias.insert(
"version".to_string(),
@@ -807,13 +806,12 @@ impl Locker {
let mut datetime: Option<chrono::DateTime<chrono::Utc>> = None;
if path.is_some()
- && in_array(
- PhpMixed::String(source_type.clone().unwrap_or_default()),
- &PhpMixed::List(vec![
+ && in_array_loose(
+ source_type.clone().unwrap_or_default(),
+ &[
PhpMixed::String("git".to_string()),
PhpMixed::String("hg".to_string()),
- ]),
- false,
+ ],
)
{
let source_ref = package
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
}
}
diff --git a/crates/shirabe/src/util/auth_helper.rs b/crates/shirabe/src/util/auth_helper.rs
index 0e02e764..80852bb2 100644
--- a/crates/shirabe/src/util/auth_helper.rs
+++ b/crates/shirabe/src/util/auth_helper.rs
@@ -12,8 +12,8 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
PHP_URL_HOST, PHP_URL_PATH, PHP_URL_SCHEME, PhpMixed, RuntimeException, base64_encode, explode,
- in_array, is_array, is_string, json_decode, parse_url, php_regex, str_replace, strpos,
- strtolower, substr, trim,
+ in_array_loose, in_array_strict, is_array, is_string, json_decode, parse_url, php_regex,
+ str_replace, strpos, strtolower, substr, trim,
};
#[derive(Debug)]
@@ -71,13 +71,12 @@ impl AuthHelper {
0,
Some(1),
));
- if in_array(
- PhpMixed::String(input.clone()),
- &PhpMixed::List(vec![
+ if in_array_loose(
+ input.clone(),
+ &[
PhpMixed::String("y".to_string()),
PhpMixed::String("n".to_string()),
- ]),
- false,
+ ],
) {
return Ok(PhpMixed::String(input));
}
@@ -250,14 +249,13 @@ impl AuthHelper {
.and_then(|a| a.get("password"))
.and_then(|v| v.clone())
.unwrap_or_default();
- if in_array(
- PhpMixed::String(password),
- &PhpMixed::List(vec![
+ if in_array_strict(
+ password,
+ &[
PhpMixed::String("gitlab-ci-token".to_string()),
PhpMixed::String("private-token".to_string()),
PhpMixed::String("oauth2".to_string()),
- ]),
- true,
+ ],
) {
return Err(TransportException::new(
format!("Invalid credentials for '{}', aborting.", url),
@@ -522,26 +520,21 @@ impl AuthHelper {
authentication_display_message =
Some("Using GitHub token authentication".to_string());
}
- } else if in_array(
- PhpMixed::String(password.clone()),
- &PhpMixed::List(vec![
+ } 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()),
- ]),
- true,
- ) && in_array(
- PhpMixed::String(origin.to_string()),
- &PhpMixed::List({
- let gitlab_domains = self.config.borrow_mut().get("gitlab-domains");
- match &gitlab_domains {
- PhpMixed::List(l) => l.clone(),
- PhpMixed::Array(a) => a.values().cloned().collect(),
- _ => vec![],
- }
- }),
- true,
- ) {
+ ],
+ ) && in_array_strict(origin.to_string(), &{
+ let gitlab_domains = self.config.borrow_mut().get("gitlab-domains");
+ match &gitlab_domains {
+ PhpMixed::List(l) => l.clone(),
+ PhpMixed::Array(a) => a.values().cloned().collect(),
+ _ => vec![],
+ }
+ }) {
if password == "oauth2" {
headers.push(PhpMixed::String(format!(
"Authorization: Bearer {}",
@@ -600,13 +593,12 @@ impl AuthHelper {
.insert(origin.to_string(), display_message.clone());
}
}
- } else if in_array(
- PhpMixed::String(origin.to_string()),
- &PhpMixed::List(vec![
+ } else if in_array_strict(
+ origin.to_string(),
+ &[
PhpMixed::String("api.bitbucket.org".to_string()),
PhpMixed::String("api.github.com".to_string()),
- ]),
- true,
+ ],
) {
return self.add_authentication_options(options, &str_replace("api.", "", origin), url);
}
diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs
index cbda0d43..0ee69926 100644
--- a/crates/shirabe/src/util/git.rs
+++ b/crates/shirabe/src/util/git.rs
@@ -17,8 +17,9 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
InvalidArgumentException, PHP_EOL, PhpMixed, RuntimeException, array_map, clearstatcache,
- explode, implode, in_array, is_dir, php_regex, preg_quote, rawurldecode, rawurlencode,
- str_contains, str_ends_with, str_replace_array, strlen, strpos, substr, trim, version_compare,
+ explode, implode, in_array_loose, in_array_strict, is_dir, php_regex, preg_quote, rawurldecode,
+ rawurlencode, str_contains, str_ends_with, str_replace_array, strlen, strpos, substr, trim,
+ version_compare,
};
use std::sync::Mutex;
@@ -329,15 +330,12 @@ impl Git {
Self::get_github_domains_regex(&self.config.borrow())
),
url,
- ) && !in_array(
- PhpMixed::String("ssh".to_string()),
- &PhpMixed::List(
- protocols_list
- .iter()
- .map(|s| PhpMixed::String(s.clone()))
- .collect(),
- ),
- true,
+ ) && !in_array_strict(
+ "ssh".to_string(),
+ &protocols_list
+ .iter()
+ .map(|s| PhpMixed::String(s.clone()))
+ .collect::<Vec<_>>(),
);
let mut auth: Option<IndexMap<String, Option<String>>> = None;
@@ -1346,16 +1344,15 @@ impl Git {
let mut masked_credentials: Vec<String> = vec![];
for credential in credentials {
- if in_array(
- PhpMixed::String(credential.clone()),
- &PhpMixed::List(vec![
+ if in_array_loose(
+ credential.clone(),
+ &[
PhpMixed::String("private-token".to_string()),
PhpMixed::String("x-token-auth".to_string()),
PhpMixed::String("oauth2".to_string()),
PhpMixed::String("gitlab-ci-token".to_string()),
PhpMixed::String("x-oauth-basic".to_string()),
- ]),
- false,
+ ],
) {
masked_credentials.push(credential.clone());
} else if strlen(credential) > 6 {
diff --git a/crates/shirabe/src/util/github.rs b/crates/shirabe/src/util/github.rs
index 0afbb684..01a5dd1f 100644
--- a/crates/shirabe/src/util/github.rs
+++ b/crates/shirabe/src/util/github.rs
@@ -9,7 +9,7 @@ use crate::util::HttpDownloader;
use crate::util::ProcessExecutor;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
-use shirabe_php_shim::{PhpMixed, date, in_array, php_regex, stripos, strtolower};
+use shirabe_php_shim::{PhpMixed, date, in_array_loose, php_regex, stripos, strtolower};
#[derive(Debug)]
pub struct GitHub {
@@ -52,11 +52,7 @@ impl GitHub {
pub fn authorize_oauth(&mut self, origin_url: &str) -> bool {
let github_domains = self.config.borrow_mut().get("github-domains");
- if !in_array(
- PhpMixed::String(origin_url.to_string()),
- &github_domains,
- false,
- ) {
+ if !in_array_loose(origin_url.to_string(), github_domains.values()) {
return false;
}
diff --git a/crates/shirabe/src/util/gitlab.rs b/crates/shirabe/src/util/gitlab.rs
index 2b23cdbf..c14ad46a 100644
--- a/crates/shirabe/src/util/gitlab.rs
+++ b/crates/shirabe/src/util/gitlab.rs
@@ -11,7 +11,7 @@ use crate::util::ProcessExecutor;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
- PhpMixed, RuntimeException, http_build_query, in_array, json_decode, php_regex, time,
+ PhpMixed, RuntimeException, http_build_query, in_array_strict, json_decode, php_regex, time,
};
#[derive(Debug)]
@@ -55,15 +55,9 @@ impl GitLab {
let bc_origin_url = Preg::replace(php_regex!("{:\\d+}"), "", origin_url);
let gitlab_domains = self.config.borrow_mut().get("gitlab-domains");
- if !in_array(
- PhpMixed::String(origin_url.to_string()),
- &gitlab_domains,
- true,
- ) && !in_array(
- PhpMixed::String(bc_origin_url.clone()),
- &gitlab_domains,
- true,
- ) {
+ if !in_array_strict(origin_url.to_string(), gitlab_domains.values())
+ && !in_array_strict(bc_origin_url.clone(), gitlab_domains.values())
+ {
return false;
}
diff --git a/crates/shirabe/src/util/http/curl_downloader.rs b/crates/shirabe/src/util/http/curl_downloader.rs
index 2d2259b9..64ff42a6 100644
--- a/crates/shirabe/src/util/http/curl_downloader.rs
+++ b/crates/shirabe/src/util/http/curl_downloader.rs
@@ -33,7 +33,8 @@ use crate::util::{AuthHelper, PromptAuthResult, StoreAuth};
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
- PhpMixed, in_array, parse_url, php_regex, preg_quote, rename, strpos, substr, unlink_silent,
+ PhpMixed, in_array_loose, in_array_strict, parse_url, php_regex, preg_quote, rename, strpos,
+ substr, unlink_silent,
};
use std::sync::atomic::{AtomicBool, Ordering};
@@ -412,15 +413,12 @@ impl CurlDownloader {
.and_then(|v| v.as_int())
.unwrap_or(0);
if Self::method_is_get(options)
- && in_array(
- PhpMixed::Int(status_code),
- &PhpMixed::List(
- [423, 425, 500, 502, 503, 504, 507, 510]
- .iter()
- .map(|c| PhpMixed::Int(*c))
- .collect(),
- ),
- true,
+ && in_array_strict(
+ status_code,
+ &[423, 425, 500, 502, 503, 504, 507, 510]
+ .iter()
+ .map(|c| PhpMixed::Int(*c))
+ .collect::<Vec<_>>(),
)
&& retries < self.max_retries
{
@@ -717,10 +715,9 @@ impl CurlDownloader {
.and_then(|b| b.as_int())
.unwrap_or(0);
- if in_array(
- PhpMixed::Int(response.inner.get_status_code()),
- &PhpMixed::List(vec![PhpMixed::Int(401), PhpMixed::Int(403)]),
- false,
+ if in_array_loose(
+ response.inner.get_status_code(),
+ &[PhpMixed::Int(401), PhpMixed::Int(403)],
) && retry_auth_failure
{
let status_message = response.inner.get_status_message();
@@ -767,11 +764,7 @@ impl CurlDownloader {
_ => Vec::new(),
};
if response.inner.get_status_code() == 404
- && in_array(
- PhpMixed::String(origin.to_string()),
- &PhpMixed::List(gitlab_domains_list),
- true,
- )
+ && in_array_strict(origin.to_string(), &gitlab_domains_list)
&& strpos(url, "archive.zip").is_some()
{
needs_auth_retry = Some("GitLab requires authentication and it was not provided");
@@ -827,19 +820,16 @@ impl CurlDownloader {
}
let mut details = String::new();
- if in_array(
- PhpMixed::String(
- response
- .inner
- .get_header("content-type")
- .unwrap_or_default()
- .to_lowercase(),
- ),
- &PhpMixed::List(vec![
+ if in_array_strict(
+ 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()),
- ]),
- true,
+ ],
) {
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 7b1c8f61..9ebf4f4f 100644
--- a/crates/shirabe/src/util/platform.rs
+++ b/crates/shirabe/src/util/platform.rs
@@ -5,7 +5,7 @@ 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, ini_get, is_array,
+ 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,
@@ -280,13 +280,12 @@ 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(
- PhpMixed::String(strtoupper(&Self::get_env("MSYSTEM").unwrap_or_default())),
- &PhpMixed::List(vec![
+ if in_array_strict(
+ strtoupper(&Self::get_env("MSYSTEM").unwrap_or_default()),
+ &[
PhpMixed::String("MINGW32".to_string()),
PhpMixed::String("MINGW64".to_string()),
- ]),
- true,
+ ],
) {
return true;
}
diff --git a/crates/shirabe/src/util/process_executor.rs b/crates/shirabe/src/util/process_executor.rs
index c24e2f83..463c5d19 100644
--- a/crates/shirabe/src/util/process_executor.rs
+++ b/crates/shirabe/src/util/process_executor.rs
@@ -15,8 +15,9 @@ use shirabe_external_packages::symfony::process::exception::ProcessSignaledExcep
use shirabe_external_packages::symfony::process::exception::RuntimeException as SymfonyProcessRuntimeException;
use shirabe_php_shim::{
LogicException, PHP_EOL, PhpMixed, RuntimeException, array_intersect, array_map,
- escapeshellarg, explode, implode, in_array, is_array, is_dir, is_numeric, is_string, php_regex,
- rtrim, str_replace, strcspn, strlen, strpbrk, strtolower, strtr_array, substr_replace, trim,
+ escapeshellarg, explode, implode, in_array_strict, is_array, is_dir, is_numeric, is_string,
+ php_regex, rtrim, str_replace, strcspn, strlen, strpbrk, strtolower, strtr_array,
+ substr_replace, trim,
};
use std::sync::{LazyLock, Mutex};
@@ -974,15 +975,12 @@ impl ProcessExecutor {
/// Resolves executable paths on Windows
fn get_executable(name: &str) -> String {
- if in_array(
- PhpMixed::String(strtolower(name)),
- &PhpMixed::List(
- Self::BUILTIN_CMD_COMMANDS
- .iter()
- .map(|s| PhpMixed::String(s.to_string()))
- .collect(),
- ),
- true,
+ if in_array_strict(
+ strtolower(name),
+ &Self::BUILTIN_CMD_COMMANDS
+ .iter()
+ .map(|s| PhpMixed::String(s.to_string()))
+ .collect::<Vec<_>>(),
) {
return name.to_string();
}
diff --git a/crates/shirabe/src/util/url.rs b/crates/shirabe/src/util/url.rs
index 621f6fab..b1974b0b 100644
--- a/crates/shirabe/src/util/url.rs
+++ b/crates/shirabe/src/util/url.rs
@@ -4,7 +4,9 @@ use crate::config::Config;
use crate::util::GitHub;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
-use shirabe_php_shim::{PHP_URL_HOST, PHP_URL_PORT, PhpMixed, in_array, parse_url, php_regex};
+use shirabe_php_shim::{
+ PHP_URL_HOST, PHP_URL_PORT, PhpMixed, in_array_strict, parse_url, php_regex,
+};
pub struct Url;
@@ -93,17 +95,13 @@ impl Url {
r#ref
);
}
- } else if in_array(
- PhpMixed::String(host.clone()),
- &config.get("github-domains"),
- true,
- ) {
+ } else if in_array_strict(host.clone(), config.get("github-domains").values()) {
url = Preg::replace(
php_regex!(r"{(/repos/[^/]+/[^/]+/(zip|tar)ball)(?:/.+)?$}i"),
&format!("$1/{}", r#ref),
&url,
);
- } else if in_array(PhpMixed::String(host), &config.get("gitlab-domains"), true) {
+ } else if in_array_strict(host, config.get("gitlab-domains").values()) {
url = Preg::replace(
php_regex!(
r"{(/api/v[34]/projects/[^/]+/repository/archive\.(?:zip|tar\.gz|tar\.bz2|tar)\?sha=).+$}i"
@@ -146,11 +144,7 @@ impl Url {
// Gitlab can be installed in a non-root context (i.e. gitlab.com/foo). When downloading archives the originUrl
// is the host without the path, so we look for the registered gitlab-domains matching the host here
if !origin.contains('/')
- && !in_array(
- PhpMixed::String(origin.clone()),
- &config.get("gitlab-domains"),
- true,
- )
+ && !in_array_strict(origin.clone(), config.get("gitlab-domains").values())
{
let gitlab_domains: Vec<String> = match config.get("gitlab-domains") {
PhpMixed::List(list) => list