From 4856f05e870ec5d2daaa74bf9a86a1519a813614 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 18 Aug 2026 08:37:30 +0900 Subject: fix(input): return a bool|string|string[]|null enum from get_option `InputInterface::get_option` returned `PhpMixed`, so the negation branch of `Input::get_option` reproduced PHP's `return !$value;` as `!value.as_bool().unwrap_or(false)`, which inverts the result for a string value instead of leaving it `false`. It now returns `InputOptionValue`, whose `to_bool` is PHP's truthiness cast. The narrowing also removes the `Vec` element handling the commands carried for array options: `as_array` hands back `&[String]`, so the `filter_map(|v| v.as_string())` chains at eight call sites collapse. Its other accessors keep `PhpMixed`'s names and meanings (`is_null`, `as_bool`, `as_string`, `to_bool`), and `From for PhpMixed` covers the callers that feed the value back into an `IndexMap` or a `PhpMixed` parameter. `Input` keeps its parsed options and `InputOption` its defaults as `PhpMixed`, so `Input::get_option` is where the narrowing happens and where a value outside the domain panics. Co-Authored-By: Claude Opus 5 (1M context) --- .../src/command/complete_command.rs | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'crates/shirabe-symfony-console/src/command/complete_command.rs') diff --git a/crates/shirabe-symfony-console/src/command/complete_command.rs b/crates/shirabe-symfony-console/src/command/complete_command.rs index dc418178..432888b6 100644 --- a/crates/shirabe-symfony-console/src/command/complete_command.rs +++ b/crates/shirabe-symfony-console/src/command/complete_command.rs @@ -78,19 +78,26 @@ impl CompleteCommand { input: &dyn InputInterface, ) -> anyhow::Result { let current_index = input.get_option("current")?; - if !current_index.to_bool() || !shirabe_php_shim::ctype_digit(¤t_index.to_string()) { + if !current_index.to_bool() + || !shirabe_php_shim::ctype_digit(current_index.as_string().unwrap_or_default()) + { anyhow::bail!(shirabe_php_shim::RuntimeException::new( "The \"--current\" option must be set and it must be an integer.".to_string() )); } - let tokens: Vec = match input.get_option("input")?.as_list() { - Some(list) => list.iter().map(|v| v.to_string()).collect(), - None => Vec::new(), - }; + let tokens: Vec = input + .get_option("input")? + .as_array() + .map(<[String]>::to_vec) + .unwrap_or_default(); let mut completion_input = CompletionInput::from_tokens( tokens, - current_index.to_string().parse::().unwrap_or(0), + current_index + .as_string() + .unwrap_or_default() + .parse::() + .unwrap_or(0), )?; // try { $completionInput->bind(...); } catch (ExceptionInterface $e) {} @@ -254,13 +261,13 @@ impl Command for CompleteCommand { let completion_output = self .completion_outputs - .get(&shell.to_string()) + .get(shell.as_string().unwrap_or_default()) .cloned() .unwrap_or(PhpMixed::Bool(false)); if !completion_output.to_bool() { anyhow::bail!(shirabe_php_shim::RuntimeException::new(format!( "Shell completion is not supported for your shell: \"{}\" (supported: \"{}\").", - shell, + shell.as_string().unwrap_or_default(), self.completion_outputs .keys() .cloned() -- cgit v1.3.1-4-g156e