diff options
Diffstat (limited to 'crates/shirabe/src/repository')
16 files changed, 229 insertions, 403 deletions
diff --git a/crates/shirabe/src/repository/artifact_repository.rs b/crates/shirabe/src/repository/artifact_repository.rs index 3715c27..b913edb 100644 --- a/crates/shirabe/src/repository/artifact_repository.rs +++ b/crates/shirabe/src/repository/artifact_repository.rs @@ -190,23 +190,17 @@ impl ArtifactRepository { let shasum = hash_file("sha1", &real_path).unwrap_or_default(); let mut dist = IndexMap::new(); - dist.insert( - "type".to_string(), - Box::new(PhpMixed::String(file_type.to_string())), - ); - dist.insert( - "url".to_string(), - Box::new(PhpMixed::String(url_normalized)), - ); - dist.insert("shasum".to_string(), Box::new(PhpMixed::String(shasum))); + dist.insert("type".to_string(), PhpMixed::String(file_type.to_string())); + dist.insert("url".to_string(), PhpMixed::String(url_normalized)); + dist.insert("shasum".to_string(), PhpMixed::String(shasum)); if let Some(arr) = package.as_array_mut() { - arr.insert("dist".to_string(), Box::new(PhpMixed::Array(dist))); + arr.insert("dist".to_string(), PhpMixed::Array(dist)); } let cfg: IndexMap<String, PhpMixed> = package .as_array() .cloned() - .map(|m| m.into_iter().map(|(k, v)| (k, *v)).collect()) + .map(|m| m.into_iter().collect()) .unwrap_or_default(); match self.loader.load(cfg, None) { Ok(package) => Ok(Some(package)), diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs index f35be80..365d1c3 100644 --- a/crates/shirabe/src/repository/composer_repository.rs +++ b/crates/shirabe/src/repository/composer_repository.rs @@ -237,7 +237,6 @@ impl ComposerRepository { .cloned() .unwrap_or_default() .into_iter() - .map(|(k, v)| (k, *v)) .collect::<IndexMap<String, PhpMixed>>(); let mut url = repo_config .get("url") @@ -738,7 +737,7 @@ impl ComposerRepository { // do not show virtual packages in results as they are not directly useful from a composer perspective if let Some(v) = arr.get("virtual") { // PHP's `empty()` is false when the value is truthy - let is_empty = match &**v { + let is_empty = match v { PhpMixed::Null => true, PhpMixed::Bool(false) => true, PhpMixed::Int(0) => true, @@ -753,11 +752,7 @@ impl ComposerRepository { } } - results.push( - arr.iter() - .map(|(k, v)| (k.clone(), (**v).clone())) - .collect(), - ); + results.push(arr.iter().map(|(k, v)| (k.clone(), v.clone())).collect()); } return Ok(results); @@ -923,11 +918,8 @@ impl ComposerRepository { let advisory = PartialSecurityAdvisory::create(name, data, &parser)?; let is_full = matches!(advisory, AnySecurityAdvisory::Full(_)); if !allow_partial_advisories && !is_full { - let data_mixed = PhpMixed::Array( - data.iter() - .map(|(k, v)| (k.clone(), Box::new(v.clone()))) - .collect(), - ); + let data_mixed = + PhpMixed::Array(data.iter().map(|(k, v)| (k.clone(), v.clone())).collect()); return Err(RuntimeException { message: format!( "Advisory for {} could not be loaded as a full advisory from {}{}{}", @@ -976,7 +968,7 @@ impl ComposerRepository { let response = spec .as_list() .and_then(|l| l.first()) - .map(|b| (**b).clone()) + .cloned() .unwrap_or(PhpMixed::Null); let response_arr = match response.as_array() { Some(a) => a.clone(), @@ -995,10 +987,8 @@ impl ComposerRepository { let mut entries: Vec<AnySecurityAdvisory> = Vec::new(); for (_k, data_mixed) in sec_advs_arr.iter() { if let Some(data) = data_mixed.as_array() { - let data_map: IndexMap<String, PhpMixed> = data - .iter() - .map(|(k, v)| (k.clone(), (**v).clone())) - .collect(); + let data_map: IndexMap<String, PhpMixed> = + data.iter().map(|(k, v)| (k.clone(), v.clone())).collect(); if let Some(adv) = create(&data_map, &name, &package_constraint_map)? { entries.push(adv); } @@ -1018,30 +1008,27 @@ impl ComposerRepository { .entry("http".to_string()) .or_insert(PhpMixed::Array(IndexMap::new())); if let PhpMixed::Array(http_map) = http_entry { - http_map.insert( - "method".to_string(), - Box::new(PhpMixed::String("POST".to_string())), - ); - if let Some(header_box) = http_map.get("header") { + http_map.insert("method".to_string(), PhpMixed::String("POST".to_string())); + if let Some(header_val) = http_map.get("header") { // cast to array - let arr = match &**header_box { + let arr = match header_val { PhpMixed::List(l) => l.clone(), - other => vec![Box::new(other.clone())], + other => vec![other.clone()], }; - http_map.insert("header".to_string(), Box::new(PhpMixed::List(arr))); + http_map.insert("header".to_string(), PhpMixed::List(arr)); } let mut headers = match http_map.get("header") { - Some(b) => match &**b { + Some(b) => match b { PhpMixed::List(l) => l.clone(), _ => vec![], }, None => vec![], }; - headers.push(Box::new(PhpMixed::String( + headers.push(PhpMixed::String( "Content-type: application/x-www-form-urlencoded".to_string(), - ))); - http_map.insert("header".to_string(), Box::new(PhpMixed::List(headers))); - http_map.insert("timeout".to_string(), Box::new(PhpMixed::Int(10))); + )); + http_map.insert("header".to_string(), PhpMixed::List(headers)); + http_map.insert("timeout".to_string(), PhpMixed::Int(10)); let packages_list: Vec<(String, String)> = package_constraint_map .keys() .map(|k| ("packages".to_string(), k.clone())) @@ -1054,7 +1041,7 @@ impl ComposerRepository { "&", "=", ); - http_map.insert("content".to_string(), Box::new(PhpMixed::String(body))); + http_map.insert("content".to_string(), PhpMixed::String(body)); } let response = self.http_downloader.borrow_mut().get(&api_url, options)?; @@ -1087,10 +1074,8 @@ impl ComposerRepository { let mut entries: Vec<AnySecurityAdvisory> = Vec::new(); for data_mixed in list.iter() { if let Some(data) = data_mixed.as_array() { - let data_map: IndexMap<String, PhpMixed> = data - .iter() - .map(|(k, v)| (k.clone(), (**v).clone())) - .collect(); + let data_map: IndexMap<String, PhpMixed> = + data.iter().map(|(k, v)| (k.clone(), v.clone())).collect(); if let Some(adv) = create(&data_map, name, &package_constraint_map)? { entries.push(adv); } @@ -1147,7 +1132,7 @@ impl ComposerRepository { { let entry: IndexMap<String, PhpMixed> = provider .iter() - .map(|(k, v)| (k.clone(), (**v).clone())) + .map(|(k, v)| (k.clone(), v.clone())) .collect(); result.insert(name.to_string(), entry); } @@ -1343,10 +1328,8 @@ impl ComposerRepository { if let Some(raw) = self.cache.read(&cache_key) { let decoded = json_decode(&raw, true)?; if let Some(arr) = decoded.as_array() { - let map: IndexMap<String, PhpMixed> = arr - .iter() - .map(|(k, v)| (k.clone(), (**v).clone())) - .collect(); + let map: IndexMap<String, PhpMixed> = + arr.iter().map(|(k, v)| (k.clone(), v.clone())).collect(); packages_opt = Some(map); packages_source = Some(format!( "cached file ({} originating from {})", @@ -1363,10 +1346,8 @@ impl ComposerRepository { // we already loaded some packages from this file, so assume it is fresh and avoid fetching it again if already_loaded.contains_key(name) { if let Some(arr) = &contents_arr { - let map: IndexMap<String, PhpMixed> = arr - .iter() - .map(|(k, v)| (k.clone(), (**v).clone())) - .collect(); + let map: IndexMap<String, PhpMixed> = + arr.iter().map(|(k, v)| (k.clone(), v.clone())).collect(); packages_opt = Some(map); packages_source = Some(format!( "cached file ({} originating from {})", @@ -1382,10 +1363,8 @@ impl ComposerRepository { self.fetch_file_if_last_modified(&url, &cache_key, last_modified)?; match response { FetchFileIfLastModifiedResult::NotModified => { - let map: IndexMap<String, PhpMixed> = arr - .iter() - .map(|(k, v)| (k.clone(), (**v).clone())) - .collect(); + let map: IndexMap<String, PhpMixed> = + arr.iter().map(|(k, v)| (k.clone(), v.clone())).collect(); packages_opt = Some(map); packages_source = Some(format!( "cached file ({} originating from {})", @@ -1424,10 +1403,7 @@ impl ComposerRepository { Some(c) => PhpMixed::Int(c), None => PhpMixed::Null, }, - &PhpMixed::List(vec![ - Box::new(PhpMixed::Int(404)), - Box::new(PhpMixed::Int(499)), - ]), + &PhpMixed::List(vec![PhpMixed::Int(404), PhpMixed::Int(499)]), true, ) { @@ -1466,23 +1442,14 @@ impl ComposerRepository { .get(name) .cloned() .unwrap_or_default(); - let entries_mixed: Vec<Box<PhpMixed>> = entries + let entries_mixed: Vec<PhpMixed> = entries .into_iter() - .map(|m| { - Box::new(PhpMixed::Array( - m.into_iter().map(|(k, v)| (k, Box::new(v))).collect(), - )) - }) + .map(|m| PhpMixed::Array(m.into_iter().collect())) .collect(); versions_map.insert("versions".to_string(), PhpMixed::List(entries_mixed)); packages_inner.insert( "packages".to_string(), - PhpMixed::Array( - versions_map - .into_iter() - .map(|(k, v)| (k, Box::new(v))) - .collect(), - ), + PhpMixed::Array(versions_map.into_iter().collect()), ); packages = packages_inner; packages_source = Some(format!( @@ -1501,9 +1468,9 @@ impl ComposerRepository { .unwrap_or_default(); for (_pkg_key, versions_mixed) in packages_inner.iter() { // $versions can be either array<string, array> or list<array> - let iter_versions: Vec<PhpMixed> = match &**versions_mixed { - PhpMixed::Array(a) => a.values().map(|v| (**v).clone()).collect(), - PhpMixed::List(l) => l.iter().map(|v| (**v).clone()).collect(), + let iter_versions: Vec<PhpMixed> = match versions_mixed { + PhpMixed::Array(a) => a.values().map(|v| v.clone()).collect(), + PhpMixed::List(l) => l.clone(), _ => continue, }; for version_mixed in iter_versions.iter() { @@ -1513,7 +1480,7 @@ impl ComposerRepository { }; let mut version: IndexMap<String, PhpMixed> = version_arr .iter() - .map(|(k, v)| (k.clone(), (**v).clone())) + .map(|(k, v)| (k.clone(), v.clone())) .collect(); let normalized_name = strtolower( version @@ -1735,14 +1702,8 @@ impl ComposerRepository { // [$response, $packagesSource] = $spec; let spec_list = spec.as_list().cloned().unwrap_or_default(); - let response = spec_list - .first() - .map(|b| (**b).clone()) - .unwrap_or(PhpMixed::Null); - let packages_source_val = spec_list - .get(1) - .map(|b| (**b).clone()) - .unwrap_or(PhpMixed::Null); + let response = spec_list.first().cloned().unwrap_or(PhpMixed::Null); + let packages_source_val = spec_list.get(1).cloned().unwrap_or(PhpMixed::Null); let packages_source: Option<String> = packages_source_val.as_string().map(|s| s.to_string()); if response.is_null() { @@ -1758,7 +1719,7 @@ impl ComposerRepository { .and_then(|a| a.get(&real_name)) .cloned() { - Some(b) => *b, + Some(b) => b, None => continue, }; @@ -1768,7 +1729,7 @@ impl ComposerRepository { .filter_map(|v| { v.as_array().map(|a| { a.iter() - .map(|(k, v)| (k.clone(), (**v).clone())) + .map(|(k, v)| (k.clone(), v.clone())) .collect::<IndexMap<String, PhpMixed>>() }) }) @@ -1778,7 +1739,7 @@ impl ComposerRepository { .filter_map(|v| { v.as_array().map(|a| { a.iter() - .map(|(k, v)| (k.clone(), (**v).clone())) + .map(|(k, v)| (k.clone(), v.clone())) .collect::<IndexMap<String, PhpMixed>>() }) }) @@ -1909,10 +1870,8 @@ impl ComposerRepository { if let Some(raw) = self.cache.read(&cache_key) { let decoded = json_decode(&raw, true)?; if let Some(arr) = decoded.as_array() { - let map: IndexMap<String, PhpMixed> = arr - .iter() - .map(|(k, v)| (k.clone(), (**v).clone())) - .collect(); + let map: IndexMap<String, PhpMixed> = + arr.iter().map(|(k, v)| (k.clone(), v.clone())).collect(); last_modified = map .get("last-modified") .and_then(|v| v.as_string()) @@ -1939,7 +1898,7 @@ impl ComposerRepository { Url::sanitize(url.clone()) ); contents_opt - .map(|m| PhpMixed::Array(m.into_iter().map(|(k, v)| (k, Box::new(v))).collect())) + .map(|m| PhpMixed::Array(m.into_iter().collect())) .unwrap_or(PhpMixed::Null) } else { response @@ -1953,14 +1912,14 @@ impl ComposerRepository { let has_advisories = response_arr.is_some_and(|a| a.contains_key("security-advisories")); if !has_pkg && !has_advisories { return Ok(PhpMixed::List(vec![ - Box::new(PhpMixed::Null), - Box::new(PhpMixed::String(packages_source)), + PhpMixed::Null, + PhpMixed::String(packages_source), ])); } Ok(PhpMixed::List(vec![ - Box::new(response_data), - Box::new(PhpMixed::String(packages_source)), + response_data, + PhpMixed::String(packages_source), ])) } @@ -2079,10 +2038,8 @@ impl ComposerRepository { if let Some(cached_raw) = self.cache.read("packages.json") { let cached_decoded = json_decode(&cached_raw, true)?; if let Some(arr) = cached_decoded.as_array() { - let cached_data: IndexMap<String, PhpMixed> = arr - .iter() - .map(|(k, v)| (k.clone(), (**v).clone())) - .collect(); + let cached_data: IndexMap<String, PhpMixed> = + arr.iter().map(|(k, v)| (k.clone(), v.clone())).collect(); let age = self.cache.get_age("packages.json"); if root_max_age.is_some() && age.is_some() && age.unwrap() <= root_max_age.unwrap() { @@ -2477,7 +2434,7 @@ impl ComposerRepository { let decoded = json_decode(&raw, true)?; decoded .as_array() - .map(|a| a.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()) + .map(|a| a.iter().map(|(k, v)| (k.clone(), v.clone())).collect()) .unwrap_or_default() } else { self.fetch_file(&url, Some(&cache_key), Some(&sha256), false)? @@ -2505,8 +2462,7 @@ impl ComposerRepository { if let Some(versions) = pkg.get("versions").and_then(|v| v.as_array()) { for (_, metadata) in versions.iter() { if let Some(m) = metadata.as_array() { - packages - .push(m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()); + packages.push(m.iter().map(|(k, v)| (k.clone(), v.clone())).collect()); } } } @@ -2529,7 +2485,7 @@ impl ComposerRepository { }; let metadata_map: IndexMap<String, PhpMixed> = metadata .iter() - .map(|(k, v)| (k.clone(), (**v).clone())) + .map(|(k, v)| (k.clone(), v.clone())) .collect(); packages.push(metadata_map.clone()); let meta_name = metadata_map @@ -2566,7 +2522,7 @@ impl ComposerRepository { let decoded = json_decode(&raw, true)?; decoded .as_array() - .map(|a| a.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()) + .map(|a| a.iter().map(|(k, v)| (k.clone(), v.clone())).collect()) .unwrap_or_default() } else { self.fetch_file(include, None, None, false)? @@ -2724,13 +2680,8 @@ impl ComposerRepository { m.into() }, ); - pre_file_download_event.set_transport_options( - self.options - .clone() - .into_iter() - .map(|(k, v)| (k, Box::new(v))) - .collect(), - ); + pre_file_download_event + .set_transport_options(self.options.clone().into_iter().collect()); let pre_file_download_event_name = pre_file_download_event.get_name().to_string(); dispatcher.dispatch( @@ -2741,7 +2692,7 @@ impl ComposerRepository { options = pre_file_download_event .get_transport_options() .iter() - .map(|(k, v)| (k.clone(), (**v).clone())) + .map(|(k, v)| (k.clone(), v.clone())) .collect(); } @@ -2802,7 +2753,7 @@ impl ComposerRepository { let decoded = response.decode_json()?; let mut data_local: IndexMap<String, PhpMixed> = decoded .as_array() - .map(|a| a.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()) + .map(|a| a.iter().map(|(k, v)| (k.clone(), v.clone())).collect()) .unwrap_or_default(); HttpDownloader::output_warnings(self.io.clone(), &self.url, &data_local); @@ -2820,7 +2771,7 @@ impl ComposerRepository { let as_mixed = PhpMixed::Array( data_local .iter() - .map(|(k, v)| (k.clone(), Box::new(v.clone()))) + .map(|(k, v)| (k.clone(), v.clone())) .collect(), ); json = JsonFile::encode_with_options(&as_mixed, JsonEncodeOptions::none()); @@ -2870,7 +2821,7 @@ impl ComposerRepository { )?; let map: IndexMap<String, PhpMixed> = parsed .as_array() - .map(|a| a.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()) + .map(|a| a.iter().map(|(k, v)| (k.clone(), v.clone())).collect()) .unwrap_or_default(); data = Some(map); @@ -2921,13 +2872,8 @@ impl ComposerRepository { m.into() }, ); - pre_file_download_event.set_transport_options( - self.options - .clone() - .into_iter() - .map(|(k, v)| (k, Box::new(v))) - .collect(), - ); + pre_file_download_event + .set_transport_options(self.options.clone().into_iter().collect()); let pre_file_download_event_name = pre_file_download_event.get_name().to_string(); dispatcher.dispatch( Some(&pre_file_download_event_name), @@ -2937,7 +2883,7 @@ impl ComposerRepository { options = pre_file_download_event .get_transport_options() .iter() - .map(|(k, v)| (k.clone(), (**v).clone())) + .map(|(k, v)| (k.clone(), v.clone())) .collect(); } @@ -2947,24 +2893,24 @@ impl ComposerRepository { .or_insert(PhpMixed::Array(IndexMap::new())); if let PhpMixed::Array(http_map) = http_entry { if let Some(existing) = http_map.get("header") { - let arr = match &**existing { + let arr = match existing { PhpMixed::List(l) => l.clone(), - other => vec![Box::new(other.clone())], + other => vec![other.clone()], }; - http_map.insert("header".to_string(), Box::new(PhpMixed::List(arr))); + http_map.insert("header".to_string(), PhpMixed::List(arr)); } let mut headers = match http_map.get("header") { - Some(b) => match &**b { + Some(b) => match b { PhpMixed::List(l) => l.clone(), _ => vec![], }, None => vec![], }; - headers.push(Box::new(PhpMixed::String(format!( + headers.push(PhpMixed::String(format!( "If-Modified-Since: {}", last_modified_time - )))); - http_map.insert("header".to_string(), Box::new(PhpMixed::List(headers))); + ))); + http_map.insert("header".to_string(), PhpMixed::List(headers)); } let mut response = self @@ -3001,7 +2947,7 @@ impl ComposerRepository { let decoded = response.decode_json()?; let mut data: IndexMap<String, PhpMixed> = decoded .as_array() - .map(|a| a.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()) + .map(|a| a.iter().map(|(k, v)| (k.clone(), v.clone())).collect()) .unwrap_or_default(); HttpDownloader::output_warnings(self.io.clone(), &self.url, &data); @@ -3009,11 +2955,8 @@ impl ComposerRepository { response.collect(); if let Some(ref lmd) = last_modified_date { data.insert("last-modified".to_string(), PhpMixed::String(lmd.clone())); - let as_mixed = PhpMixed::Array( - data.iter() - .map(|(k, v)| (k.clone(), Box::new(v.clone()))) - .collect(), - ); + let as_mixed = + PhpMixed::Array(data.iter().map(|(k, v)| (k.clone(), v.clone())).collect()); json = JsonFile::encode_with_options(&as_mixed, JsonEncodeOptions::none()); } if !self.cache.is_read_only() { @@ -3066,9 +3009,7 @@ impl ComposerRepository { if self.packages_not_found_cache.contains_key(filename) { let mut empty: IndexMap<String, PhpMixed> = IndexMap::new(); empty.insert("packages".to_string(), PhpMixed::Array(IndexMap::new())); - return Ok(PhpMixed::Array( - empty.into_iter().map(|(k, v)| (k, Box::new(v))).collect(), - )); + return Ok(PhpMixed::Array(empty.into_iter().collect())); } if self.fresh_metadata_urls.contains_key(filename) && last_modified_time.is_some() { @@ -3091,13 +3032,8 @@ impl ComposerRepository { m.into() }, ); - pre_file_download_event.set_transport_options( - self.options - .clone() - .into_iter() - .map(|(k, v)| (k, Box::new(v))) - .collect(), - ); + pre_file_download_event + .set_transport_options(self.options.clone().into_iter().collect()); let pre_file_download_event_name = pre_file_download_event.get_name().to_string(); dispatcher.dispatch( Some(&pre_file_download_event_name), @@ -3107,7 +3043,7 @@ impl ComposerRepository { options = pre_file_download_event .get_transport_options() .iter() - .map(|(k, v)| (k.clone(), (**v).clone())) + .map(|(k, v)| (k.clone(), v.clone())) .collect(); } @@ -3117,24 +3053,24 @@ impl ComposerRepository { .or_insert(PhpMixed::Array(IndexMap::new())); if let PhpMixed::Array(http_map) = http_entry { if let Some(existing) = http_map.get("header") { - let arr = match &**existing { + let arr = match existing { PhpMixed::List(l) => l.clone(), - other => vec![Box::new(other.clone())], + other => vec![other.clone()], }; - http_map.insert("header".to_string(), Box::new(PhpMixed::List(arr))); + http_map.insert("header".to_string(), PhpMixed::List(arr)); } let mut headers = match http_map.get("header") { - Some(b) => match &**b { + Some(b) => match b { PhpMixed::List(l) => l.clone(), _ => vec![], }, None => vec![], }; - headers.push(Box::new(PhpMixed::String(format!( + headers.push(PhpMixed::String(format!( "If-Modified-Since: {}", last_modified_time - )))); - http_map.insert("header".to_string(), Box::new(PhpMixed::List(headers))); + ))); + http_map.insert("header".to_string(), PhpMixed::List(headers)); } } @@ -3164,9 +3100,7 @@ impl ComposerRepository { let mut empty: IndexMap<String, PhpMixed> = IndexMap::new(); empty.insert("packages".to_string(), PhpMixed::Array(IndexMap::new())); - return Ok(PhpMixed::Array( - empty.into_iter().map(|(k, v)| (k, Box::new(v))).collect(), - )); + return Ok(PhpMixed::Array(empty.into_iter().collect())); } let mut json = response.get_body().unwrap_or("").to_string(); @@ -3181,7 +3115,7 @@ impl ComposerRepository { let decoded = response.decode_json()?; let mut data: IndexMap<String, PhpMixed> = decoded .as_array() - .map(|a| a.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()) + .map(|a| a.iter().map(|(k, v)| (k.clone(), v.clone())).collect()) .unwrap_or_default(); HttpDownloader::output_warnings(self.io.clone(), &self.url, &data); @@ -3189,11 +3123,8 @@ impl ComposerRepository { response.collect(); if let Some(lmd) = last_modified_date { data.insert("last-modified".to_string(), PhpMixed::String(lmd)); - let as_mixed = PhpMixed::Array( - data.iter() - .map(|(k, v)| (k.clone(), Box::new(v.clone()))) - .collect(), - ); + let as_mixed = + PhpMixed::Array(data.iter().map(|(k, v)| (k.clone(), v.clone())).collect()); json = JsonFile::encode_with_options( &as_mixed, JsonEncodeOptions { @@ -3207,9 +3138,7 @@ impl ComposerRepository { } self.fresh_metadata_urls.insert(filename.to_string(), true); - Ok(PhpMixed::Array( - data.into_iter().map(|(k, v)| (k, Box::new(v))).collect(), - )) + Ok(PhpMixed::Array(data.into_iter().collect())) } /// The onRejected handler of `asyncFetchFile`: marks the package as not found / the repo as @@ -3290,7 +3219,7 @@ impl ComposerRepository { let version_package_name = strtolower(&name_str); let version_map: IndexMap<String, PhpMixed> = version .iter() - .map(|(k, v)| (k.clone(), (**v).clone())) + .map(|(k, v)| (k.clone(), v.clone())) .collect(); self.partial_packages_by_name .as_mut() diff --git a/crates/shirabe/src/repository/filesystem_repository.rs b/crates/shirabe/src/repository/filesystem_repository.rs index 79136c9..86887d1 100644 --- a/crates/shirabe/src/repository/filesystem_repository.rs +++ b/crates/shirabe/src/repository/filesystem_repository.rs @@ -110,7 +110,7 @@ impl FilesystemRepository { let data = self.file.read()?; let packages_value = if let PhpMixed::Array(ref m) = data { if m.contains_key("packages") { - (*m.get("packages").unwrap().clone()).clone() + m.get("packages").unwrap().clone() } else { data.clone() } @@ -163,30 +163,14 @@ impl FilesystemRepository { let mut loader = ArrayLoader::new(None, true); if let Some(packages_list) = packages.as_list() { for package_data in packages_list.iter() { - let cfg = (**package_data) - .as_array() - .cloned() - .map(|m| { - m.into_iter() - .map(|(k, v)| (k, *v)) - .collect::<IndexMap<String, PhpMixed>>() - }) - .unwrap_or_default(); + let cfg = package_data.as_array().cloned().unwrap_or_default(); let package = loader.load(cfg, Some("Composer\\Package\\CompletePackage".to_string()))?; self.inner.add_package(package)?; } } else if let Some(packages_array) = packages.as_array() { for (_, package_data) in packages_array.iter() { - let cfg = (**package_data) - .as_array() - .cloned() - .map(|m| { - m.into_iter() - .map(|(k, v)| (k, *v)) - .collect::<IndexMap<String, PhpMixed>>() - }) - .unwrap_or_default(); + let cfg = package_data.as_array().cloned().unwrap_or_default(); let package = loader.load(cfg, Some("Composer\\Package\\CompletePackage".to_string()))?; self.inner.add_package(package)?; @@ -286,12 +270,7 @@ impl FilesystemRepository { }, ); if let Some(PhpMixed::List(list)) = data.get_mut("packages") { - list.push(Box::new(PhpMixed::Array( - pkg_array - .into_iter() - .map(|(k, v)| (k, Box::new(v))) - .collect(), - ))); + list.push(PhpMixed::Array(pkg_array.into_iter().collect())); } // only write to the files the names which are really installed, as we receive the full list @@ -302,25 +281,25 @@ impl FilesystemRepository { self.inner .dev_package_names .iter() - .map(|s| Box::new(PhpMixed::String(s.clone()))) + .map(|s| PhpMixed::String(s.clone())) .collect(), ), true, ) && let Some(PhpMixed::List(list)) = data.get_mut("dev-package-names") { - list.push(Box::new(PhpMixed::String(package.get_name().to_string()))); + list.push(PhpMixed::String(package.get_name().to_string())); } } // PHP: sort($data['dev-package-names']); if let Some(PhpMixed::List(list)) = data.get_mut("dev-package-names") { - usort(list, |a: &Box<PhpMixed>, b: &Box<PhpMixed>| -> i64 { + usort(list, |a: &PhpMixed, b: &PhpMixed| -> i64 { shirabe_php_shim::strcmp(a.as_string().unwrap_or(""), b.as_string().unwrap_or("")) }); } // PHP: usort($data['packages'], static function ($a, $b): int { return strcmp($a['name'], $b['name']); }); if let Some(PhpMixed::List(list)) = data.get_mut("packages") { - usort(list, |a: &Box<PhpMixed>, b: &Box<PhpMixed>| -> i64 { + usort(list, |a: &PhpMixed, b: &PhpMixed| -> i64 { let a_name = a .as_array() .and_then(|m| m.get("name")) @@ -335,12 +314,8 @@ impl FilesystemRepository { }); } - self.file.write(PhpMixed::Array( - data.clone() - .into_iter() - .map(|(k, v)| (k, Box::new(v))) - .collect(), - ))?; + self.file + .write(PhpMixed::Array(data.clone().into_iter().collect()))?; if self.dump_versions { let versions = self.generate_installed_versions( @@ -403,7 +378,7 @@ impl FilesystemRepository { evaluated .as_array() .cloned() - .map(|m| m.into_iter().map(|(k, v)| (k, *v)).collect()) + .map(|m| m.into_iter().collect()) .unwrap_or_default(), ); @@ -432,7 +407,7 @@ impl FilesystemRepository { if !inner_arr.is_empty() { let inner_map: IndexMap<String, PhpMixed> = inner_arr .iter() - .map(|(k, v)| (k.clone(), (**v).clone())) + .map(|(k, v)| (k.clone(), v.clone())) .collect(); lines.push_str(&self.dump_to_php_code(&inner_map, level)); } else { @@ -443,7 +418,7 @@ impl FilesystemRepository { let inner_map: IndexMap<String, PhpMixed> = list .iter() .enumerate() - .map(|(i, v)| (i.to_string(), (**v).clone())) + .map(|(i, v)| (i.to_string(), v.clone())) .collect(); lines.push_str(&self.dump_to_php_code(&inner_map, level)); } else { @@ -493,7 +468,7 @@ impl FilesystemRepository { self.inner .dev_package_names .iter() - .map(|s| Box::new(PhpMixed::String(s.clone()))) + .map(|s| PhpMixed::String(s.clone())) .collect(), )); let mut packages: Vec<PackageInterfaceHandle> = @@ -531,7 +506,6 @@ impl FilesystemRepository { &dev_packages, ) .into_iter() - .map(|(k, v)| (k, Box::new(v))) .collect(), ), ); @@ -552,9 +526,7 @@ impl FilesystemRepository { if let Some(PhpMixed::Array(versions_map)) = versions.get_mut("versions") { versions_map.insert( package.get_name().to_string(), - Box::new(PhpMixed::Array( - dumped.into_iter().map(|(k, v)| (k, Box::new(v))).collect(), - )), + PhpMixed::Array(dumped.into_iter().collect()), ); } } @@ -626,13 +598,13 @@ impl FilesystemRepository { if let Some(PhpMixed::Array(versions_map)) = versions.get_mut("versions") { for (_name, version) in versions_map.iter_mut() { - if let PhpMixed::Array(version_map) = version.as_mut() { + if let PhpMixed::Array(version_map) = version { for key in ["aliases", "replaced", "provided"] { - if let Some(boxed) = version_map.get_mut(key) - && let PhpMixed::List(list) = boxed.as_mut() + if let Some(entry) = version_map.get_mut(key) + && let PhpMixed::List(list) = entry { // PHP: sort($versions['versions'][$name][$key], SORT_NATURAL); - usort(list, |a: &Box<PhpMixed>, b: &Box<PhpMixed>| -> i64 { + usort(list, |a: &PhpMixed, b: &PhpMixed| -> i64 { shirabe_php_shim::strnatcmp( a.as_string().unwrap_or(""), b.as_string().unwrap_or(""), @@ -871,28 +843,26 @@ impl RepositoryInterface for FilesystemRepository { fn versions_entry<'a>( versions: &'a mut IndexMap<String, PhpMixed>, target: &str, -) -> &'a mut IndexMap<String, Box<PhpMixed>> { +) -> &'a mut IndexMap<String, PhpMixed> { let versions_map = match versions.get_mut("versions") { Some(PhpMixed::Array(m)) => m, _ => unreachable!("versions['versions'] is always an array"), }; match versions_map .entry(target.to_string()) - .or_insert_with(|| Box::new(PhpMixed::Array(IndexMap::new()))) - .as_mut() + .or_insert_with(|| PhpMixed::Array(IndexMap::new())) { PhpMixed::Array(m) => m, _ => unreachable!("versions['versions'][target] is always an array"), } } -fn push_to_list(entry: &mut IndexMap<String, Box<PhpMixed>>, key: &str, value: String) { +fn push_to_list(entry: &mut IndexMap<String, PhpMixed>, key: &str, value: String) { if let PhpMixed::List(list) = entry .entry(key.to_string()) - .or_insert_with(|| Box::new(PhpMixed::List(vec![]))) - .as_mut() + .or_insert_with(|| PhpMixed::List(vec![])) { - list.push(Box::new(PhpMixed::String(value))); + list.push(PhpMixed::String(value)); } } @@ -907,17 +877,14 @@ fn record_replace_or_provide( if !entry.contains_key("dev_requirement") { entry.insert( "dev_requirement".to_string(), - Box::new(PhpMixed::Bool(is_dev_package)), + PhpMixed::Bool(is_dev_package), ); } else if !is_dev_package { - entry.insert( - "dev_requirement".to_string(), - Box::new(PhpMixed::Bool(false)), - ); + entry.insert("dev_requirement".to_string(), PhpMixed::Bool(false)); } let already_present = match entry.get(key) { Some(b) => matches!( - b.as_ref(), + b, PhpMixed::List(list) if list.iter().any(|v| v.as_string() == Some(value.as_str())) ), None => false, diff --git a/crates/shirabe/src/repository/filter_repository.rs b/crates/shirabe/src/repository/filter_repository.rs index 90e211f..0882973 100644 --- a/crates/shirabe/src/repository/filter_repository.rs +++ b/crates/shirabe/src/repository/filter_repository.rs @@ -37,7 +37,7 @@ impl FilterRepository { let names: Vec<String> = list .iter() .filter_map(|v| { - if let PhpMixed::String(s) = v.as_ref() { + if let PhpMixed::String(s) = v { Some(s.clone()) } else { None @@ -67,7 +67,7 @@ impl FilterRepository { let names: Vec<String> = list .iter() .filter_map(|v| { - if let PhpMixed::String(s) = v.as_ref() { + if let PhpMixed::String(s) = v { Some(s.clone()) } else { None diff --git a/crates/shirabe/src/repository/package_repository.rs b/crates/shirabe/src/repository/package_repository.rs index 5ba4840..554e24a 100644 --- a/crates/shirabe/src/repository/package_repository.rs +++ b/crates/shirabe/src/repository/package_repository.rs @@ -24,7 +24,7 @@ impl PackageRepository { pub fn new(config: IndexMap<String, PhpMixed>) -> Self { let package = config.get("package").cloned().unwrap_or(PhpMixed::Null); let config_list: Vec<PhpMixed> = match package { - PhpMixed::List(list) => list.into_iter().map(|p| *p).collect(), + PhpMixed::List(list) => list.into_iter().collect(), other => vec![other], }; @@ -33,7 +33,7 @@ impl PackageRepository { .cloned() .unwrap_or(PhpMixed::Array(IndexMap::new())) { - PhpMixed::Array(map) => map.into_iter().map(|(k, v)| (k, *v)).collect(), + PhpMixed::Array(map) => map, _ => IndexMap::new(), }; @@ -51,8 +51,8 @@ impl PackageRepository { let mut loader = ValidatingArrayLoader::new(Box::new(ArrayLoader::new(None, true)), true, None, 0); for package in &self.config { - let config_map: IndexMap<String, Box<PhpMixed>> = match package { - PhpMixed::Array(m) => m.clone(), + let config_map: IndexMap<String, PhpMixed> = match package { + PhpMixed::Array(m) => m.iter().map(|(k, v)| (k.clone(), v.clone())).collect(), _ => IndexMap::new(), }; let package_loaded = match loader.load(config_map, "") { @@ -104,8 +104,8 @@ impl AdvisoryProviderInterface for PackageRepository { }; let mut items: Vec<AnySecurityAdvisory> = Vec::new(); for data in list { - let data_map: IndexMap<String, PhpMixed> = match data.as_ref() { - PhpMixed::Array(m) => m.iter().map(|(k, v)| (k.clone(), *v.clone())).collect(), + let data_map: IndexMap<String, PhpMixed> = match data { + PhpMixed::Array(m) => m.clone(), _ => continue, }; let advisory = diff --git a/crates/shirabe/src/repository/path_repository.rs b/crates/shirabe/src/repository/path_repository.rs index 160c917..4508460 100644 --- a/crates/shirabe/src/repository/path_repository.rs +++ b/crates/shirabe/src/repository/path_repository.rs @@ -82,7 +82,6 @@ impl PathRepository { .cloned() .unwrap_or_default() .into_iter() - .map(|(k, v)| (k, *v)) .collect::<IndexMap<String, PhpMixed>>(); if !options.contains_key("relative") { let filesystem = Filesystem::new(None); @@ -152,16 +151,13 @@ impl PathRepository { let json = file_get_contents(&composer_file_path).unwrap_or_default(); let parsed = JsonFile::parse_json(Some(&json), Some(&composer_file_path))?; let mut package: IndexMap<String, PhpMixed> = match parsed { - PhpMixed::Array(m) => m.into_iter().map(|(k, v)| (k, *v)).collect(), + PhpMixed::Array(m) => m.into_iter().collect(), _ => IndexMap::new(), }; let dist = { - let mut dist = IndexMap::new(); - dist.insert( - "type".to_string(), - Box::new(PhpMixed::String("path".to_string())), - ); - dist.insert("url".to_string(), Box::new(PhpMixed::String(url.clone()))); + let mut dist: IndexMap<String, PhpMixed> = IndexMap::new(); + dist.insert("type".to_string(), PhpMixed::String("path".to_string())); + dist.insert("url".to_string(), PhpMixed::String(url.clone())); dist }; package.insert("dist".to_string(), PhpMixed::Array(dist)); @@ -174,30 +170,27 @@ impl PathRepository { .to_string(); if reference == "none" { if let Some(PhpMixed::Array(dist)) = package.get_mut("dist") { - dist.insert("reference".to_string(), Box::new(PhpMixed::Null)); + dist.insert("reference".to_string(), PhpMixed::Null); } } else if reference == "config" || reference == "auto" { let options_mixed = PhpMixed::Array( self.options .iter() - .map(|(k, v)| (k.clone(), Box::new(v.clone()))) + .map(|(k, v)| (k.clone(), v.clone())) .collect(), ); let ref_hash = hash("sha1", &format!("{}{}", json, serialize(&options_mixed))); if let Some(PhpMixed::Array(dist)) = package.get_mut("dist") { - dist.insert( - "reference".to_string(), - Box::new(PhpMixed::String(ref_hash)), - ); + dist.insert("reference".to_string(), PhpMixed::String(ref_hash)); } } // copy symlink/relative options to transport options - let transport_options: IndexMap<String, Box<PhpMixed>> = self + let transport_options: IndexMap<String, PhpMixed> = self .options .iter() .filter(|(k, _)| k.as_str() == "symlink" || k.as_str() == "relative") - .map(|(k, v)| (k.clone(), Box::new(v.clone()))) + .map(|(k, v)| (k.clone(), v.clone())) .collect(); package.insert( "transport-options".to_string(), @@ -274,7 +267,7 @@ impl PathRepository { .trim() .to_string(); if let Some(PhpMixed::Array(dist)) = package.get_mut("dist") { - dist.insert("reference".to_string(), Box::new(PhpMixed::String(ref_val))); + dist.insert("reference".to_string(), PhpMixed::String(ref_val)); } } diff --git a/crates/shirabe/src/repository/platform_repository.rs b/crates/shirabe/src/repository/platform_repository.rs index f345eaa..e006d19 100644 --- a/crates/shirabe/src/repository/platform_repository.rs +++ b/crates/shirabe/src/repository/platform_repository.rs @@ -325,7 +325,7 @@ impl PlatformRepository { loaded_extensions .iter() .enumerate() - .map(|(i, s)| (i.to_string(), Box::new(PhpMixed::String(s.clone())))) + .map(|(i, s)| (i.to_string(), PhpMixed::String(s.clone()))) .collect(), ), true, @@ -824,13 +824,13 @@ impl PlatformRepository { Box::new(|_args| PhpMixed::Null), vec![ PhpMixed::List(vec![ - Box::new(PhpMixed::String("ResourceBundle".to_string())), - Box::new(PhpMixed::String("create".to_string())), + PhpMixed::String("ResourceBundle".to_string()), + PhpMixed::String("create".to_string()), ]), PhpMixed::List(vec![ - Box::new(PhpMixed::String("root".to_string())), - Box::new(PhpMixed::String("ICUDATA".to_string())), - Box::new(PhpMixed::Bool(false)), + PhpMixed::String("root".to_string()), + PhpMixed::String("ICUDATA".to_string()), + PhpMixed::Bool(false), ]), ], ); @@ -857,8 +857,8 @@ impl PlatformRepository { let intl_char_versions = self.runtime.invoke( Box::new(|_args| PhpMixed::Null), vec![PhpMixed::List(vec![ - Box::new(PhpMixed::String("IntlChar".to_string())), - Box::new(PhpMixed::String("getUnicodeVersion".to_string())), + PhpMixed::String("IntlChar".to_string()), + PhpMixed::String("getUnicodeVersion".to_string()), ])], ); let sliced = @@ -1840,7 +1840,7 @@ impl PlatformRepository { match value { PhpMixed::List(list) => list .iter() - .map(|v| match v.as_ref() { + .map(|v| match v { PhpMixed::String(s) => s.clone(), PhpMixed::Int(i) => i.to_string(), PhpMixed::Float(f) => f.to_string(), @@ -1849,7 +1849,7 @@ impl PlatformRepository { .collect(), PhpMixed::Array(m) => m .values() - .map(|v| match v.as_ref() { + .map(|v| match v { PhpMixed::String(s) => s.clone(), PhpMixed::Int(i) => i.to_string(), PhpMixed::Float(f) => f.to_string(), diff --git a/crates/shirabe/src/repository/repository_factory.rs b/crates/shirabe/src/repository/repository_factory.rs index d78fc48..47caf59 100644 --- a/crates/shirabe/src/repository/repository_factory.rs +++ b/crates/shirabe/src/repository/repository_factory.rs @@ -82,10 +82,8 @@ impl RepositoryFactory { if repository.starts_with('{') { let parsed = JsonFile::parse_json(Some(repository), None)?; - let repo_config: IndexMap<String, PhpMixed> = parsed - .as_array() - .map(|m| m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()) - .unwrap_or_default(); + let repo_config: IndexMap<String, PhpMixed> = + parsed.as_array().map(|m| m.clone()).unwrap_or_default(); return Ok(repo_config); } @@ -120,15 +118,8 @@ impl RepositoryFactory { owned_rm = Self::manager(io, config, None, None, None)?; &mut owned_rm }; - let repos = Self::create_repos( - rm, - vec![PhpMixed::Array( - repo_config - .into_iter() - .map(|(k, v)| (k, Box::new(v))) - .collect(), - )], - )?; + let repos = + Self::create_repos(rm, vec![PhpMixed::Array(repo_config.into_iter().collect())])?; // PHP: return current($repos); let (_, first) = repos .into_iter() @@ -276,7 +267,7 @@ impl RepositoryFactory { .to_string(); let repo_config_map: IndexMap<String, PhpMixed> = repo_arr .iter() - .map(|(k, v)| (k.clone(), *v.clone())) + .map(|(k, v)| (k.clone(), v.clone())) .collect(); let name = Self::generate_repository_name_indexed(index, &repo_config_map, &repo_map); diff --git a/crates/shirabe/src/repository/repository_manager.rs b/crates/shirabe/src/repository/repository_manager.rs index c838657..69684e2 100644 --- a/crates/shirabe/src/repository/repository_manager.rs +++ b/crates/shirabe/src/repository/repository_manager.rs @@ -110,10 +110,7 @@ impl RepositoryManager { if config.get("packagist").and_then(|v| v.as_bool()) == Some(false) { let config_json = json_encode(&PhpMixed::Array( - config - .iter() - .map(|(k, v)| (k.clone(), Box::new(v.clone()))) - .collect(), + config.iter().map(|(k, v)| (k.clone(), v.clone())).collect(), )) .unwrap_or_default(); self.io.write_error(&format!("<warning>Repository \"{}\" ({}) has a packagist key which should be in its own repository definition</warning>", name.unwrap_or(""), config_json)); diff --git a/crates/shirabe/src/repository/vcs/forgejo_driver.rs b/crates/shirabe/src/repository/vcs/forgejo_driver.rs index 3706e02..18f1cf1 100644 --- a/crates/shirabe/src/repository/vcs/forgejo_driver.rs +++ b/crates/shirabe/src/repository/vcs/forgejo_driver.rs @@ -246,7 +246,7 @@ impl ForgejoDriver { let branch_data = response.decode_json()?; if let PhpMixed::List(ref list) = branch_data { for branch in list { - if let PhpMixed::Array(ref arr) = **branch { + if let PhpMixed::Array(ref arr) = *branch { let name = arr .get("name") .and_then(|v| v.as_string()) @@ -289,7 +289,7 @@ impl ForgejoDriver { let tags_data = response.decode_json()?; if let PhpMixed::List(ref list) = tags_data { for tag in list { - if let PhpMixed::Array(ref arr) = **tag { + if let PhpMixed::Array(ref arr) = *tag { let name = arr .get("name") .and_then(|v| v.as_string()) @@ -341,9 +341,7 @@ impl ForgejoDriver { let composer = if self.inner.should_cache(identifier) { if let Some(res) = self.inner.cache.as_mut().and_then(|c| c.read(identifier)) { let parsed = JsonFile::parse_json(Some(res.as_str()), None)?; - parsed - .as_array() - .map(|m| m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()) + parsed.as_array().map(|m| m.clone()) } else { let file_content = self.get_file_content("composer.json", identifier)?; let c = VcsDriverBase::finish_base_composer_information( @@ -358,7 +356,7 @@ impl ForgejoDriver { &PhpMixed::Array( composer_map .iter() - .map(|(k, v)| (k.clone(), Box::new(v.clone()))) + .map(|(k, v)| (k.clone(), v.clone())) .collect(), ), JsonEncodeOptions { @@ -423,8 +421,7 @@ impl ForgejoDriver { }; if let Some(PhpMixed::Array(support)) = composer_map.get_mut("support") { - support - .insert("source".to_string(), Box::new(PhpMixed::String(source_url))); + support.insert("source".to_string(), PhpMixed::String(source_url)); } } @@ -442,8 +439,7 @@ impl ForgejoDriver { .unwrap_or_default() ); if let Some(PhpMixed::Array(support)) = composer_map.get_mut("support") { - support - .insert("issues".to_string(), Box::new(PhpMixed::String(issues_url))); + support.insert("issues".to_string(), PhpMixed::String(issues_url)); } } @@ -574,9 +570,7 @@ impl ForgejoDriver { return Ok(()); } if let PhpMixed::Array(ref arr) = data { - let map: IndexMap<String, PhpMixed> = - arr.iter().map(|(k, v)| (k.clone(), *v.clone())).collect(); - self.repository_data = Some(ForgejoRepositoryData::from_remote_data(&map)?); + self.repository_data = Some(ForgejoRepositoryData::from_remote_data(arr)?); } } } diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs index 44c0d08..fb450d8 100644 --- a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs @@ -198,7 +198,7 @@ impl GitBitbucketDriver { PhpMixed::Array(m) => m.get("branches"), _ => None, }) - .and_then(|v| match v.as_ref() { + .and_then(|v| match v { PhpMixed::Array(m) => m.get("href").and_then(|v| v.as_string()).map(String::from), _ => None, }) @@ -209,7 +209,7 @@ impl GitBitbucketDriver { PhpMixed::Array(m) => m.get("tags"), _ => None, }) - .and_then(|v| match v.as_ref() { + .and_then(|v| match v { PhpMixed::Array(m) => m.get("href").and_then(|v| v.as_string()).map(String::from), _ => None, }) @@ -220,7 +220,7 @@ impl GitBitbucketDriver { PhpMixed::Array(m) => m.get("html"), _ => None, }) - .and_then(|v| match v.as_ref() { + .and_then(|v| match v { PhpMixed::Array(m) => m.get("href").and_then(|v| v.as_string()).map(String::from), _ => None, }) @@ -236,7 +236,7 @@ impl GitBitbucketDriver { .map(String::from); self.repo_data = match repo_data { - PhpMixed::Array(m) => m.into_iter().map(|(k, v)| (k, *v)).collect(), + PhpMixed::Array(m) => m, _ => IndexMap::new(), }; @@ -259,7 +259,7 @@ impl GitBitbucketDriver { if let Some(res) = res { composer = JsonFile::parse_json(Some(&res), None)? .as_array() - .map(|m| m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()); + .map(|m| m.clone()); true } else { false @@ -279,12 +279,7 @@ impl GitBitbucketDriver { identifier, &JsonFile::encode_with_options( &PhpMixed::Array( - composer - .clone() - .unwrap_or_default() - .into_iter() - .map(|(k, v)| (k, Box::new(v))) - .collect(), + composer.clone().unwrap_or_default().into_iter().collect(), ), JsonEncodeOptions { pretty_print: false, @@ -316,7 +311,7 @@ impl GitBitbucketDriver { &PhpMixed::String(identifier.to_string()), &PhpMixed::Array( tags.iter() - .map(|(k, v)| (k.clone(), Box::new(PhpMixed::String(v.clone())))) + .map(|(k, v)| (k.clone(), PhpMixed::String(v.clone()))) .collect(), ), false, @@ -327,9 +322,7 @@ impl GitBitbucketDriver { &PhpMixed::Array( branches_for_search .iter() - .map(|(k, v)| { - (k.clone(), Box::new(PhpMixed::String(v.clone()))) - }) + .map(|(k, v)| (k.clone(), PhpMixed::String(v.clone()))) .collect(), ), false, @@ -354,25 +347,25 @@ impl GitBitbucketDriver { if let PhpMixed::Array(support_map) = support_entry { support_map.insert( "source".to_string(), - Box::new(PhpMixed::String(format!( + PhpMixed::String(format!( "https://{}/{}/{}/src", PhpMixed::String(self.inner.origin_url.clone()), PhpMixed::String(self.owner.clone()), PhpMixed::String(self.repository.clone()), - ))), + )), ); } } else if let PhpMixed::Array(support_map) = support_entry { support_map.insert( "source".to_string(), - Box::new(PhpMixed::String(format!( + PhpMixed::String(format!( "https://{}/{}/{}/src/{}/?at={}", PhpMixed::String(self.inner.origin_url.clone()), PhpMixed::String(self.owner.clone()), PhpMixed::String(self.repository.clone()), PhpMixed::String(hash.unwrap()), PhpMixed::String(label.clone()), - ))), + )), ); } } @@ -390,12 +383,12 @@ impl GitBitbucketDriver { if let PhpMixed::Array(support_map) = support_entry { support_map.insert( "issues".to_string(), - Box::new(PhpMixed::String(format!( + PhpMixed::String(format!( "https://{}/{}/{}/issues", PhpMixed::String(self.inner.origin_url.clone()), PhpMixed::String(self.owner.clone()), PhpMixed::String(self.repository.clone()), - ))), + )), ); } } @@ -555,7 +548,7 @@ impl GitBitbucketDriver { let values = tags_data.get("values").cloned(); if let Some(PhpMixed::List(list)) = values { for data in list { - if let PhpMixed::Array(m) = data.as_ref() { + if let PhpMixed::Array(m) = data { let name = m .get("name") .and_then(|v| v.as_string()) @@ -563,7 +556,7 @@ impl GitBitbucketDriver { .to_string(); let hash = m .get("target") - .and_then(|v| match v.as_ref() { + .and_then(|v| match v { PhpMixed::Array(m) => m.get("hash"), _ => None, }) @@ -636,7 +629,7 @@ impl GitBitbucketDriver { let values = branch_data.get("values").cloned(); if let Some(PhpMixed::List(list)) = values { for data in list { - if let PhpMixed::Array(m) = data.as_ref() { + if let PhpMixed::Array(m) = data { let name = m .get("name") .and_then(|v| v.as_string()) @@ -644,7 +637,7 @@ impl GitBitbucketDriver { .to_string(); let hash = m .get("target") - .and_then(|v| match v.as_ref() { + .and_then(|v| match v { PhpMixed::Array(m) => m.get("hash"), _ => None, }) @@ -702,10 +695,7 @@ impl GitBitbucketDriver { let code = te.get_code(); let in_set = in_array( PhpMixed::Int(code), - &PhpMixed::List(vec![ - Box::new(PhpMixed::Int(403)), - Box::new(PhpMixed::Int(404)), - ]), + &PhpMixed::List(vec![PhpMixed::Int(403), PhpMixed::Int(404)]), true, ); if in_set @@ -783,13 +773,13 @@ impl GitBitbucketDriver { } /// @param array<array{name: string, href: string}> $cloneLinks - fn parse_clone_urls(&mut self, clone_links: Option<Box<PhpMixed>>) { - let list = match clone_links.as_deref() { - Some(PhpMixed::List(l)) => l.clone(), + fn parse_clone_urls(&mut self, clone_links: Option<PhpMixed>) { + let list = match clone_links { + Some(PhpMixed::List(l)) => l, _ => return, }; for clone_link in list { - if let PhpMixed::Array(m) = clone_link.as_ref() + if let PhpMixed::Array(m) = clone_link && m.get("name").and_then(|v| v.as_string()) == Some("https") { // Format: https://(user@)bitbucket.org/{user}/{repo} diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs index 8c8c81a..e9956a9 100644 --- a/crates/shirabe/src/repository/vcs/github_driver.rs +++ b/crates/shirabe/src/repository/vcs/github_driver.rs @@ -279,9 +279,7 @@ impl GitHubDriver { .and_then(|c| c.read(identifier)) .unwrap_or_default(); let parsed = JsonFile::parse_json(Some(&res), None)?; - parsed - .as_array() - .map(|m| m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()) + parsed.as_array().map(|m| m.clone()) } else { let file_content = self.get_file_content("composer.json", identifier)?; let composer = VcsDriverBase::finish_base_composer_information( @@ -296,7 +294,7 @@ impl GitHubDriver { let php_value: PhpMixed = PhpMixed::Array( composer_map .iter() - .map(|(k, v)| (k.clone(), Box::new(v.clone()))) + .map(|(k, v)| (k.clone(), v.clone())) .collect(), ); self.inner.cache.as_mut().map(|c| { @@ -337,7 +335,7 @@ impl GitHubDriver { &PhpMixed::Array( tags_map .into_iter() - .map(|(k, v)| (k, Box::new(PhpMixed::String(v)))) + .map(|(k, v)| (k, PhpMixed::String(v))) .collect(), ), false, @@ -349,7 +347,7 @@ impl GitHubDriver { &PhpMixed::Array( branches_map .into_iter() - .map(|(k, v)| (k, Box::new(PhpMixed::String(v)))) + .map(|(k, v)| (k, PhpMixed::String(v))) .collect(), ), false, @@ -364,13 +362,13 @@ impl GitHubDriver { }) { support.insert( "source".to_string(), - Box::new(PhpMixed::String(format!( + PhpMixed::String(format!( "https://{}/{}/{}/tree/{}", PhpMixed::String(self.inner.origin_url.clone()), PhpMixed::String(self.owner.clone()), PhpMixed::String(self.repository.clone()), PhpMixed::String(label_str), - ))), + )), ); } } @@ -388,12 +386,12 @@ impl GitHubDriver { { support.insert( "issues".to_string(), - Box::new(PhpMixed::String(format!( + PhpMixed::String(format!( "https://{}/{}/{}/issues", PhpMixed::String(self.inner.origin_url.clone()), PhpMixed::String(self.owner.clone()), PhpMixed::String(self.repository.clone()), - ))), + )), ); } if !composer.contains_key("abandoned") && self.is_archived { @@ -711,11 +709,7 @@ impl GitHubDriver { let result_mixed = PhpMixed::List( result .into_iter() - .map(|m| { - Box::new(PhpMixed::Array( - m.into_iter().map(|(k, v)| (k, Box::new(v))).collect(), - )) - }) + .map(|m| PhpMixed::Array(m.into_iter().collect())) .collect(), ); self.funding_info = Some(result_mixed.clone()); @@ -854,7 +848,7 @@ impl GitHubDriver { let tags_data = response.decode_json()?; if let PhpMixed::List(ref list) = tags_data { for tag in list { - if let PhpMixed::Array(ref tag_map) = **tag { + if let PhpMixed::Array(ref tag_map) = *tag { let name = tag_map .get("name") .and_then(|v| v.as_string()) @@ -904,7 +898,7 @@ impl GitHubDriver { let branch_data = response.decode_json()?; if let PhpMixed::List(ref list) = branch_data { for branch in list { - if let PhpMixed::Array(ref branch_map) = **branch { + if let PhpMixed::Array(ref branch_map) = *branch { let ref_str = branch_map .get("ref") .and_then(|v| v.as_string()) @@ -1171,7 +1165,7 @@ impl GitHubDriver { Ok(response) => { let data = response.decode_json()?; self.repo_data = match data { - PhpMixed::Array(m) => Some(m.into_iter().map(|(k, v)| (k, *v)).collect()), + PhpMixed::Array(m) => Some(m), _ => None, }; } diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs index 0bc933e..e0fb72e 100644 --- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs +++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs @@ -121,8 +121,8 @@ impl GitLabDriver { self.scheme = if in_array( PhpMixed::String(scheme_match.clone()), &PhpMixed::List(vec![ - Box::new(PhpMixed::String("https".to_string())), - Box::new(PhpMixed::String("http".to_string())), + PhpMixed::String("https".to_string()), + PhpMixed::String("http".to_string()), ]), true, ) { @@ -169,9 +169,9 @@ impl GitLabDriver { if !in_array( PhpMixed::String(protocol.to_string()), &PhpMixed::List(vec![ - Box::new(PhpMixed::String("git".to_string())), - Box::new(PhpMixed::String("http".to_string())), - Box::new(PhpMixed::String("https".to_string())), + PhpMixed::String("git".to_string()), + PhpMixed::String("http".to_string()), + PhpMixed::String("https".to_string()), ]), true, ) { @@ -274,7 +274,7 @@ impl GitLabDriver { .unwrap_or_default(); JsonFile::parse_json(Some(&res), None)? .as_array() - .map(|m| m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()) + .map(|m| m.clone()) } else { let file_content = self.get_file_content("composer.json", identifier)?; let composer = VcsDriverBase::finish_base_composer_information( @@ -290,13 +290,7 @@ impl GitLabDriver { c.write( identifier, &JsonFile::encode_with_options( - &PhpMixed::Array( - composer_map - .clone() - .into_iter() - .map(|(k, v)| (k, Box::new(v))) - .collect(), - ), + &PhpMixed::Array(composer_map.clone().into_iter().collect()), JsonEncodeOptions { pretty_print: false, ..Default::default() @@ -330,7 +324,7 @@ impl GitLabDriver { &PhpMixed::Array( self.get_tags()? .into_iter() - .map(|(k, v)| (k, Box::new(PhpMixed::String(v)))) + .map(|(k, v)| (k, PhpMixed::String(v))) .collect(), ), true, @@ -343,7 +337,7 @@ impl GitLabDriver { self.get_branches() .unwrap_or_default() .into_iter() - .map(|(k, v)| (k, Box::new(PhpMixed::String(v)))) + .map(|(k, v)| (k, PhpMixed::String(v))) .collect(), ), true, @@ -363,11 +357,11 @@ impl GitLabDriver { }) { support.insert( "source".to_string(), - Box::new(PhpMixed::String(format!( + PhpMixed::String(format!( "{}/-/tree/{}", PhpMixed::String(web_url), PhpMixed::String(label_str), - ))), + )), ); } } @@ -394,10 +388,7 @@ impl GitLabDriver { }) { support.insert( "issues".to_string(), - Box::new(PhpMixed::String(format!( - "{}/-/issues", - PhpMixed::String(web_url), - ))), + PhpMixed::String(format!("{}/-/issues", PhpMixed::String(web_url),)), ); } } @@ -610,8 +601,8 @@ impl GitLabDriver { && !in_array( PhpMixed::String(character.clone()), &PhpMixed::List(vec![ - Box::new(PhpMixed::String("-".to_string())), - Box::new(PhpMixed::String("_".to_string())), + PhpMixed::String("-".to_string()), + PhpMixed::String("_".to_string()), ]), true, ) { @@ -644,7 +635,7 @@ impl GitLabDriver { if let PhpMixed::List(ref list) = data { for datum in list { - if let PhpMixed::Array(ref datum_map) = **datum { + if let PhpMixed::Array(ref datum_map) = *datum { let name = datum_map .get("name") .and_then(|v| v.as_string()) @@ -665,10 +656,7 @@ impl GitLabDriver { .get("commit") .and_then(|v| v.as_array()) .cloned() - .unwrap_or_default() - .into_iter() - .map(|(k, v)| (k, *v)) - .collect(); + .unwrap_or_default(); self.commits.insert(commit_id, commit_data); } } @@ -704,7 +692,7 @@ impl GitLabDriver { .map_err(|e| anyhow::anyhow!("{}", e.message))? .decode_json()?; self.project = match project { - PhpMixed::Array(m) => Some(m.into_iter().map(|(k, v)| (k, *v)).collect()), + PhpMixed::Array(m) => Some(m), _ => None, }; let project = self.project.clone().unwrap_or_default(); @@ -871,12 +859,7 @@ impl GitLabDriver { )); } - if !empty( - &json_map - .get("id") - .cloned() - .unwrap_or(Box::new(PhpMixed::Null)), - ) { + if !empty(&json_map.get("id").cloned().unwrap_or(PhpMixed::Null)) { self.is_private = false; } diff --git a/crates/shirabe/src/repository/vcs/svn_driver.rs b/crates/shirabe/src/repository/vcs/svn_driver.rs index 6346a84..96a1b38 100644 --- a/crates/shirabe/src/repository/vcs/svn_driver.rs +++ b/crates/shirabe/src/repository/vcs/svn_driver.rs @@ -187,9 +187,8 @@ impl SvnDriver { } let parsed = JsonFile::parse_json(Some(res.as_str()), None)?; - let composer: Option<IndexMap<String, PhpMixed>> = parsed - .as_array() - .map(|m| m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()); + let composer: Option<IndexMap<String, PhpMixed>> = + parsed.as_array().map(|m| m.clone()); self.inner .info_cache .insert(identifier.to_string(), composer.clone()); diff --git a/crates/shirabe/src/repository/vcs/vcs_driver.rs b/crates/shirabe/src/repository/vcs/vcs_driver.rs index ac7496d..249e53f 100644 --- a/crates/shirabe/src/repository/vcs/vcs_driver.rs +++ b/crates/shirabe/src/repository/vcs/vcs_driver.rs @@ -75,7 +75,7 @@ impl VcsDriverBase { .cloned() .unwrap_or(PhpMixed::Array(IndexMap::new())); let options: IndexMap<String, PhpMixed> = match options_mixed { - PhpMixed::Array(a) => a.into_iter().map(|(k, v)| (k, *v)).collect(), + PhpMixed::Array(a) => a, _ => IndexMap::new(), }; self.http_downloader @@ -114,10 +114,7 @@ impl VcsDriverBase { _ => return Ok(None), }; - // PHP arrays own their nested values; the Rust representation wraps them - // in Box<PhpMixed>. Unbox the outer level so callers can mutate keys. - let mut composer: IndexMap<String, PhpMixed> = - array.into_iter().map(|(k, v)| (k, *v)).collect(); + let mut composer: IndexMap<String, PhpMixed> = array; if (!composer.contains_key("time") || composer @@ -153,9 +150,7 @@ impl VcsDriverBase { && let Some(res) = self.cache.as_mut().and_then(|c| c.read(identifier)) { let parsed = JsonFile::parse_json(Some(&res), None)?; - let composer: Option<IndexMap<String, PhpMixed>> = parsed - .as_array() - .map(|m| m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()); + let composer: Option<IndexMap<String, PhpMixed>> = parsed.as_array().map(|m| m.clone()); self.info_cache .insert(identifier.to_string(), composer.clone()); return Ok(Some(composer)); @@ -219,7 +214,7 @@ pub trait VcsDriver: VcsDriverInterface { { let parsed = JsonFile::parse_json(Some(&res), None)?; let parsed_map: Option<IndexMap<String, PhpMixed>> = match parsed { - PhpMixed::Array(a) => Some(a.into_iter().map(|(k, v)| (k, *v)).collect()), + PhpMixed::Array(a) => Some(a), _ => None, }; self.info_cache_mut() @@ -235,7 +230,7 @@ pub trait VcsDriver: VcsDriverInterface { let composer_mixed = PhpMixed::Array( composer_map .iter() - .map(|(k, v)| (k.clone(), Box::new(v.clone()))) + .map(|(k, v)| (k.clone(), v.clone())) .collect(), ); let encoded = JsonFile::encode_with_options( @@ -273,7 +268,7 @@ pub trait VcsDriver: VcsDriverInterface { )?; let mut composer: IndexMap<String, PhpMixed> = match composer { - PhpMixed::Array(a) if !a.is_empty() => a.into_iter().map(|(k, v)| (k, *v)).collect(), + PhpMixed::Array(a) if !a.is_empty() => a, _ => return Ok(None), }; @@ -313,7 +308,7 @@ pub trait VcsDriver: VcsDriverInterface { .cloned() .unwrap_or(PhpMixed::Array(IndexMap::new())); let options: IndexMap<String, PhpMixed> = match options_mixed { - PhpMixed::Array(a) => a.into_iter().map(|(k, v)| (k, *v)).collect(), + PhpMixed::Array(a) => a, _ => IndexMap::new(), }; self.http_downloader() diff --git a/crates/shirabe/src/repository/vcs_repository.rs b/crates/shirabe/src/repository/vcs_repository.rs index b7c0dbb..526aa01 100644 --- a/crates/shirabe/src/repository/vcs_repository.rs +++ b/crates/shirabe/src/repository/vcs_repository.rs @@ -796,7 +796,7 @@ impl VcsRepository { match dist { Some(m) => PhpMixed::Array( m.into_iter() - .map(|(k, v)| (k, Box::new(PhpMixed::String(v)))) + .map(|(k, v)| (k, PhpMixed::String(v))) .collect(), ), None => PhpMixed::Null, @@ -810,7 +810,7 @@ impl VcsRepository { PhpMixed::Array( source .into_iter() - .map(|(k, v)| (k, Box::new(PhpMixed::String(v)))) + .map(|(k, v)| (k, PhpMixed::String(v))) .collect(), ), ); @@ -960,9 +960,9 @@ impl VcsRepository { in_array( PhpMixed::Int(e.get_code()), &PhpMixed::List(vec![ - Box::new(PhpMixed::Int(401)), - Box::new(PhpMixed::Int(403)), - Box::new(PhpMixed::Int(429)), + PhpMixed::Int(401), + PhpMixed::Int(403), + PhpMixed::Int(429), ]), true, ) || e.get_code() >= 500 |
