aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages/src/symfony/console/question
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-20 18:34:54 +0900
committernsfisis <nsfisis@gmail.com>2026-06-20 18:34:54 +0900
commit81b9fc9d92bb74aa8428ae4db39bd84e8c16095c (patch)
tree3efb6476d797e2a95545c4c3abba468c3e3c8d52 /crates/shirabe-external-packages/src/symfony/console/question
parentc09cd630afb4bb0ca10e926f93bf706ca828ae85 (diff)
downloadphp-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-external-packages/src/symfony/console/question')
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs22
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/question/question.rs10
2 files changed, 15 insertions, 17 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs b/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs
index e1368e5..64f0687 100644
--- a/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs
@@ -10,7 +10,7 @@ use shirabe_php_shim::PhpMixed;
#[derive(Debug)]
pub struct ChoiceQuestion {
inner: Question,
- choices: IndexMap<String, Box<PhpMixed>>,
+ choices: IndexMap<String, PhpMixed>,
multiselect: bool,
prompt: String,
error_message: String,
@@ -22,7 +22,7 @@ impl ChoiceQuestion {
/// `$default` The default answer to return.
pub fn new(
question: String,
- choices: IndexMap<String, Box<PhpMixed>>,
+ choices: IndexMap<String, PhpMixed>,
default: Option<PhpMixed>,
) -> Result<Self, LogicException> {
if choices.is_empty() {
@@ -44,14 +44,14 @@ impl ChoiceQuestion {
this.inner.set_validator(Some(validator));
// setAutocompleterValues never throws for an array argument.
this.inner
- .set_autocompleter_values(Some(PhpMixed::Array(choices)))
+ .set_autocompleter_values(Some(PhpMixed::Array(choices.clone())))
.expect("autocompleter cannot be set on a hidden question during construction");
Ok(this)
}
/// Returns available choices.
- pub fn get_choices(&self) -> &IndexMap<String, Box<PhpMixed>> {
+ pub fn get_choices(&self) -> &IndexMap<String, PhpMixed> {
&self.choices
}
@@ -151,7 +151,7 @@ impl ChoiceQuestion {
for value in &selected_choices {
let mut results: Vec<String> = Vec::new();
for (key, choice) in &choices {
- if (**choice) == *value {
+ if (*choice) == *value {
results.push(key.clone());
}
}
@@ -178,10 +178,10 @@ impl ChoiceQuestion {
if !is_assoc {
if let Some(found_key) = &result_key {
// $result = $choices[$result];
- result = (*choices[found_key]).clone();
+ result = choices[found_key].clone();
} else if let Some(found) = choices.get(&shirabe_php_shim::strval(value)) {
// isset($choices[$value])
- result = (**found).clone();
+ result = found.clone();
} else {
result = PhpMixed::Bool(false);
}
@@ -218,13 +218,11 @@ impl ChoiceQuestion {
}
if multiselect {
- return Ok(PhpMixed::List(
- multiselect_choices.into_iter().map(Box::new).collect(),
- ));
+ return Ok(PhpMixed::List(multiselect_choices));
}
Ok(shirabe_php_shim::current(PhpMixed::List(
- multiselect_choices.into_iter().map(Box::new).collect(),
+ multiselect_choices,
)))
})
}
@@ -232,7 +230,7 @@ impl ChoiceQuestion {
/// array_search operates over the choice values as strings; this projects the
/// choices map's values into the string-keyed form the shim expects.
-fn choices_as_str(choices: &IndexMap<String, Box<PhpMixed>>) -> IndexMap<String, String> {
+fn choices_as_str(choices: &IndexMap<String, PhpMixed>) -> IndexMap<String, String> {
choices
.iter()
.map(|(k, v)| (k.clone(), shirabe_php_shim::strval(v)))
diff --git a/crates/shirabe-external-packages/src/symfony/console/question/question.rs b/crates/shirabe-external-packages/src/symfony/console/question/question.rs
index 78ae9b2..9ec3aef 100644
--- a/crates/shirabe-external-packages/src/symfony/console/question/question.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/question/question.rs
@@ -133,13 +133,13 @@ impl Question {
// array_merge(array_keys($values), array_values($values))
let mut merged: Vec<PhpMixed> =
array.keys().map(|k| PhpMixed::String(k.clone())).collect();
- merged.extend(array.values().map(|v| (**v).clone()));
+ merged.extend(array.values().map(|v| v.clone()));
merged
} else {
// array_values($values)
match &values {
- PhpMixed::List(list) => list.iter().map(|v| (**v).clone()).collect(),
- PhpMixed::Array(array) => array.values().map(|v| (**v).clone()).collect(),
+ PhpMixed::List(list) => list.iter().cloned().collect(),
+ PhpMixed::Array(array) => array.values().map(|v| v.clone()).collect(),
_ => unreachable!(),
}
};
@@ -154,8 +154,8 @@ impl Question {
// Non-array iterables are not modeled by PhpMixed; extract any
// list/array elements, otherwise treat as an empty iterator.
let cached: Vec<PhpMixed> = match values {
- PhpMixed::List(list) => list.into_iter().map(|v| *v).collect(),
- PhpMixed::Array(array) => array.into_values().map(|v| *v).collect(),
+ PhpMixed::List(list) => list.into_iter().collect(),
+ PhpMixed::Array(array) => array.into_values().map(|v| v).collect(),
_ => Vec::new(),
};
Some(Box::new(move |_input: &str| Some(cached.clone())))