diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-20 18:34:54 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-20 18:34:54 +0900 |
| commit | 81b9fc9d92bb74aa8428ae4db39bd84e8c16095c (patch) | |
| tree | 3efb6476d797e2a95545c4c3abba468c3e3c8d52 /crates/shirabe/src/io | |
| parent | c09cd630afb4bb0ca10e926f93bf706ca828ae85 (diff) | |
| download | php-shirabe-81b9fc9d92bb74aa8428ae4db39bd84e8c16095c.tar.gz php-shirabe-81b9fc9d92bb74aa8428ae4db39bd84e8c16095c.tar.zst php-shirabe-81b9fc9d92bb74aa8428ae4db39bd84e8c16095c.zip | |
refactor(php-shim): drop Box wrapping from PhpMixed List/Array
The List and Array variants of PhpMixed boxed their elements
unnecessarily. Store PhpMixed values directly and update all callers
accordingly.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/io')
| -rw-r--r-- | crates/shirabe/src/io/base_io.rs | 40 | ||||
| -rw-r--r-- | crates/shirabe/src/io/console_io.rs | 40 |
2 files changed, 29 insertions, 51 deletions
diff --git a/crates/shirabe/src/io/base_io.rs b/crates/shirabe/src/io/base_io.rs index f8e4d32..99c3d70 100644 --- a/crates/shirabe/src/io/base_io.rs +++ b/crates/shirabe/src/io/base_io.rs @@ -13,10 +13,10 @@ use shirabe_php_shim::{ UnexpectedValueException, array_merge, in_array, json_encode_ex, }; -fn log_context(context: &[(&str, &str)]) -> IndexMap<String, Box<PhpMixed>> { +fn log_context(context: &[(&str, &str)]) -> IndexMap<String, PhpMixed> { context .iter() - .map(|(k, v)| (k.to_string(), Box::new(PhpMixed::String(v.to_string())))) + .map(|(k, v)| (k.to_string(), PhpMixed::String(v.to_string()))) .collect() } @@ -132,11 +132,11 @@ pub trait BaseIO: IOInterface { ); let merged = array_merge( github_domains.unwrap_or(PhpMixed::List(vec![])), - PhpMixed::List(vec![Box::new(PhpMixed::String(domain.clone()))]), + PhpMixed::List(vec![PhpMixed::String(domain.clone())]), ); let mut inner = IndexMap::new(); - inner.insert("github-domains".to_string(), Box::new(merged)); - let mut config_outer: IndexMap<String, PhpMixed> = IndexMap::new(); + inner.insert("github-domains".to_string(), merged); + let mut config_outer = IndexMap::new(); config_outer.insert("config".to_string(), PhpMixed::Array(inner)); config.merge(&config_outer, "implicit-due-to-auth"); } @@ -178,10 +178,10 @@ pub trait BaseIO: IOInterface { ); let merged = array_merge( gitlab_domains.unwrap_or(PhpMixed::List(vec![])), - PhpMixed::List(vec![Box::new(PhpMixed::String(domain.clone()))]), + PhpMixed::List(vec![PhpMixed::String(domain.clone())]), ); let mut inner = IndexMap::new(); - inner.insert("gitlab-domains".to_string(), Box::new(merged)); + inner.insert("gitlab-domains".to_string(), merged); let mut config_outer: IndexMap<String, PhpMixed> = IndexMap::new(); config_outer.insert("config".to_string(), PhpMixed::Array(inner)); config.merge(&config_outer, "implicit-due-to-auth"); @@ -219,10 +219,10 @@ pub trait BaseIO: IOInterface { ); let merged = array_merge( gitlab_domains.unwrap_or(PhpMixed::List(vec![])), - PhpMixed::List(vec![Box::new(PhpMixed::String(domain.clone()))]), + PhpMixed::List(vec![PhpMixed::String(domain.clone())]), ); let mut inner = IndexMap::new(); - inner.insert("gitlab-domains".to_string(), Box::new(merged)); + inner.insert("gitlab-domains".to_string(), merged); let mut config_outer: IndexMap<String, PhpMixed> = IndexMap::new(); config_outer.insert("config".to_string(), PhpMixed::Array(inner)); config.merge(&config_outer, "implicit-due-to-auth"); @@ -267,10 +267,10 @@ pub trait BaseIO: IOInterface { ); let merged = array_merge( forgejo_domains.unwrap_or(PhpMixed::List(vec![])), - PhpMixed::List(vec![Box::new(PhpMixed::String(domain.clone()))]), + PhpMixed::List(vec![PhpMixed::String(domain.clone())]), ); let mut inner = IndexMap::new(); - inner.insert("forgejo-domains".to_string(), Box::new(merged)); + inner.insert("forgejo-domains".to_string(), merged); let mut config_outer: IndexMap<String, PhpMixed> = IndexMap::new(); config_outer.insert("config".to_string(), PhpMixed::Array(inner)); config.merge(&config_outer, "implicit-due-to-auth"); @@ -344,17 +344,15 @@ pub trait BaseIO: IOInterface { .and_then(|v| v.as_string()) .map(|s| s.to_string()); - let mut ssl_options: IndexMap<String, Box<PhpMixed>> = IndexMap::new(); + let mut ssl_options = IndexMap::new(); if let Some(cert) = local_cert { - ssl_options - .insert("local_cert".to_string(), Box::new(PhpMixed::String(cert))); + ssl_options.insert("local_cert".to_string(), PhpMixed::String(cert)); } if let Some(pk) = local_pk { - ssl_options.insert("local_pk".to_string(), Box::new(PhpMixed::String(pk))); + ssl_options.insert("local_pk".to_string(), PhpMixed::String(pk)); } if let Some(pass) = passphrase { - ssl_options - .insert("passphrase".to_string(), Box::new(PhpMixed::String(pass))); + ssl_options.insert("passphrase".to_string(), PhpMixed::String(pass)); } if !ssl_options.contains_key("local_cert") { @@ -465,10 +463,10 @@ pub trait BaseIO: IOInterface { if in_array( level.clone(), &PhpMixed::List(vec![ - Box::new(PhpMixed::String(LogLevel::EMERGENCY.to_string())), - Box::new(PhpMixed::String(LogLevel::ALERT.to_string())), - Box::new(PhpMixed::String(LogLevel::CRITICAL.to_string())), - Box::new(PhpMixed::String(LogLevel::ERROR.to_string())), + 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, ) { diff --git a/crates/shirabe/src/io/console_io.rs b/crates/shirabe/src/io/console_io.rs index e061401..25ec02d 100644 --- a/crates/shirabe/src/io/console_io.rs +++ b/crates/shirabe/src/io/console_io.rs @@ -117,12 +117,7 @@ impl ConsoleIO { ) }) .collect(); - PhpMixed::List( - mapped - .into_iter() - .map(|s| Box::new(PhpMixed::String(s))) - .collect(), - ) + PhpMixed::List(mapped.into_iter().map(PhpMixed::String).collect()) } else { messages }; @@ -326,12 +321,7 @@ impl ConsoleIO { _ => {} } - PhpMixed::Array( - sanitized - .into_iter() - .map(|(k, v)| (k, Box::new(v))) - .collect(), - ) + PhpMixed::Array(sanitized.into_iter().collect()) } /// Ensures a string is valid UTF-8, replacing invalid byte sequences with '?' @@ -576,12 +566,7 @@ impl IOInterfaceImmutable for ConsoleIO { error_message: String, multiselect: bool, ) -> PhpMixed { - let choices: PhpMixed = PhpMixed::List( - choices - .into_iter() - .map(|s| Box::new(PhpMixed::String(s))) - .collect(), - ); + let choices: PhpMixed = PhpMixed::List(choices.into_iter().map(PhpMixed::String).collect()); let _helper = self .helper_set .get("question") @@ -590,17 +575,17 @@ impl IOInterfaceImmutable for ConsoleIO { .as_string() .unwrap_or("") .to_string(); - // ChoiceQuestion::new expects an IndexMap<String, Box<PhpMixed>>; project the + // ChoiceQuestion::new expects an IndexMap<String, PhpMixed>; project the // sanitized choice list/map into the keyed form, preserving keys. let sanitized_choices_mixed = Self::sanitize(choices.clone(), true); - let sanitized_choices: IndexMap<String, Box<PhpMixed>> = match sanitized_choices_mixed { + let sanitized_choices: IndexMap<String, PhpMixed> = match sanitized_choices_mixed { PhpMixed::List(l) => l .into_iter() .enumerate() .map(|(i, b)| (i.to_string(), b)) .collect(), PhpMixed::Array(a) => a, - other => indexmap! { "0".to_string() => Box::new(other) }, + other => indexmap! { "0".to_string() => other }, }; let sanitized_default = if is_string(&default) { Some(Self::sanitize(default, true)) @@ -657,14 +642,14 @@ impl IOInterfaceImmutable for ConsoleIO { } let mut results: Vec<String> = vec![]; - let result_list = result.as_list().cloned().unwrap_or_default(); + let result_list: Vec<PhpMixed> = result.as_list().cloned().unwrap_or_default(); let choice_list: Vec<(String, PhpMixed)> = match &choices { PhpMixed::List(l) => l .iter() .enumerate() - .map(|(i, v)| (i.to_string(), (**v).clone())) + .map(|(i, v)| (i.to_string(), v.clone())) .collect(), - PhpMixed::Array(a) => a.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect(), + PhpMixed::Array(a) => a.iter().map(|(k, v)| (k.clone(), v.clone())).collect(), _ => vec![], }; for (index, choice) in &choice_list { @@ -673,12 +658,7 @@ impl IOInterfaceImmutable for ConsoleIO { } } - PhpMixed::List( - results - .into_iter() - .map(|s| Box::new(PhpMixed::String(s))) - .collect(), - ) + PhpMixed::List(results.into_iter().map(PhpMixed::String).collect()) } fn get_authentications(&self) -> IndexMap<String, IndexMap<String, Option<String>>> { |
