From 791ef1cd465597ff43dab4216c4b00e9e4160da8 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 6 Aug 2026 06:25:10 +0900 Subject: refactor(php-shim): split in_array into strict and loose variants --- .../shirabe/src/command/package_discovery_trait.rs | 32 +++++++++------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'crates/shirabe/src/command/package_discovery_trait.rs') 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::>(), ) }); // 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::>(), ) { return Err(InvalidArgumentException { message: format!( -- cgit v1.3.1