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) --- crates/shirabe/src/command/base_command.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'crates/shirabe/src/command/base_command.rs') diff --git a/crates/shirabe/src/command/base_command.rs b/crates/shirabe/src/command/base_command.rs index d7f935c1..8ec9f350 100644 --- a/crates/shirabe/src/command/base_command.rs +++ b/crates/shirabe/src/command/base_command.rs @@ -20,7 +20,7 @@ use crate::util::Platform; use indexmap::IndexMap; use shirabe_php_shim::{ InvalidArgumentException, LogicException, PhpClass, PhpMixed, RuntimeException, - UnexpectedValueException, count, explode, in_array_strict, is_string, + UnexpectedValueException, count, explode, in_array_strict, }; use shirabe_symfony_console::Terminal; use shirabe_symfony_console::command::{Command, CommandData, SetDefinitionArg}; @@ -445,7 +445,11 @@ impl BaseCommand for BaseCommandData { } if input.borrow().has_option("prefer-install") - && is_string(&input.borrow().get_option("prefer-install")?) + && input + .borrow() + .get_option("prefer-install")? + .as_string() + .is_some() { if input .borrow() @@ -556,7 +560,7 @@ impl BaseCommand for BaseCommandData { return Ok(PlatformRequirementFilterFactory::ignore_all()); } - let ignores = input.borrow().get_option("ignore-platform-req")?; + let ignores: PhpMixed = input.borrow().get_option("ignore-platform-req")?.into(); if count(&ignores) > 0 { return PlatformRequirementFilterFactory::from_bool_or_list(ignores); } @@ -906,8 +910,9 @@ pub fn base_command_initialize( { let ignore_platform_req_env = Platform::get_env("COMPOSER_IGNORE_PLATFORM_REQ"); let ignore_str = ignore_platform_req_env.clone().unwrap_or_default(); - if 0 == count(&input.borrow().get_option("ignore-platform-req")?) - && ignore_platform_req_env.is_some() + if 0 == count(&PhpMixed::from( + input.borrow().get_option("ignore-platform-req")?, + )) && ignore_platform_req_env.is_some() && !ignore_str.is_empty() { input.borrow_mut().set_option( -- cgit v1.3.1-4-g156e