aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/package/loader
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-20 01:16:50 +0900
committernsfisis <nsfisis@gmail.com>2026-06-20 02:22:41 +0900
commitefec43b3b8827820cf35fe1b73d8e33f5fe84eb4 (patch)
treea62bbba72324de48be5f8e689559f8d9e288fc61 /crates/shirabe/src/package/loader
parentcac18ef73a39b4ac41fa4d6ccb753804d4c42cb7 (diff)
downloadphp-shirabe-efec43b3b8827820cf35fe1b73d8e33f5fe84eb4.tar.gz
php-shirabe-efec43b3b8827820cf35fe1b73d8e33f5fe84eb4.tar.zst
php-shirabe-efec43b3b8827820cf35fe1b73d8e33f5fe84eb4.zip
refactor: auto-fix clippy warnings
Diffstat (limited to 'crates/shirabe/src/package/loader')
-rw-r--r--crates/shirabe/src/package/loader/array_loader.rs390
-rw-r--r--crates/shirabe/src/package/loader/root_package_loader.rs38
-rw-r--r--crates/shirabe/src/package/loader/validating_array_loader.rs652
3 files changed, 525 insertions, 555 deletions
diff --git a/crates/shirabe/src/package/loader/array_loader.rs b/crates/shirabe/src/package/loader/array_loader.rs
index 222b5df..889624d 100644
--- a/crates/shirabe/src/package/loader/array_loader.rs
+++ b/crates/shirabe/src/package/loader/array_loader.rs
@@ -35,10 +35,7 @@ pub struct ArrayLoader {
impl ArrayLoader {
pub fn new(parser: Option<VersionParser>, load_options: bool) -> Self {
- let parser = match parser {
- Some(p) => p,
- None => VersionParser::new(),
- };
+ let parser = parser.unwrap_or_default();
Self {
version_parser: parser,
load_options,
@@ -340,11 +337,11 @@ impl ArrayLoader {
.set_target_dir(target_dir.as_string().map(|s| s.to_string()));
}
- if let Some(extra) = config.get("extra") {
- if matches!(extra, PhpMixed::Array(_)) {
- let extra_map = php_to_map(extra);
- package.package_mut().set_extra(extra_map);
- }
+ if let Some(extra) = config.get("extra")
+ && matches!(extra, PhpMixed::Array(_))
+ {
+ let extra_map = php_to_map(extra);
+ package.package_mut().set_extra(extra_map);
}
if let Some(bin) = config.get("bin").cloned() {
@@ -355,13 +352,13 @@ impl ArrayLoader {
if let PhpMixed::List(ref mut list) = bin_list {
for item in list.iter_mut() {
if let Some(s) = item.as_string() {
- *item = Box::new(PhpMixed::String(ltrim(s, Some("/"))));
+ **item = PhpMixed::String(ltrim(s, Some("/")));
}
}
} else if let PhpMixed::Array(ref mut map) = bin_list {
for (_k, v) in map.iter_mut() {
if let Some(s) = v.as_string() {
- *v = Box::new(PhpMixed::String(ltrim(s, Some("/"))));
+ **v = PhpMixed::String(ltrim(s, Some("/")));
}
}
}
@@ -376,10 +373,10 @@ impl ArrayLoader {
.set_installation_source(installation_source.as_string().map(|s| s.to_string()));
}
- if let Some(default_branch) = config.get("default-branch") {
- if default_branch.as_bool() == Some(true) {
- package.package_mut().set_is_default_branch(true);
- }
+ if let Some(default_branch) = config.get("default-branch")
+ && default_branch.as_bool() == Some(true)
+ {
+ package.package_mut().set_is_default_branch(true);
}
if let Some(source) = config.get("source").cloned() {
@@ -473,25 +470,23 @@ impl ArrayLoader {
}
}
- if let Some(suggest) = config.get("suggest").cloned() {
- if let PhpMixed::Array(mut suggest_map) = suggest {
- for (target, reason) in suggest_map.iter_mut() {
- if let Some(r) = reason.as_string() {
- if trim(r, None) == "self.version" {
- *reason = Box::new(PhpMixed::String(
- package.get_pretty_version().to_string(),
- ));
- let _ = target;
- }
- }
+ if let Some(suggest) = config.get("suggest").cloned()
+ && let PhpMixed::Array(mut suggest_map) = suggest
+ {
+ for (target, reason) in suggest_map.iter_mut() {
+ if let Some(r) = reason.as_string()
+ && trim(r, None) == "self.version"
+ {
+ **reason = PhpMixed::String(package.get_pretty_version().to_string());
+ let _ = target;
}
- let suggests: IndexMap<String, String> = suggest_map
- .iter()
- .map(|(k, v)| (k.clone(), strval(v)))
- .collect();
- config.insert("suggest".to_string(), PhpMixed::Array(suggest_map));
- package.package_mut().set_suggests(suggests);
}
+ let suggests: IndexMap<String, String> = suggest_map
+ .iter()
+ .map(|(k, v)| (k.clone(), strval(v)))
+ .collect();
+ config.insert("suggest".to_string(), PhpMixed::Array(suggest_map));
+ package.package_mut().set_suggests(suggests);
}
if let Some(autoload) = config.get("autoload") {
@@ -514,201 +509,198 @@ impl ArrayLoader {
package.package_mut().set_php_ext(Some(php_ext_map));
}
- if let Some(time_value) = config.get("time") {
- if !shirabe_php_shim::empty(time_value) {
- let time_str = time_value.as_string().unwrap_or("");
- let time = if Preg::is_match(r"/^\d++$/D", time_str) {
- format!("@{}", time_str)
- } else {
- time_str.to_string()
- };
+ if let Some(time_value) = config.get("time")
+ && !shirabe_php_shim::empty(time_value)
+ {
+ let time_str = time_value.as_string().unwrap_or("");
+ let time = if Preg::is_match(r"/^\d++$/D", time_str) {
+ format!("@{}", time_str)
+ } else {
+ time_str.to_string()
+ };
- if let Ok(date) = shirabe_php_shim::date_create::<Utc>(&time) {
- package.package_mut().set_release_date(Some(date));
- }
+ if let Ok(date) = shirabe_php_shim::date_create::<Utc>(&time) {
+ package.package_mut().set_release_date(Some(date));
}
}
- if let Some(notification_url) = config.get("notification-url") {
- if !shirabe_php_shim::empty(notification_url) {
- package
- .package_mut()
- .set_notification_url(strval(notification_url));
- }
+ if let Some(notification_url) = config.get("notification-url")
+ && !shirabe_php_shim::empty(notification_url)
+ {
+ package
+ .package_mut()
+ .set_notification_url(strval(notification_url));
}
- if let Some(archive) = config.get("archive").cloned() {
- if let PhpMixed::Array(archive_map) = archive {
- if let Some(name) = archive_map.get("name") {
- if !shirabe_php_shim::empty(name) {
- package.complete_mut().set_archive_name(strval(name));
- }
- }
- if let Some(exclude) = archive_map.get("exclude") {
- if !shirabe_php_shim::empty(exclude) {
- package
- .complete_mut()
- .set_archive_excludes(php_to_string_vec(exclude));
- }
- }
+ if let Some(archive) = config.get("archive").cloned()
+ && let PhpMixed::Array(archive_map) = archive
+ {
+ if let Some(name) = archive_map.get("name")
+ && !shirabe_php_shim::empty(name)
+ {
+ package.complete_mut().set_archive_name(strval(name));
+ }
+ if let Some(exclude) = archive_map.get("exclude")
+ && !shirabe_php_shim::empty(exclude)
+ {
+ package
+ .complete_mut()
+ .set_archive_excludes(php_to_string_vec(exclude));
}
}
- if let Some(scripts) = config.get("scripts").cloned() {
- if let PhpMixed::Array(mut scripts_map) = scripts {
- for (event, listeners) in scripts_map.iter_mut() {
- let listeners_array = match listeners.as_ref() {
- PhpMixed::Array(_) | PhpMixed::List(_) => listeners.clone(),
- other => Box::new(PhpMixed::List(vec![Box::new(other.clone())])),
- };
- *listeners = listeners_array;
- let _ = event;
- }
- for reserved in ["composer", "php", "putenv"].iter() {
- if scripts_map.contains_key(*reserved) {
- trigger_error(
- &format!(
- "The `{}` script name is reserved for internal use, please avoid defining it",
- reserved
- ),
- E_USER_DEPRECATED,
- );
- }
+ if let Some(scripts) = config.get("scripts").cloned()
+ && let PhpMixed::Array(mut scripts_map) = scripts
+ {
+ for (event, listeners) in scripts_map.iter_mut() {
+ let listeners_array = match listeners.as_ref() {
+ PhpMixed::Array(_) | PhpMixed::List(_) => listeners.clone(),
+ other => Box::new(PhpMixed::List(vec![Box::new(other.clone())])),
+ };
+ *listeners = listeners_array;
+ let _ = event;
+ }
+ for reserved in ["composer", "php", "putenv"].iter() {
+ if scripts_map.contains_key(*reserved) {
+ trigger_error(
+ &format!(
+ "The `{}` script name is reserved for internal use, please avoid defining it",
+ reserved
+ ),
+ E_USER_DEPRECATED,
+ );
}
- let scripts: IndexMap<String, Vec<String>> = scripts_map
- .iter()
- .map(|(k, v)| (k.clone(), php_to_string_vec(v)))
- .collect();
- config.insert("scripts".to_string(), PhpMixed::Array(scripts_map));
- package.complete_mut().set_scripts(scripts);
}
+ let scripts: IndexMap<String, Vec<String>> = scripts_map
+ .iter()
+ .map(|(k, v)| (k.clone(), php_to_string_vec(v)))
+ .collect();
+ config.insert("scripts".to_string(), PhpMixed::Array(scripts_map));
+ package.complete_mut().set_scripts(scripts);
}
- if let Some(description) = config.get("description") {
- if !shirabe_php_shim::empty(description) && is_string(description) {
- package
- .complete_mut()
- .set_description(description.as_string().unwrap_or("").to_string());
- }
+ if let Some(description) = config.get("description")
+ && !shirabe_php_shim::empty(description)
+ && is_string(description)
+ {
+ package
+ .complete_mut()
+ .set_description(description.as_string().unwrap_or("").to_string());
}
- if let Some(homepage) = config.get("homepage") {
- if !shirabe_php_shim::empty(homepage) && is_string(homepage) {
- package
- .complete_mut()
- .set_homepage(homepage.as_string().unwrap_or("").to_string());
- }
+ if let Some(homepage) = config.get("homepage")
+ && !shirabe_php_shim::empty(homepage)
+ && is_string(homepage)
+ {
+ package
+ .complete_mut()
+ .set_homepage(homepage.as_string().unwrap_or("").to_string());
}
- if let Some(keywords) = config.get("keywords") {
- if !shirabe_php_shim::empty(keywords) {
- if matches!(keywords, PhpMixed::Array(_) | PhpMixed::List(_)) {
- let keywords_vec: Vec<String> = match keywords {
- PhpMixed::List(list) => list.iter().map(|v| strval(v)).collect(),
- PhpMixed::Array(map) => map.values().map(|v| strval(v)).collect(),
- _ => vec![],
- };
- package.complete_mut().set_keywords(keywords_vec);
- }
- }
+ if let Some(keywords) = config.get("keywords")
+ && !shirabe_php_shim::empty(keywords)
+ && matches!(keywords, PhpMixed::Array(_) | PhpMixed::List(_))
+ {
+ let keywords_vec: Vec<String> = match keywords {
+ PhpMixed::List(list) => list.iter().map(|v| strval(v)).collect(),
+ PhpMixed::Array(map) => map.values().map(|v| strval(v)).collect(),
+ _ => vec![],
+ };
+ package.complete_mut().set_keywords(keywords_vec);
}
- if let Some(license) = config.get("license") {
- if !shirabe_php_shim::empty(license) {
- let license_vec: Vec<String> = match license {
- PhpMixed::Array(map) => map
- .values()
- .map(|v| v.as_string().unwrap_or("").to_string())
- .collect(),
- PhpMixed::List(list) => list
- .iter()
- .map(|v| v.as_string().unwrap_or("").to_string())
- .collect(),
- other => vec![other.as_string().unwrap_or("").to_string()],
- };
- package.complete_mut().set_license(license_vec);
- }
+ if let Some(license) = config.get("license")
+ && !shirabe_php_shim::empty(license)
+ {
+ let license_vec: Vec<String> = match license {
+ PhpMixed::Array(map) => map
+ .values()
+ .map(|v| v.as_string().unwrap_or("").to_string())
+ .collect(),
+ PhpMixed::List(list) => list
+ .iter()
+ .map(|v| v.as_string().unwrap_or("").to_string())
+ .collect(),
+ other => vec![other.as_string().unwrap_or("").to_string()],
+ };
+ package.complete_mut().set_license(license_vec);
}
- if let Some(authors) = config.get("authors") {
- if !shirabe_php_shim::empty(authors) {
- if let PhpMixed::List(list) = authors {
- let authors_vec: Vec<IndexMap<String, String>> = list
- .iter()
- .filter_map(|v| match v.as_ref() {
- PhpMixed::Array(m) => Some(
- m.iter()
- .map(|(k, v)| {
- (k.clone(), v.as_string().unwrap_or("").to_string())
- })
- .collect(),
- ),
- _ => None,
- })
- .collect();
- package.complete_mut().set_authors(authors_vec);
- }
- }
+ if let Some(authors) = config.get("authors")
+ && !shirabe_php_shim::empty(authors)
+ && let PhpMixed::List(list) = authors
+ {
+ let authors_vec: Vec<IndexMap<String, String>> = list
+ .iter()
+ .filter_map(|v| match v.as_ref() {
+ PhpMixed::Array(m) => Some(
+ m.iter()
+ .map(|(k, v)| (k.clone(), v.as_string().unwrap_or("").to_string()))
+ .collect(),
+ ),
+ _ => None,
+ })
+ .collect();
+ package.complete_mut().set_authors(authors_vec);
}
- if let Some(support) = config.get("support") {
- if let PhpMixed::Array(map) = support {
- let support_map: IndexMap<String, String> = map
- .iter()
- .map(|(k, v)| (k.clone(), v.as_string().unwrap_or("").to_string()))
- .collect();
- package.complete_mut().set_support(support_map);
- }
+ if let Some(support) = config.get("support")
+ && let PhpMixed::Array(map) = support
+ {
+ let support_map: IndexMap<String, String> = map
+ .iter()
+ .map(|(k, v)| (k.clone(), v.as_string().unwrap_or("").to_string()))
+ .collect();
+ package.complete_mut().set_support(support_map);
}
- if let Some(funding) = config.get("funding") {
- if !shirabe_php_shim::empty(funding) {
- if let PhpMixed::List(list) = funding {
- let funding_vec: Vec<IndexMap<String, PhpMixed>> = list
- .iter()
- .filter_map(|v| match v.as_ref() {
- PhpMixed::Array(m) => {
- Some(m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect())
- }
- _ => None,
- })
- .collect();
- package.complete_mut().set_funding(funding_vec);
- }
- }
+ if let Some(funding) = config.get("funding")
+ && !shirabe_php_shim::empty(funding)
+ && let PhpMixed::List(list) = funding
+ {
+ let funding_vec: Vec<IndexMap<String, PhpMixed>> = list
+ .iter()
+ .filter_map(|v| match v.as_ref() {
+ PhpMixed::Array(m) => {
+ Some(m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect())
+ }
+ _ => None,
+ })
+ .collect();
+ package.complete_mut().set_funding(funding_vec);
}
if let Some(abandoned) = config.get("abandoned") {
package.complete_mut().set_abandoned(abandoned.clone());
}
- if self.load_options {
- if let Some(transport_options) = config.get("transport-options") {
- let options = php_to_map(transport_options);
- package.package_mut().set_transport_options(options);
- }
+ if self.load_options
+ && let Some(transport_options) = config.get("transport-options")
+ {
+ let options = php_to_map(transport_options);
+ package.package_mut().set_transport_options(options);
}
let alias_normalized = self.get_branch_alias(config)?;
- if let Some(alias_normalized) = alias_normalized {
- if !alias_normalized.is_empty() {
- let pretty_alias = Preg::replace(r"{(\.9{7})+}", ".x", &alias_normalized);
+ if let Some(alias_normalized) = alias_normalized
+ && !alias_normalized.is_empty()
+ {
+ let pretty_alias = Preg::replace(r"{(\.9{7})+}", ".x", &alias_normalized);
- return Ok(match package {
- CompleteOrRootPackage::Root(root) => RootAliasPackageHandle::new(
- RootPackageHandle::from_root_package(root),
- alias_normalized,
- pretty_alias,
- )
- .into(),
- CompleteOrRootPackage::Complete(complete) => CompleteAliasPackageHandle::new(
- CompletePackageHandle::from_complete_package(complete),
- alias_normalized,
- pretty_alias,
- )
- .into(),
- });
- }
+ return Ok(match package {
+ CompleteOrRootPackage::Root(root) => RootAliasPackageHandle::new(
+ RootPackageHandle::from_root_package(root),
+ alias_normalized,
+ pretty_alias,
+ )
+ .into(),
+ CompleteOrRootPackage::Complete(complete) => CompleteAliasPackageHandle::new(
+ CompletePackageHandle::from_complete_package(complete),
+ alias_normalized,
+ pretty_alias,
+ )
+ .into(),
+ });
}
Ok(package.into_handle())
@@ -773,11 +765,11 @@ impl ArrayLoader {
let entry = (target.clone(), link);
link_cache
.entry(name.clone())
- .or_insert_with(IndexMap::new)
+ .or_default()
.entry(r#type.to_string())
- .or_insert_with(IndexMap::new)
+ .or_default()
.entry(target.clone())
- .or_insert_with(IndexMap::new)
+ .or_default()
.insert(constraint_str.clone(), entry.clone());
entry
};
@@ -940,10 +932,10 @@ impl ArrayLoader {
let target_prefix = self
.version_parser
.parse_numeric_alias_prefix(&target_branch);
- if let (Some(sp), Some(tp)) = (source_prefix.as_ref(), target_prefix.as_ref()) {
- if stripos(tp, sp) != Some(0) {
- continue;
- }
+ if let (Some(sp), Some(tp)) = (source_prefix.as_ref(), target_prefix.as_ref())
+ && stripos(tp, sp) != Some(0)
+ {
+ continue;
}
return Ok(Some(validated_target_branch));
diff --git a/crates/shirabe/src/package/loader/root_package_loader.rs b/crates/shirabe/src/package/loader/root_package_loader.rs
index 92f2be0..2d3bd0a 100644
--- a/crates/shirabe/src/package/loader/root_package_loader.rs
+++ b/crates/shirabe/src/package/loader/root_package_loader.rs
@@ -221,17 +221,17 @@ impl RootPackageLoader {
}
for link_type in SUPPORTED_LINK_TYPES.keys() {
- if let Some(section) = config.get(*link_type) {
- if let Some(section_map) = section.as_array() {
- for (link_name, _constraint) in section_map {
- if let Some(err) =
- ValidatingArrayLoader::has_package_naming_error(link_name, true)
- {
- return Err(anyhow::anyhow!(RuntimeException {
- message: format!("{}.{}", link_type, err),
- code: 0,
- }));
- }
+ if let Some(section) = config.get(*link_type)
+ && let Some(section_map) = section.as_array()
+ {
+ for (link_name, _constraint) in section_map {
+ if let Some(err) =
+ ValidatingArrayLoader::has_package_naming_error(link_name, true)
+ {
+ return Err(anyhow::anyhow!(RuntimeException {
+ message: format!("{}.{}", link_type, err),
+ code: 0,
+ }));
}
}
}
@@ -392,14 +392,14 @@ impl RootPackageLoader {
for (req_name, req_version) in requires {
let req_version = Preg::replace(r"^([^,\s@]+) as .+$", "$1", req_version);
let mut m: IndexMap<CaptureKey, String> = IndexMap::new();
- if Preg::is_match3(r"^[^,\s@]+?#([a-f0-9]+)$", &req_version, Some(&mut m)) {
- if VersionParser::parse_stability(&req_version) == "dev" {
- let name = strtolower(req_name);
- references.insert(
- name,
- m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(),
- );
- }
+ if Preg::is_match3(r"^[^,\s@]+?#([a-f0-9]+)$", &req_version, Some(&mut m))
+ && VersionParser::parse_stability(&req_version) == "dev"
+ {
+ let name = strtolower(req_name);
+ references.insert(
+ name,
+ m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(),
+ );
}
}
references
diff --git a/crates/shirabe/src/package/loader/validating_array_loader.rs b/crates/shirabe/src/package/loader/validating_array_loader.rs
index dd2642e..490c0a9 100644
--- a/crates/shirabe/src/package/loader/validating_array_loader.rs
+++ b/crates/shirabe/src/package/loader/validating_array_loader.rs
@@ -43,9 +43,9 @@ impl ValidatingArrayLoader {
parser: Option<VersionParser>,
flags: i64,
) -> Self {
- let version_parser = parser.unwrap_or_else(|| VersionParser::new());
+ let version_parser = parser.unwrap_or_default();
- if strict_name != true {
+ if !strict_name {
trigger_error(
"$strictName must be set to true in ValidatingArrayLoader's constructor as of 2.2, and it will be removed in 3.0",
E_USER_DEPRECATED,
@@ -72,21 +72,21 @@ impl ValidatingArrayLoader {
self.config = config.clone();
self.validate_string("name", true);
- if let Some(name_val) = config.get("name").and_then(|v| v.as_string()) {
- if let Some(err) = Self::has_package_naming_error(name_val, false) {
- self.errors.push(format!("name : {}", err));
- }
+ if let Some(name_val) = config.get("name").and_then(|v| v.as_string())
+ && let Some(err) = Self::has_package_naming_error(name_val, false)
+ {
+ self.errors.push(format!("name : {}", err));
}
if self.config.contains_key("version") {
let version_val = self.config["version"].clone();
- if !is_scalar(&*version_val) {
+ if !is_scalar(&version_val) {
self.validate_string("version", false);
} else {
- if !is_string(&*version_val) {
+ if !is_string(&version_val) {
self.config.insert(
"version".to_string(),
- Box::new(PhpMixed::String(php_to_string(&*version_val))),
+ Box::new(PhpMixed::String(php_to_string(&version_val))),
);
}
let version_str = self
@@ -111,36 +111,35 @@ impl ValidatingArrayLoader {
.get("config")
.and_then(|v| v.as_array())
.cloned()
+ && let Some(platform_val) = config_section.get("platform")
{
- if let Some(platform_val) = config_section.get("platform") {
- let platform_array: IndexMap<String, Box<PhpMixed>> = match platform_val.as_ref() {
- PhpMixed::Array(m) => m.clone(),
- other => {
- let mut m = IndexMap::new();
- m.insert("0".to_string(), Box::new(other.clone()));
- m
- }
- };
- for (key, platform) in &platform_array {
- if let PhpMixed::Bool(false) = platform.as_ref() {
- continue;
- }
- if !is_string(platform) {
- self.errors.push(format!(
- "config.platform.{} : invalid value ({} {}): expected string or false",
- key,
- get_debug_type(platform),
- var_export(platform, true)
- ));
- continue;
- }
- let platform_str = platform.as_string().unwrap_or("").to_string();
- if let Err(e) = self.version_parser.normalize(&platform_str, None) {
- self.errors.push(format!(
- "config.platform.{} : invalid value ({}): {}",
- key, platform_str, e
- ));
- }
+ let platform_array: IndexMap<String, Box<PhpMixed>> = match platform_val.as_ref() {
+ PhpMixed::Array(m) => m.clone(),
+ other => {
+ let mut m = IndexMap::new();
+ m.insert("0".to_string(), Box::new(other.clone()));
+ m
+ }
+ };
+ for (key, platform) in &platform_array {
+ if let PhpMixed::Bool(false) = platform.as_ref() {
+ continue;
+ }
+ if !is_string(platform) {
+ self.errors.push(format!(
+ "config.platform.{} : invalid value ({} {}): expected string or false",
+ key,
+ get_debug_type(platform),
+ var_export(platform, true)
+ ));
+ continue;
+ }
+ let platform_str = platform.as_string().unwrap_or("").to_string();
+ if let Err(e) = self.version_parser.normalize(&platform_str, None) {
+ self.errors.push(format!(
+ "config.platform.{} : invalid value ({}): {}",
+ key, platform_str, e
+ ));
}
}
}
@@ -150,7 +149,7 @@ impl ValidatingArrayLoader {
self.validate_array("extra", false);
if self.config.contains_key("bin") {
- if is_string(&*self.config["bin"]) {
+ if is_string(&self.config["bin"]) {
self.validate_string("bin", false);
} else {
self.validate_flat_array("bin", None, false);
@@ -181,7 +180,7 @@ impl ValidatingArrayLoader {
if self.config.contains_key("license") {
let license_val = self.config["license"].clone();
// validate main data types
- if is_array(&*license_val) || is_string(&*license_val) {
+ if is_array(&license_val) || is_string(&license_val) {
let mut licenses: IndexMap<String, Box<PhpMixed>> = match license_val.as_ref() {
PhpMixed::Array(m) => m.clone(),
other => {
@@ -194,7 +193,7 @@ impl ValidatingArrayLoader {
let license_keys: Vec<String> = licenses.keys().cloned().collect();
for index in &license_keys {
let license = licenses[index].clone();
- if !is_string(&*license) {
+ if !is_string(&license) {
self.warnings.push(format!(
"License {} should be a string.",
PhpMixed::String(json_encode(&*license).unwrap_or_default()),
@@ -264,11 +263,11 @@ impl ValidatingArrayLoader {
.unwrap_or_default();
for key in &author_keys {
let author = self.config["authors"].as_array().unwrap()[key].clone();
- if !is_array(&*author) {
+ if !is_array(&author) {
self.errors.push(format!(
"authors.{} : should be an array, {} given",
key,
- get_debug_type(&*author)
+ get_debug_type(&author)
));
if let Some(PhpMixed::Array(m)) =
self.config.get_mut("authors").map(|v| v.as_mut())
@@ -279,21 +278,19 @@ impl ValidatingArrayLoader {
}
for author_data in ["homepage", "email", "name", "role"] {
let val_opt = author.as_array().and_then(|m| m.get(author_data)).cloned();
- if let Some(val) = val_opt {
- if !is_string(&*val) {
- self.errors.push(format!(
- "authors.{}.{} : invalid value, must be a string",
- key, author_data
- ));
- if let Some(PhpMixed::Array(authors)) =
- self.config.get_mut("authors").map(|v| v.as_mut())
- {
- if let Some(author_entry) = authors.get_mut(key) {
- if let PhpMixed::Array(am) = author_entry.as_mut() {
- am.shift_remove(author_data);
- }
- }
- }
+ if let Some(val) = val_opt
+ && !is_string(&val)
+ {
+ self.errors.push(format!(
+ "authors.{}.{} : invalid value, must be a string",
+ key, author_data
+ ));
+ if let Some(PhpMixed::Array(authors)) =
+ self.config.get_mut("authors").map(|v| v.as_mut())
+ && let Some(author_entry) = authors.get_mut(key)
+ && let PhpMixed::Array(am) = author_entry.as_mut()
+ {
+ am.shift_remove(author_data);
}
}
}
@@ -302,21 +299,19 @@ impl ValidatingArrayLoader {
.and_then(|m| m.get("homepage"))
.and_then(|v| v.as_string())
.map(|s| s.to_string());
- if let Some(homepage_str) = homepage {
- if !self.filter_url(&homepage_str, &["http", "https"]) {
- self.warnings.push(format!(
- "authors.{}.homepage : invalid value ({}), must be an http/https URL",
- key, homepage_str
- ));
- if let Some(PhpMixed::Array(authors)) =
- self.config.get_mut("authors").map(|v| v.as_mut())
- {
- if let Some(author_entry) = authors.get_mut(key) {
- if let PhpMixed::Array(am) = author_entry.as_mut() {
- am.shift_remove("homepage");
- }
- }
- }
+ if let Some(homepage_str) = homepage
+ && !self.filter_url(&homepage_str, &["http", "https"])
+ {
+ self.warnings.push(format!(
+ "authors.{}.homepage : invalid value ({}), must be an http/https URL",
+ key, homepage_str
+ ));
+ if let Some(PhpMixed::Array(authors)) =
+ self.config.get_mut("authors").map(|v| v.as_mut())
+ && let Some(author_entry) = authors.get_mut(key)
+ && let PhpMixed::Array(am) = author_entry.as_mut()
+ {
+ am.shift_remove("homepage");
}
}
let email = author
@@ -324,21 +319,19 @@ impl ValidatingArrayLoader {
.and_then(|m| m.get("email"))
.and_then(|v| v.as_string())
.map(|s| s.to_string());
- if let Some(email_str) = email {
- if !filter_var(&email_str, FILTER_VALIDATE_EMAIL) {
- self.warnings.push(format!(
- "authors.{}.email : invalid value ({}), must be a valid email address",
- key, email_str
- ));
- if let Some(PhpMixed::Array(authors)) =
- self.config.get_mut("authors").map(|v| v.as_mut())
- {
- if let Some(author_entry) = authors.get_mut(key) {
- if let PhpMixed::Array(am) = author_entry.as_mut() {
- am.shift_remove("email");
- }
- }
- }
+ if let Some(email_str) = email
+ && !filter_var(&email_str, FILTER_VALIDATE_EMAIL)
+ {
+ self.warnings.push(format!(
+ "authors.{}.email : invalid value ({}), must be a valid email address",
+ key, email_str
+ ));
+ if let Some(PhpMixed::Array(authors)) =
+ self.config.get_mut("authors").map(|v| v.as_mut())
+ && let Some(author_entry) = authors.get_mut(key)
+ && let PhpMixed::Array(am) = author_entry.as_mut()
+ {
+ am.shift_remove("email");
}
}
let current_author_len = self
@@ -349,12 +342,11 @@ impl ValidatingArrayLoader {
.and_then(|v| v.as_array())
.map(|m| m.len())
.unwrap_or(0);
- if current_author_len == 0 {
- if let Some(PhpMixed::Array(authors)) =
+ if current_author_len == 0
+ && let Some(PhpMixed::Array(authors)) =
self.config.get_mut("authors").map(|v| v.as_mut())
- {
- authors.shift_remove(key);
- }
+ {
+ authors.shift_remove(key);
}
}
let authors_len = self
@@ -381,15 +373,15 @@ impl ValidatingArrayLoader {
.and_then(|v| v.as_array())
.and_then(|m| m.get(key))
.cloned();
- if let Some(val) = val_opt {
- if !is_string(&*val) {
- self.errors
- .push(format!("support.{} : invalid value, must be a string", key));
- if let Some(PhpMixed::Array(support)) =
- self.config.get_mut("support").map(|v| v.as_mut())
- {
- support.shift_remove(key);
- }
+ if let Some(val) = val_opt
+ && !is_string(&val)
+ {
+ self.errors
+ .push(format!("support.{} : invalid value, must be a string", key));
+ if let Some(PhpMixed::Array(support)) =
+ self.config.get_mut("support").map(|v| v.as_mut())
+ {
+ support.shift_remove(key);
}
}
}
@@ -401,17 +393,17 @@ impl ValidatingArrayLoader {
.and_then(|m| m.get("email"))
.and_then(|v| v.as_string())
.map(|s| s.to_string());
- if let Some(email_str) = support_email {
- if !filter_var(&email_str, FILTER_VALIDATE_EMAIL) {
- self.warnings.push(format!(
- "support.email : invalid value ({}), must be a valid email address",
- email_str
- ));
- if let Some(PhpMixed::Array(support)) =
- self.config.get_mut("support").map(|v| v.as_mut())
- {
- support.shift_remove("email");
- }
+ if let Some(email_str) = support_email
+ && !filter_var(&email_str, FILTER_VALIDATE_EMAIL)
+ {
+ self.warnings.push(format!(
+ "support.email : invalid value ({}), must be a valid email address",
+ email_str
+ ));
+ if let Some(PhpMixed::Array(support)) =
+ self.config.get_mut("support").map(|v| v.as_mut())
+ {
+ support.shift_remove("email");
}
}
@@ -422,17 +414,17 @@ impl ValidatingArrayLoader {
.and_then(|m| m.get("irc"))
.and_then(|v| v.as_string())
.map(|s| s.to_string());
- if let Some(irc_str) = support_irc {
- if !self.filter_url(&irc_str, &["irc", "ircs"]) {
- self.warnings.push(format!(
+ if let Some(irc_str) = support_irc
+ && !self.filter_url(&irc_str, &["irc", "ircs"])
+ {
+ self.warnings.push(format!(
"support.irc : invalid value ({}), must be a irc://<server>/<channel> or ircs:// URL",
irc_str
));
- if let Some(PhpMixed::Array(support)) =
- self.config.get_mut("support").map(|v| v.as_mut())
- {
- support.shift_remove("irc");
- }
+ if let Some(PhpMixed::Array(support)) =
+ self.config.get_mut("support").map(|v| v.as_mut())
+ {
+ support.shift_remove("irc");
}
}
@@ -446,17 +438,17 @@ impl ValidatingArrayLoader {
.and_then(|m| m.get(key))
.and_then(|v| v.as_string())
.map(|s| s.to_string());
- if let Some(url_str) = url_opt {
- if !self.filter_url(&url_str, &["http", "https"]) {
- self.warnings.push(format!(
- "support.{} : invalid value ({}), must be an http/https URL",
- key, url_str
- ));
- if let Some(PhpMixed::Array(support)) =
- self.config.get_mut("support").map(|v| v.as_mut())
- {
- support.shift_remove(key);
- }
+ if let Some(url_str) = url_opt
+ && !self.filter_url(&url_str, &["http", "https"])
+ {
+ self.warnings.push(format!(
+ "support.{} : invalid value ({}), must be an http/https URL",
+ key, url_str
+ ));
+ if let Some(PhpMixed::Array(support)) =
+ self.config.get_mut("support").map(|v| v.as_mut())
+ {
+ support.shift_remove(key);
}
}
}
@@ -476,11 +468,11 @@ impl ValidatingArrayLoader {
.unwrap_or_default();
for key in &funding_keys {
let funding_option = self.config["funding"].as_array().unwrap()[key].clone();
- if !is_array(&*funding_option) {
+ if !is_array(&funding_option) {
self.errors.push(format!(
"funding.{} : should be an array, {} given",
key,
- get_debug_type(&*funding_option)
+ get_debug_type(&funding_option)
));
if let Some(PhpMixed::Array(funding)) =
self.config.get_mut("funding").map(|v| v.as_mut())
@@ -494,21 +486,19 @@ impl ValidatingArrayLoader {
.as_array()
.and_then(|m| m.get(funding_data))
.cloned();
- if let Some(val) = val_opt {
- if !is_string(&*val) {
- self.errors.push(format!(
- "funding.{}.{} : invalid value, must be a string",
- key, funding_data
- ));
- if let Some(PhpMixed::Array(funding)) =
- self.config.get_mut("funding").map(|v| v.as_mut())
- {
- if let Some(entry) = funding.get_mut(key) {
- if let PhpMixed::Array(em) = entry.as_mut() {
- em.shift_remove(funding_data);
- }
- }
- }
+ if let Some(val) = val_opt
+ && !is_string(&val)
+ {
+ self.errors.push(format!(
+ "funding.{}.{} : invalid value, must be a string",
+ key, funding_data
+ ));
+ if let Some(PhpMixed::Array(funding)) =
+ self.config.get_mut("funding").map(|v| v.as_mut())
+ && let Some(entry) = funding.get_mut(key)
+ && let PhpMixed::Array(em) = entry.as_mut()
+ {
+ em.shift_remove(funding_data);
}
}
}
@@ -517,21 +507,19 @@ impl ValidatingArrayLoader {
.and_then(|m| m.get("url"))
.and_then(|v| v.as_string())
.map(|s| s.to_string());
- if let Some(url_str) = url {
- if !self.filter_url(&url_str, &["http", "https"]) {
- self.warnings.push(format!(
- "funding.{}.url : invalid value ({}), must be an http/https URL",
- key, url_str
- ));
- if let Some(PhpMixed::Array(funding)) =
- self.config.get_mut("funding").map(|v| v.as_mut())
- {
- if let Some(entry) = funding.get_mut(key) {
- if let PhpMixed::Array(em) = entry.as_mut() {
- em.shift_remove("url");
- }
- }
- }
+ if let Some(url_str) = url
+ && !self.filter_url(&url_str, &["http", "https"])
+ {
+ self.warnings.push(format!(
+ "funding.{}.url : invalid value ({}), must be an http/https URL",
+ key, url_str
+ ));
+ if let Some(PhpMixed::Array(funding)) =
+ self.config.get_mut("funding").map(|v| v.as_mut())
+ && let Some(entry) = funding.get_mut(key)
+ && let PhpMixed::Array(em) = entry.as_mut()
+ {
+ em.shift_remove("url");
}
}
let entry_empty = self
@@ -542,12 +530,11 @@ impl ValidatingArrayLoader {
.and_then(|v| v.as_array())
.map(|m| m.is_empty())
.unwrap_or(true);
- if entry_empty {
- if let Some(PhpMixed::Array(funding)) =
+ if entry_empty
+ && let Some(PhpMixed::Array(funding)) =
self.config.get_mut("funding").map(|v| v.as_mut())
- {
- funding.shift_remove(key);
- }
+ {
+ funding.shift_remove(key);
}
}
if Self::is_empty_array(self.config.get("funding")) {
@@ -576,62 +563,63 @@ impl ValidatingArrayLoader {
_ => IndexMap::new(),
};
- if let Some(v) = php_ext.get("extension-name").cloned() {
- if !is_string(&*v) {
- self.errors.push(format!(
- "php-ext.extension-name : should be a string, {} given",
- get_debug_type(&*v)
- ));
- php_ext.shift_remove("extension-name");
- }
+ if let Some(v) = php_ext.get("extension-name").cloned()
+ && !is_string(&v)
+ {
+ self.errors.push(format!(
+ "php-ext.extension-name : should be a string, {} given",
+ get_debug_type(&v)
+ ));
+ php_ext.shift_remove("extension-name");
}
- if let Some(v) = php_ext.get("priority").cloned() {
- if !is_int(&*v) {
- self.errors.push(format!(
- "php-ext.priority : should be an integer, {} given",
- get_debug_type(&*v)
- ));
- php_ext.shift_remove("priority");
- }
+ if let Some(v) = php_ext.get("priority").cloned()
+ && !is_int(&v)
+ {
+ self.errors.push(format!(
+ "php-ext.priority : should be an integer, {} given",
+ get_debug_type(&v)
+ ));
+ php_ext.shift_remove("priority");
}
- if let Some(v) = php_ext.get("support-zts").cloned() {
- if !is_bool(&*v) {
- self.errors.push(format!(
- "php-ext.support-zts : should be a boolean, {} given",
- get_debug_type(&*v)
- ));
- php_ext.shift_remove("support-zts");
- }
+ if let Some(v) = php_ext.get("support-zts").cloned()
+ && !is_bool(&v)
+ {
+ self.errors.push(format!(
+ "php-ext.support-zts : should be a boolean, {} given",
+ get_debug_type(&v)
+ ));
+ php_ext.shift_remove("support-zts");
}
- if let Some(v) = php_ext.get("support-nts").cloned() {
- if !is_bool(&*v) {
- self.errors.push(format!(
- "php-ext.support-nts : should be a boolean, {} given",
- get_debug_type(&*v)
- ));
- php_ext.shift_remove("support-nts");
- }
+ if let Some(v) = php_ext.get("support-nts").cloned()
+ && !is_bool(&v)
+ {
+ self.errors.push(format!(
+ "php-ext.support-nts : should be a boolean, {} given",
+ get_debug_type(&v)
+ ));
+ php_ext.shift_remove("support-nts");
}
- if let Some(v) = php_ext.get("build-path").cloned() {
- if !is_string(&*v) && !matches!(v.as_ref(), PhpMixed::Null) {
- self.errors.push(format!(
- "php-ext.build-path : should be a string or null, {} given",
- get_debug_type(&*v)
- ));
- php_ext.shift_remove("build-path");
- }
+ if let Some(v) = php_ext.get("build-path").cloned()
+ && !is_string(&v)
+ && !matches!(v.as_ref(), PhpMixed::Null)
+ {
+ self.errors.push(format!(
+ "php-ext.build-path : should be a string or null, {} given",
+ get_debug_type(&v)
+ ));
+ php_ext.shift_remove("build-path");
}
if php_ext.contains_key("download-url-method") {
let v = php_ext["download-url-method"].clone();
- if !is_array(&*v) && !is_string(&*v) {
+ if !is_array(&v) && !is_string(&v) {
self.errors.push(format!(
"php-ext.download-url-method : should be an array or a string, {} given",
- get_debug_type(&*v)
+ get_debug_type(&v)
));
php_ext.shift_remove("download-url-method");
} else {
@@ -641,7 +629,7 @@ impl ValidatingArrayLoader {
"pre-packaged-binary",
];
let defined_download_url_methods: IndexMap<String, Box<PhpMixed>> =
- if is_array(&*v) {
+ if is_array(&v) {
v.as_array().unwrap().clone()
} else {
let mut m = IndexMap::new();
@@ -657,11 +645,11 @@ impl ValidatingArrayLoader {
php_ext.shift_remove("download-url-method");
} else {
for (key, download_url_method) in &defined_download_url_methods {
- if !is_string(&**download_url_method) {
+ if !is_string(download_url_method) {
self.errors.push(format!(
"php-ext.download-url-method.{} : should be a string, {} given",
key,
- get_debug_type(&**download_url_method)
+ get_debug_type(download_url_method)
));
php_ext.shift_remove("download-url-method");
} else if !valid_download_url_methods
@@ -695,11 +683,11 @@ impl ValidatingArrayLoader {
for field_name in ["os-families", "os-families-exclude"] {
if let Some(field_val) = php_ext.get(field_name).cloned() {
- if !is_array(&*field_val) {
+ if !is_array(&field_val) {
self.errors.push(format!(
"php-ext.{} : should be an array, {} given",
field_name,
- get_debug_type(&*field_val)
+ get_debug_type(&field_val)
));
php_ext.shift_remove(field_name);
} else if field_val.as_array().unwrap().is_empty() {
@@ -713,12 +701,12 @@ impl ValidatingArrayLoader {
field_val.as_array().unwrap().keys().cloned().collect();
for key in &field_keys {
let os_family = field_val.as_array().unwrap()[key].clone();
- if !is_string(&*os_family) {
+ if !is_string(&os_family) {
self.errors.push(format!(
"php-ext.{}.{} : should be a string, {} given",
field_name,
key,
- get_debug_type(&*os_family)
+ get_debug_type(&os_family)
));
if let Some(PhpMixed::Array(arr)) =
php_ext.get_mut(field_name).map(|v| v.as_mut())
@@ -757,10 +745,10 @@ impl ValidatingArrayLoader {
if php_ext.contains_key("configure-options") {
let configure_options = php_ext["configure-options"].clone();
- if !is_array(&*configure_options) {
+ if !is_array(&configure_options) {
self.errors.push(format!(
"php-ext.configure-options : should be an array, {} given",
- get_debug_type(&*configure_options)
+ get_debug_type(&configure_options)
));
php_ext.shift_remove("configure-options");
} else {
@@ -772,11 +760,11 @@ impl ValidatingArrayLoader {
.collect();
for key in &configure_keys {
let option = configure_options.as_array().unwrap()[key].clone();
- if !is_array(&*option) {
+ if !is_array(&option) {
self.errors.push(format!(
"php-ext.configure-options.{} : should be an array, {} given",
key,
- get_debug_type(&*option)
+ get_debug_type(&option)
));
if let Some(PhpMixed::Array(arr)) =
php_ext.get_mut("configure-options").map(|v| v.as_mut())
@@ -801,11 +789,11 @@ impl ValidatingArrayLoader {
}
let name_val = option_map["name"].clone();
- if !is_string(&*name_val) {
+ if !is_string(&name_val) {
self.errors.push(format!(
"php-ext.configure-options.{}.name : should be a string, {} given",
key,
- get_debug_type(&*name_val)
+ get_debug_type(&name_val)
));
if let Some(PhpMixed::Array(arr)) =
php_ext.get_mut("configure-options").map(|v| v.as_mut())
@@ -815,41 +803,37 @@ impl ValidatingArrayLoader {
continue;
}
- if let Some(needs_value) = option_map.get("needs-value").cloned() {
- if !is_bool(&*needs_value) {
- self.errors.push(format!(
+ if let Some(needs_value) = option_map.get("needs-value").cloned()
+ && !is_bool(&needs_value)
+ {
+ self.errors.push(format!(
"php-ext.configure-options.{}.needs-value : should be a boolean, {} given",
key,
- get_debug_type(&*needs_value)
+ get_debug_type(&needs_value)
));
- if let Some(PhpMixed::Array(co)) =
- php_ext.get_mut("configure-options").map(|v| v.as_mut())
- {
- if let Some(entry) = co.get_mut(key) {
- if let PhpMixed::Array(em) = entry.as_mut() {
- em.shift_remove("needs-value");
- }
- }
- }
+ if let Some(PhpMixed::Array(co)) =
+ php_ext.get_mut("configure-options").map(|v| v.as_mut())
+ && let Some(entry) = co.get_mut(key)
+ && let PhpMixed::Array(em) = entry.as_mut()
+ {
+ em.shift_remove("needs-value");
}
}
- if let Some(description) = option_map.get("description").cloned() {
- if !is_string(&*description) {
- self.errors.push(format!(
+ if let Some(description) = option_map.get("description").cloned()
+ && !is_string(&description)
+ {
+ self.errors.push(format!(
"php-ext.configure-options.{}.description : should be a string, {} given",
key,
- get_debug_type(&*description)
+ get_debug_type(&description)
));
- if let Some(PhpMixed::Array(co)) =
- php_ext.get_mut("configure-options").map(|v| v.as_mut())
- {
- if let Some(entry) = co.get_mut(key) {
- if let PhpMixed::Array(em) = entry.as_mut() {
- em.shift_remove("description");
- }
- }
- }
+ if let Some(PhpMixed::Array(co)) =
+ php_ext.get_mut("configure-options").map(|v| v.as_mut())
+ && let Some(entry) = co.get_mut(key)
+ && let PhpMixed::Array(em) = entry.as_mut()
+ {
+ em.shift_remove("description");
}
}
}
@@ -885,19 +869,19 @@ impl ValidatingArrayLoader {
.unwrap_or_default();
for (package, constraint) in &link_section {
let package = package.to_string();
- if let Some(name_val) = self.config.get("name").and_then(|v| v.as_string()) {
- if strcasecmp(&package, name_val) == 0 {
- self.errors.push(format!(
- "{}.{} : a package cannot set a {} on itself",
- link_type, package, link_type
- ));
- if let Some(PhpMixed::Array(arr)) =
- self.config.get_mut(link_type).map(|v| v.as_mut())
- {
- arr.shift_remove(&package);
- }
- continue;
+ if let Some(name_val) = self.config.get("name").and_then(|v| v.as_string())
+ && strcasecmp(&package, name_val) == 0
+ {
+ self.errors.push(format!(
+ "{}.{} : a package cannot set a {} on itself",
+ link_type, package, link_type
+ ));
+ if let Some(PhpMixed::Array(arr)) =
+ self.config.get_mut(link_type).map(|v| v.as_mut())
+ {
+ arr.shift_remove(&package);
}
+ continue;
}
if let Some(err) = Self::has_package_naming_error(&package, true) {
self.warnings.push(format!("{}.{}", link_type, err));
@@ -907,7 +891,7 @@ impl ValidatingArrayLoader {
link_type, package
));
}
- if !is_string(&**constraint) {
+ if !is_string(constraint) {
self.errors.push(format!(
"{}.{} : invalid value, must be a string containing a version constraint",
link_type, package
@@ -950,7 +934,7 @@ impl ValidatingArrayLoader {
&& link_type == "require"
&& link_constraint
.as_constraint()
- .map_or(false, |c| ["==", "="].contains(&c.get_operator()))
+ .is_some_and(|c| ["==", "="].contains(&c.get_operator()))
&& AnyConstraint::from(SimpleConstraint::new(
">=".to_string(),
"1.0.0.0-dev".to_string(),
@@ -1017,7 +1001,7 @@ impl ValidatingArrayLoader {
.cloned()
.unwrap_or_default();
for (package, description) in &suggest_map {
- if !is_string(&**description) {
+ if !is_string(description) {
self.errors.push(format!(
"suggest.{} : invalid value, must be a string describing why the package is suggested",
package
@@ -1076,16 +1060,16 @@ impl ValidatingArrayLoader {
arr.shift_remove(r#type);
}
}
- if r#type == "psr-4" {
- if let Some(type_map) = type_config.as_array() {
- for (namespace, _dirs) in type_map {
- let ns_str = namespace.as_str();
- if ns_str != "" && substr(ns_str, -1, None) != "\\" {
- self.errors.push(format!(
+ if r#type == "psr-4"
+ && let Some(type_map) = type_config.as_array()
+ {
+ for (namespace, _dirs) in type_map {
+ let ns_str = namespace.as_str();
+ if !ns_str.is_empty() && substr(ns_str, -1, None) != "\\" {
+ self.errors.push(format!(
"autoload.psr-4 : invalid value ({}), namespaces must end with a namespace separator, should be {}\\\\",
ns_str, ns_str
));
- }
}
}
}
@@ -1132,35 +1116,36 @@ impl ValidatingArrayLoader {
self.errors
.push(format!("{}.reference : must be present", src_type));
}
- if let Some(type_val) = section.get("type") {
- if !is_string(&**type_val) {
- self.errors.push(format!(
- "{}.type : should be a string, {} given",
- src_type,
- get_debug_type(&**type_val)
- ));
- }
+ if let Some(type_val) = section.get("type")
+ && !is_string(type_val)
+ {
+ self.errors.push(format!(
+ "{}.type : should be a string, {} given",
+ src_type,
+ get_debug_type(type_val)
+ ));
}
- if let Some(url_val) = section.get("url") {
- if !is_string(&**url_val) {
- self.errors.push(format!(
- "{}.url : should be a string, {} given",
- src_type,
- get_debug_type(&**url_val)
- ));
- }
+ if let Some(url_val) = section.get("url")
+ && !is_string(url_val)
+ {
+ self.errors.push(format!(
+ "{}.url : should be a string, {} given",
+ src_type,
+ get_debug_type(url_val)
+ ));
}
- if let Some(ref_val) = section.get("reference") {
- if !is_string(&**ref_val) && !is_int(&**ref_val) {
- self.errors.push(format!(
- "{}.reference : should be a string or int, {} given",
- src_type,
- get_debug_type(&**ref_val)
- ));
- }
+ if let Some(ref_val) = section.get("reference")
+ && !is_string(ref_val)
+ && !is_int(ref_val)
+ {
+ self.errors.push(format!(
+ "{}.reference : should be a string or int, {} given",
+ src_type,
+ get_debug_type(ref_val)
+ ));
}
if let Some(ref_val) = section.get("reference") {
- let ref_str = php_to_string(&**ref_val);
+ let ref_str = php_to_string(ref_val);
if Preg::is_match("{^\\s*-}", &ref_str) {
self.errors.push(format!(
"{}.reference : must not start with a \"-\", \"{}\" given",
@@ -1169,7 +1154,7 @@ impl ValidatingArrayLoader {
}
}
if let Some(url_val) = section.get("url") {
- let url_str = php_to_string(&**url_val);
+ let url_str = php_to_string(url_val);
if Preg::is_match("{^\\s*-}", &url_str) {
self.errors.push(format!(
"{}.url : must not start with a \"-\", \"{}\" given",
@@ -1195,28 +1180,26 @@ impl ValidatingArrayLoader {
.unwrap_or(false);
if has_branch_alias {
let branch_alias_val = self.config["extra"].as_array().unwrap()["branch-alias"].clone();
- if !is_array(&*branch_alias_val) {
+ if !is_array(&branch_alias_val) {
self.errors.push(
"extra.branch-alias : must be an array of versions => aliases".to_string(),
);
} else {
let branch_alias_map = branch_alias_val.as_array().cloned().unwrap_or_default();
for (source_branch, target_branch) in &branch_alias_map {
- if !is_string(&**target_branch) {
+ if !is_string(target_branch) {
self.warnings.push(format!(
"extra.branch-alias.{} : the target branch ({}) must be a string, \"{}\" received.",
source_branch,
json_encode(&**target_branch).unwrap_or_default(),
- get_debug_type(&**target_branch)
+ get_debug_type(target_branch)
));
if let Some(PhpMixed::Array(extra)) =
self.config.get_mut("extra").map(|v| v.as_mut())
+ && let Some(ba) = extra.get_mut("branch-alias")
+ && let PhpMixed::Array(bam) = ba.as_mut()
{
- if let Some(ba) = extra.get_mut("branch-alias") {
- if let PhpMixed::Array(bam) = ba.as_mut() {
- bam.shift_remove(source_branch);
- }
- }
+ bam.shift_remove(source_branch);
}
continue;
}
@@ -1231,12 +1214,10 @@ impl ValidatingArrayLoader {
));
if let Some(PhpMixed::Array(extra)) =
self.config.get_mut("extra").map(|v| v.as_mut())
+ && let Some(ba) = extra.get_mut("branch-alias")
+ && let PhpMixed::Array(bam) = ba.as_mut()
{
- if let Some(ba) = extra.get_mut("branch-alias") {
- if let PhpMixed::Array(bam) = ba.as_mut() {
- bam.shift_remove(source_branch);
- }
- }
+ bam.shift_remove(source_branch);
}
continue;
}
@@ -1255,12 +1236,10 @@ impl ValidatingArrayLoader {
));
if let Some(PhpMixed::Array(extra)) =
self.config.get_mut("extra").map(|v| v.as_mut())
+ && let Some(ba) = extra.get_mut("branch-alias")
+ && let PhpMixed::Array(bam) = ba.as_mut()
{
- if let Some(ba) = extra.get_mut("branch-alias") {
- if let PhpMixed::Array(bam) = ba.as_mut() {
- bam.shift_remove(source_branch);
- }
- }
+ bam.shift_remove(source_branch);
}
continue;
}
@@ -1272,21 +1251,19 @@ impl ValidatingArrayLoader {
let target_prefix = self
.version_parser
.parse_numeric_alias_prefix(&target_branch_str);
- if let (Some(sp), Some(tp)) = (source_prefix, target_prefix) {
- if !tp.to_lowercase().starts_with(&sp.to_lowercase()) {
- self.warnings.push(format!(
+ if let (Some(sp), Some(tp)) = (source_prefix, target_prefix)
+ && !tp.to_lowercase().starts_with(&sp.to_lowercase())
+ {
+ self.warnings.push(format!(
"extra.branch-alias.{} : the target branch ({}) is not a valid numeric alias for this version",
source_branch, target_branch_str
));
- if let Some(PhpMixed::Array(extra)) =
- self.config.get_mut("extra").map(|v| v.as_mut())
- {
- if let Some(ba) = extra.get_mut("branch-alias") {
- if let PhpMixed::Array(bam) = ba.as_mut() {
- bam.shift_remove(source_branch);
- }
- }
- }
+ if let Some(PhpMixed::Array(extra)) =
+ self.config.get_mut("extra").map(|v| v.as_mut())
+ && let Some(ba) = extra.get_mut("branch-alias")
+ && let PhpMixed::Array(bam) = ba.as_mut()
+ {
+ bam.shift_remove(source_branch);
}
}
}
@@ -1410,11 +1387,11 @@ impl ValidatingArrayLoader {
}
fn validate_string(&mut self, property: &str, mandatory: bool) -> bool {
- if self.config.contains_key(property) && !is_string(&*self.config[property]) {
+ if self.config.contains_key(property) && !is_string(&self.config[property]) {
self.errors.push(format!(
"{} : should be a string, {} given",
property,
- get_debug_type(&*self.config[property])
+ get_debug_type(&self.config[property])
));
self.config.shift_remove(property);
@@ -1425,7 +1402,8 @@ impl ValidatingArrayLoader {
|| trim(
self.config[property].as_string().unwrap_or(""),
Some(" \t\n\r\0\u{0B}"),
- ) == "";
+ )
+ .is_empty();
if is_empty {
if mandatory {
self.errors.push(format!("{} : must be present", property));
@@ -1439,11 +1417,11 @@ impl ValidatingArrayLoader {
}
fn validate_array(&mut self, property: &str, mandatory: bool) -> bool {
- if self.config.contains_key(property) && !is_array(&*self.config[property]) {
+ if self.config.contains_key(property) && !is_array(&self.config[property]) {
self.errors.push(format!(
"{} : should be an array, {} given",
property,
- get_debug_type(&*self.config[property])
+ get_debug_type(&self.config[property])
));
self.config.shift_remove(property);
@@ -1486,12 +1464,12 @@ impl ValidatingArrayLoader {
.map(|m| m.iter().map(|(k, v)| (k.clone(), v.clone())).collect())
.unwrap_or_default();
for (key, value) in entries {
- if !is_string(&*value) && !is_numeric(&*value) {
+ if !is_string(&value) && !is_numeric(&value) {
self.errors.push(format!(
"{}.{} : must be a string or int, {} given",
property,
key,
- get_debug_type(&*value)
+ get_debug_type(&value)
));
if let Some(PhpMixed::Array(arr)) =
self.config.get_mut(property).map(|v| v.as_mut())
@@ -1504,7 +1482,7 @@ impl ValidatingArrayLoader {
}
if let Some(regex_str) = regex {
- let value_str = php_to_string(&*value);
+ let value_str = php_to_string(&value);
if !Preg::is_match(&format!("{{^{}$}}u", regex_str), &value_str) {
self.warnings.push(format!(
"{}.{} : invalid value ({}), must match {}",
@@ -1543,7 +1521,7 @@ impl ValidatingArrayLoader {
}
fn filter_url(&self, value: &str, schemes: &[&str]) -> bool {
- if value == "" {
+ if value.is_empty() {
return true;
}