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-spdx-licenses/src/spdx_licenses.rs | 29 ++++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'crates/shirabe-spdx-licenses/src') diff --git a/crates/shirabe-spdx-licenses/src/spdx_licenses.rs b/crates/shirabe-spdx-licenses/src/spdx_licenses.rs index 36d87a1e..82f2ae70 100644 --- a/crates/shirabe-spdx-licenses/src/spdx_licenses.rs +++ b/crates/shirabe-spdx-licenses/src/spdx_licenses.rs @@ -1,7 +1,6 @@ //! ref: composer/vendor/composer/spdx-licenses/src/SpdxLicenses.php use indexmap::IndexMap; -use shirabe_php_shim::PhpMixed; // PHP reads the resource files from `dirname(__DIR__) . '/res'` at runtime via // file_get_contents. Composer's res directory ships with the vendored package; embed it at compile @@ -31,6 +30,14 @@ pub struct SpdxLicenses { exceptions_by_length_desc: Vec, } +#[derive(Debug)] +pub struct LicenseMetadata { + pub name: String, + pub is_osi_approved: bool, + pub url: String, + pub is_deprecated_license_id: bool, +} + impl Default for SpdxLicenses { fn default() -> Self { Self::new() @@ -53,24 +60,18 @@ impl SpdxLicenses { } /// Returns license metadata by license identifier. - /// - /// The returned list is in the form of: - /// [ 0 => full name, 1 => osi certified, 2 => link to license text, 3 => deprecation status ] - pub fn get_license_by_identifier(&self, identifier: &str) -> Option { + pub fn get_license_by_identifier(&self, identifier: &str) -> Option { let key = identifier.to_lowercase(); let (identifier, name, is_osi_approved, is_deprecated_license_id) = self.licenses.get(&key)?; - Some(PhpMixed::List(vec![ - PhpMixed::String(name.clone()), - PhpMixed::Bool(*is_osi_approved), - PhpMixed::String(format!( - "https://spdx.org/licenses/{}.html#licenseText", - identifier - )), - PhpMixed::Bool(*is_deprecated_license_id), - ])) + Some(LicenseMetadata { + name: name.clone(), + is_osi_approved: *is_osi_approved, + url: format!("https://spdx.org/licenses/{}.html#licenseText", identifier), + is_deprecated_license_id: *is_deprecated_license_id, + }) } pub fn validate(&self, license: &str) -> bool { -- cgit v1.3.1