From 0b227a4c623c72c155b1622674b78ca5cc0c4f8b Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 6 Aug 2026 04:59:34 +0900 Subject: refactor(spdx-licenses): return a dedicated type from getLicenseByIdentifier PHP hands back a positional array, so every caller had to reach into a PhpMixed list by index and fall back to a default when an element was missing or the wrong variant -- fallbacks that could never fire, since the list shape is fixed. LicenseMetadata names the four elements and makes the accesses total. This also drops the crate's last use of PhpMixed, and with it the dependency on shirabe-php-shim. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe/src/command/show_command.rs | 41 +++++++----------------------- 1 file changed, 9 insertions(+), 32 deletions(-) (limited to 'crates/shirabe/src/command') diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs index a6bb906d..77d81858 100644 --- a/crates/shirabe/src/command/show_command.rs +++ b/crates/shirabe/src/command/show_command.rs @@ -2020,24 +2020,13 @@ impl ShowCommand { let out = match license { None => license_id.clone(), Some(license) => { - // SpdxLicenses::getLicenseByIdentifier returns [0 => fullname, 1 => osiApproved, 2 => url]. - let list = license.as_list(); - let fullname = list - .and_then(|l| l.first()) - .and_then(|v| v.as_string()) - .unwrap_or("") - .to_string(); - let is_osi = - list.and_then(|l| l.get(1)).and_then(|v| v.as_bool()) == Some(true); - let url = list - .and_then(|l| l.get(2)) - .and_then(|v| v.as_string()) - .unwrap_or("") - .to_string(); - if is_osi { - format!("{} ({}) (OSI approved) {}", fullname, license_id, url) + if license.is_osi_approved { + format!( + "{} ({}) (OSI approved) {}", + license.name, license_id, license.url + ) } else { - format!("{} ({}) {}", fullname, license_id, url) + format!("{} ({}) {}", license.name, license_id, license.url) } } }; @@ -2268,23 +2257,11 @@ impl ShowCommand { match license { None => PhpMixed::String(license_id), Some(l) => { - // PHP shape: ['name' => $license[0], 'osi' => $licenseId, 'url' => $license[2]]. - // Note 'osi' is the license id string, not the OSI-approved flag. - let list = l.as_list(); - let name = list - .and_then(|x| x.first()) - .and_then(|v| v.as_string()) - .unwrap_or("") - .to_string(); - let url = list - .and_then(|x| x.get(2)) - .and_then(|v| v.as_string()) - .unwrap_or("") - .to_string(); + // The 'osi' key holds the license id string, not the OSI-approved flag. let mut m: IndexMap = IndexMap::new(); - m.insert("name".to_string(), PhpMixed::String(name)); + m.insert("name".to_string(), PhpMixed::String(l.name)); m.insert("osi".to_string(), PhpMixed::String(license_id)); - m.insert("url".to_string(), PhpMixed::String(url)); + m.insert("url".to_string(), PhpMixed::String(l.url)); PhpMixed::Array(m.into_iter().collect()) } } -- cgit v1.3.1