aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/package/loader
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/src/package/loader')
-rw-r--r--crates/shirabe/src/package/loader/array_loader.rs38
-rw-r--r--crates/shirabe/src/package/loader/invalid_package_exception.rs7
-rw-r--r--crates/shirabe/src/package/loader/json_loader.rs8
-rw-r--r--crates/shirabe/src/package/loader/loader_interface.rs8
-rw-r--r--crates/shirabe/src/package/loader/mod.rs6
-rw-r--r--crates/shirabe/src/package/loader/root_package_loader.rs89
-rw-r--r--crates/shirabe/src/package/loader/validating_array_loader.rs169
7 files changed, 162 insertions, 163 deletions
diff --git a/crates/shirabe/src/package/loader/array_loader.rs b/crates/shirabe/src/package/loader/array_loader.rs
index c0dc2a2..72d9754 100644
--- a/crates/shirabe/src/package/loader/array_loader.rs
+++ b/crates/shirabe/src/package/loader/array_loader.rs
@@ -5,9 +5,9 @@ use chrono::{DateTime, TimeZone, Utc};
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::preg::Preg;
use shirabe_php_shim::{
- is_scalar, is_string, json_encode, ltrim, sprintf, stripos, strpos, strtolower, strval, substr,
- trigger_error, trim, ucfirst, Exception, LogicException, PhpMixed, UnexpectedValueException,
- E_USER_DEPRECATED,
+ E_USER_DEPRECATED, Exception, LogicException, PhpMixed, UnexpectedValueException, is_scalar,
+ is_string, json_encode, ltrim, sprintf, stripos, strpos, strtolower, strval, substr,
+ trigger_error, trim, ucfirst,
};
use crate::package::base_package::{BasePackage, SUPPORTED_LINK_TYPES};
@@ -213,7 +213,9 @@ impl ArrayLoader {
let _name = config.get("name").and_then(|v| v.as_string()).unwrap_or("");
let _pretty_version = config_version.as_string().unwrap_or("").to_string();
let _ = version;
- todo!("phase-b: dynamic class-string instantiation new $class($name, $version, $prettyVersion)")
+ todo!(
+ "phase-b: dynamic class-string instantiation new $class($name, $version, $prettyVersion)"
+ )
}
/// @param CompletePackage $package
@@ -482,9 +484,7 @@ impl ArrayLoader {
if let Some(description) = config.get("description") {
if !shirabe_php_shim::empty(description) && is_string(description) {
- package.set_description(
- description.as_string().unwrap_or("").to_string(),
- );
+ package.set_description(description.as_string().unwrap_or("").to_string());
}
}
@@ -629,10 +629,9 @@ impl ArrayLoader {
let mut links: IndexMap<String, Link> = IndexMap::new();
let entries: IndexMap<String, PhpMixed> = match entry {
- PhpMixed::Array(m) => m
- .iter()
- .map(|(k, v)| (k.clone(), (**v).clone()))
- .collect(),
+ PhpMixed::Array(m) => {
+ m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()
+ }
_ => continue,
};
for (pretty_target, constraint) in entries {
@@ -781,10 +780,7 @@ impl ArrayLoader {
/// @param mixed[] $config the entire package config
///
/// @return string|null normalized version of the branch alias or null if there is none
- pub fn get_branch_alias(
- &self,
- config: &IndexMap<String, PhpMixed>,
- ) -> Result<Option<String>> {
+ pub fn get_branch_alias(&self, config: &IndexMap<String, PhpMixed>) -> Result<Option<String>> {
if !config.contains_key("version") || !is_scalar(config.get("version").unwrap()) {
return Err(UnexpectedValueException {
message: "no/invalid version defined".to_string(),
@@ -824,7 +820,8 @@ impl ArrayLoader {
}
// normalize without -dev and ensure it's a numeric branch that is parseable
- let validated_target_branch = if target_branch == VersionParser::DEFAULT_BRANCH_ALIAS
+ let validated_target_branch = if target_branch
+ == VersionParser::DEFAULT_BRANCH_ALIAS
{
VersionParser::DEFAULT_BRANCH_ALIAS.to_string()
} else {
@@ -841,9 +838,12 @@ impl ArrayLoader {
}
// If using numeric aliases ensure the alias is a valid subversion
- let source_prefix =
- self.version_parser.parse_numeric_alias_prefix(&source_branch);
- let target_prefix = self.version_parser.parse_numeric_alias_prefix(&target_branch);
+ let source_prefix = self
+ .version_parser
+ .parse_numeric_alias_prefix(&source_branch);
+ 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;
diff --git a/crates/shirabe/src/package/loader/invalid_package_exception.rs b/crates/shirabe/src/package/loader/invalid_package_exception.rs
index 88a7f5f..b0eeb23 100644
--- a/crates/shirabe/src/package/loader/invalid_package_exception.rs
+++ b/crates/shirabe/src/package/loader/invalid_package_exception.rs
@@ -14,7 +14,12 @@ impl InvalidPackageException {
pub fn new(errors: Vec<String>, warnings: Vec<String>, data: Vec<PhpMixed>) -> Self {
let message = format!(
"Invalid package information: \n{}",
- errors.iter().chain(warnings.iter()).cloned().collect::<Vec<_>>().join("\n")
+ errors
+ .iter()
+ .chain(warnings.iter())
+ .cloned()
+ .collect::<Vec<_>>()
+ .join("\n")
);
Self {
inner: Exception { message, code: 0 },
diff --git a/crates/shirabe/src/package/loader/json_loader.rs b/crates/shirabe/src/package/loader/json_loader.rs
index 5e5829a..8f10995 100644
--- a/crates/shirabe/src/package/loader/json_loader.rs
+++ b/crates/shirabe/src/package/loader/json_loader.rs
@@ -1,10 +1,10 @@
//! ref: composer/src/Composer/Package/Loader/JsonLoader.php
-use std::path::Path;
-use anyhow::Result;
use crate::json::json_file::JsonFile;
use crate::package::base_package::BasePackage;
use crate::package::loader::loader_interface::LoaderInterface;
+use anyhow::Result;
+use std::path::Path;
pub enum JsonLoaderInput {
File(JsonFile),
@@ -26,9 +26,7 @@ impl JsonLoader {
JsonLoaderInput::String(ref s) if Path::new(s).exists() => {
JsonFile::parse_json(&std::fs::read_to_string(s)?, Some(s))?
}
- JsonLoaderInput::String(ref s) => {
- JsonFile::parse_json(s, None)?
- }
+ JsonLoaderInput::String(ref s) => JsonFile::parse_json(s, None)?,
};
self.loader.load(config, None)
diff --git a/crates/shirabe/src/package/loader/loader_interface.rs b/crates/shirabe/src/package/loader/loader_interface.rs
index 9f1e6da..530f1eb 100644
--- a/crates/shirabe/src/package/loader/loader_interface.rs
+++ b/crates/shirabe/src/package/loader/loader_interface.rs
@@ -1,9 +1,13 @@
//! ref: composer/src/Composer/Package/Loader/LoaderInterface.php
+use crate::package::base_package::BasePackage;
use indexmap::IndexMap;
use shirabe_php_shim::PhpMixed;
-use crate::package::base_package::BasePackage;
pub trait LoaderInterface {
- fn load(&self, config: IndexMap<String, PhpMixed>, class: Option<String>) -> anyhow::Result<Box<BasePackage>>;
+ fn load(
+ &self,
+ config: IndexMap<String, PhpMixed>,
+ class: Option<String>,
+ ) -> anyhow::Result<Box<BasePackage>>;
}
diff --git a/crates/shirabe/src/package/loader/mod.rs b/crates/shirabe/src/package/loader/mod.rs
new file mode 100644
index 0000000..402b59c
--- /dev/null
+++ b/crates/shirabe/src/package/loader/mod.rs
@@ -0,0 +1,6 @@
+pub mod array_loader;
+pub mod invalid_package_exception;
+pub mod json_loader;
+pub mod loader_interface;
+pub mod root_package_loader;
+pub mod validating_array_loader;
diff --git a/crates/shirabe/src/package/loader/root_package_loader.rs b/crates/shirabe/src/package/loader/root_package_loader.rs
index eef7d70..59c9cf5 100644
--- a/crates/shirabe/src/package/loader/root_package_loader.rs
+++ b/crates/shirabe/src/package/loader/root_package_loader.rs
@@ -2,7 +2,9 @@
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::preg::Preg;
-use shirabe_php_shim::{strtolower, ucfirst, LogicException, RuntimeException, UnexpectedValueException};
+use shirabe_php_shim::{
+ LogicException, RuntimeException, UnexpectedValueException, strtolower, ucfirst,
+};
use crate::config::Config;
use crate::io::io_interface::IOInterface;
@@ -92,12 +94,16 @@ impl RootPackageLoader {
Box::new(shirabe_php_shim::PhpMixed::String(version)),
);
} else {
- let cwd_str = cwd.map(|s| s.to_string()).unwrap_or_else(|| Platform::get_cwd(true));
+ let cwd_str = cwd
+ .map(|s| s.to_string())
+ .unwrap_or_else(|| Platform::get_cwd(true));
let version_data = self.version_guesser.guess_version(&config, &cwd_str);
if let Some(data) = version_data {
config.insert(
"version".to_string(),
- Box::new(shirabe_php_shim::PhpMixed::String(data.pretty_version.clone())),
+ Box::new(shirabe_php_shim::PhpMixed::String(
+ data.pretty_version.clone(),
+ )),
);
config.insert(
"version_normalized".to_string(),
@@ -110,10 +116,7 @@ impl RootPackageLoader {
if !config.contains_key("version") {
if let Some(ref io) = self.io {
let name = config["name"].as_string().unwrap_or("");
- let package_type = config
- .get("type")
- .and_then(|v| v.as_string())
- .unwrap_or("");
+ let package_type = config.get("type").and_then(|v| v.as_string()).unwrap_or("");
if name != "__root__" && package_type != "project" {
io.warning(&format!(
"Composer could not detect the root package ({}) version, defaulting to '1.0.0'. See https://getcomposer.org/root-version",
@@ -167,42 +170,43 @@ impl RootPackageLoader {
}
}
- let package = self.inner.load(config.clone(), "Composer\\Package\\RootPackage")?;
+ let package = self
+ .inner
+ .load(config.clone(), "Composer\\Package\\RootPackage")?;
- let real_package: &mut RootPackage = if let Some(alias_pkg) =
- package.as_any_mut().downcast_mut::<RootAliasPackage>()
- {
- alias_pkg
- .get_alias_of_mut()
- .as_any_mut()
- .downcast_mut::<RootPackage>()
- .ok_or_else(|| {
- anyhow::anyhow!(LogicException {
- message: "Expecting a Composer\\Package\\RootPackage at this point"
- .to_string(),
- code: 0,
- })
- })?
- } else if let Some(root_pkg) = package.as_any_mut().downcast_mut::<RootPackage>() {
- root_pkg
- } else {
- return Err(anyhow::anyhow!(LogicException {
- message: "Expecting a Composer\\Package\\RootPackage at this point".to_string(),
- code: 0,
- }));
- };
+ let real_package: &mut RootPackage =
+ if let Some(alias_pkg) = package.as_any_mut().downcast_mut::<RootAliasPackage>() {
+ alias_pkg
+ .get_alias_of_mut()
+ .as_any_mut()
+ .downcast_mut::<RootPackage>()
+ .ok_or_else(|| {
+ anyhow::anyhow!(LogicException {
+ message: "Expecting a Composer\\Package\\RootPackage at this point"
+ .to_string(),
+ code: 0,
+ })
+ })?
+ } else if let Some(root_pkg) = package.as_any_mut().downcast_mut::<RootPackage>() {
+ root_pkg
+ } else {
+ return Err(anyhow::anyhow!(LogicException {
+ message: "Expecting a Composer\\Package\\RootPackage at this point".to_string(),
+ code: 0,
+ }));
+ };
if auto_versioned {
- real_package
- .replace_version(real_package.get_version().to_string(), RootPackage::DEFAULT_PRETTY_VERSION.to_string());
+ real_package.replace_version(
+ real_package.get_version().to_string(),
+ RootPackage::DEFAULT_PRETTY_VERSION.to_string(),
+ );
}
- if let Some(min_stability) = config
- .get("minimum-stability")
- .and_then(|v| v.as_string())
- {
- real_package
- .set_minimum_stability(VersionParser::normalize_stability(min_stability).to_string());
+ if let Some(min_stability) = config.get("minimum-stability").and_then(|v| v.as_string()) {
+ real_package.set_minimum_stability(
+ VersionParser::normalize_stability(min_stability).to_string(),
+ );
}
let mut aliases: Vec<IndexMap<String, String>> = vec![];
@@ -362,16 +366,11 @@ impl RootPackageLoader {
}
let stability_names: Vec<&str> = stabilities.keys().copied().collect();
- let pattern = format!(
- "^[^@]*?@({})$",
- stability_names.join("|")
- );
+ let pattern = format!("^[^@]*?@({})$", stability_names.join("|"));
let mut matched = false;
for constraint in &constraints {
- if let Some(Some(m)) =
- Preg::is_match_strict_groups(&pattern, constraint).ok()
- {
+ if let Some(Some(m)) = Preg::is_match_strict_groups(&pattern, constraint).ok() {
let name = strtolower(req_name);
let stability = stabilities[VersionParser::normalize_stability(&m[1])];
diff --git a/crates/shirabe/src/package/loader/validating_array_loader.rs b/crates/shirabe/src/package/loader/validating_array_loader.rs
index 16806d7..c1be9f2 100644
--- a/crates/shirabe/src/package/loader/validating_array_loader.rs
+++ b/crates/shirabe/src/package/loader/validating_array_loader.rs
@@ -6,10 +6,10 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::preg::Preg;
use shirabe_external_packages::composer::spdx_licenses::spdx_licenses::SpdxLicenses;
use shirabe_php_shim::{
- array_intersect_key, array_values, filter_var, get_debug_type, is_array, is_bool, is_int,
- is_numeric, is_scalar, is_string, json_encode, parse_url_all, php_to_string, sprintf,
- str_replace, strcasecmp, strtolower, strtotime, substr, trigger_error, trim, var_export,
- Exception, PhpMixed, E_USER_DEPRECATED, FILTER_VALIDATE_EMAIL, PHP_EOL,
+ E_USER_DEPRECATED, Exception, FILTER_VALIDATE_EMAIL, PHP_EOL, PhpMixed, array_intersect_key,
+ array_values, filter_var, get_debug_type, is_array, is_bool, is_int, is_numeric, is_scalar,
+ is_string, json_encode, parse_url_all, php_to_string, sprintf, str_replace, strcasecmp,
+ strtolower, strtotime, substr, trigger_error, trim, var_export,
};
use shirabe_semver::constraint::constraint::Constraint;
use shirabe_semver::constraint::match_none_constraint::MatchNoneConstraint;
@@ -97,11 +97,8 @@ impl ValidatingArrayLoader {
match self.version_parser.normalize(&version_str, None) {
Ok(_) => {}
Err(e) => {
- self.errors.push(format!(
- "version : invalid value ({}): {}",
- version_str,
- e
- ));
+ self.errors
+ .push(format!("version : invalid value ({}): {}", version_str, e));
self.config.shift_remove("version");
}
}
@@ -173,10 +170,8 @@ impl ValidatingArrayLoader {
release_date = Some(dt);
}
Err(e) => {
- self.errors.push(format!(
- "time : invalid value ({}): {}",
- time_str, e
- ));
+ self.errors
+ .push(format!("time : invalid value ({}): {}", time_str, e));
self.config.shift_remove("time");
}
}
@@ -209,9 +204,7 @@ impl ValidatingArrayLoader {
// check for license validity on newly updated branches/tags
let cutoff = strtotime("-8days").unwrap_or(0);
- if release_date.is_none()
- || release_date.unwrap().timestamp() >= cutoff
- {
+ if release_date.is_none() || release_date.unwrap().timestamp() >= cutoff {
let license_validator = SpdxLicenses::new();
for license in licenses.values() {
let license_str = license.as_string().unwrap_or("").to_string();
@@ -219,10 +212,11 @@ impl ValidatingArrayLoader {
if license_str == "proprietary" {
continue;
}
- let license_to_validate =
- str_replace("proprietary", "MIT", &license_str);
+ let license_to_validate = str_replace("proprietary", "MIT", &license_str);
if !license_validator.validate(&license_to_validate) {
- if license_validator.validate(&trim(&license_to_validate, " \t\n\r\0\u{0B}")) {
+ if license_validator
+ .validate(&trim(&license_to_validate, " \t\n\r\0\u{0B}"))
+ {
self.warnings.push(sprintf(
"License %s must not contain extra spaces, make sure to trim it.",
&[PhpMixed::String(
@@ -258,7 +252,9 @@ impl ValidatingArrayLoader {
} else {
self.warnings.push(sprintf(
"License must be a string or array of strings, got %s.",
- &[PhpMixed::String(json_encode(&*license_val).unwrap_or_default())],
+ &[PhpMixed::String(
+ json_encode(&*license_val).unwrap_or_default(),
+ )],
));
self.config.shift_remove("license");
}
@@ -277,20 +273,15 @@ impl ValidatingArrayLoader {
key,
get_debug_type(&*author)
));
- if let Some(PhpMixed::Array(m)) = self
- .config
- .get_mut("authors")
- .map(|v| v.as_mut())
+ if let Some(PhpMixed::Array(m)) =
+ self.config.get_mut("authors").map(|v| v.as_mut())
{
m.shift_remove(key);
}
continue;
}
for author_data in ["homepage", "email", "name", "role"] {
- let val_opt = author
- .as_array()
- .and_then(|m| m.get(author_data))
- .cloned();
+ 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!(
@@ -395,10 +386,8 @@ impl ValidatingArrayLoader {
.cloned();
if let Some(val) = val_opt {
if !is_string(&*val) {
- self.errors.push(format!(
- "support.{} : invalid value, must be a string",
- key
- ));
+ 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())
{
@@ -450,7 +439,9 @@ impl ValidatingArrayLoader {
}
}
- for key in ["issues", "forum", "wiki", "source", "docs", "chat", "security"] {
+ for key in [
+ "issues", "forum", "wiki", "source", "docs", "chat", "security",
+ ] {
let url_opt = self
.config
.get("support")
@@ -647,8 +638,11 @@ impl ValidatingArrayLoader {
));
php_ext.shift_remove("download-url-method");
} else {
- let valid_download_url_methods =
- ["composer-default", "pre-packaged-source", "pre-packaged-binary"];
+ let valid_download_url_methods = [
+ "composer-default",
+ "pre-packaged-source",
+ "pre-packaged-binary",
+ ];
let defined_download_url_methods: IndexMap<String, Box<PhpMixed>> =
if is_array(&*v) {
v.as_array().unwrap().clone()
@@ -673,9 +667,9 @@ impl ValidatingArrayLoader {
get_debug_type(&**download_url_method)
));
php_ext.shift_remove("download-url-method");
- } else if !valid_download_url_methods.contains(
- &download_url_method.as_string().unwrap_or(""),
- ) {
+ } else if !valid_download_url_methods
+ .contains(&download_url_method.as_string().unwrap_or(""))
+ {
self.errors.push(format!(
"php-ext.download-url-method.{} : invalid value ({}), must be one of {}",
key,
@@ -718,15 +712,10 @@ impl ValidatingArrayLoader {
));
php_ext.shift_remove(field_name);
} else {
- let field_keys: Vec<String> = field_val
- .as_array()
- .unwrap()
- .keys()
- .cloned()
- .collect();
+ let field_keys: Vec<String> =
+ field_val.as_array().unwrap().keys().cloned().collect();
for key in &field_keys {
- let os_family =
- field_val.as_array().unwrap()[key].clone();
+ let os_family = field_val.as_array().unwrap()[key].clone();
if !is_string(&*os_family) {
self.errors.push(format!(
"php-ext.{}.{} : should be a string, {} given",
@@ -785,8 +774,7 @@ impl ValidatingArrayLoader {
.cloned()
.collect();
for key in &configure_keys {
- let option =
- configure_options.as_array().unwrap()[key].clone();
+ let option = configure_options.as_array().unwrap()[key].clone();
if !is_array(&*option) {
self.errors.push(format!(
"php-ext.configure-options.{} : should be an array, {} given",
@@ -837,9 +825,8 @@ impl ValidatingArrayLoader {
key,
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(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() {
@@ -850,18 +837,15 @@ impl ValidatingArrayLoader {
}
}
- if let Some(description) =
- option_map.get("description").cloned()
- {
+ if let Some(description) = option_map.get("description").cloned() {
if !is_string(&*description) {
self.errors.push(format!(
"php-ext.configure-options.{}.description : should be a string, {} given",
key,
get_debug_type(&*description)
));
- if let Some(PhpMixed::Array(co)) = php_ext
- .get_mut("configure-options")
- .map(|v| v.as_mut())
+ 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() {
@@ -886,10 +870,8 @@ impl ValidatingArrayLoader {
// If php-ext is now empty, unset it
if !php_ext.is_empty() {
- self.config.insert(
- "php-ext".to_string(),
- Box::new(PhpMixed::Array(php_ext)),
- );
+ self.config
+ .insert("php-ext".to_string(), Box::new(PhpMixed::Array(php_ext)));
}
}
}
@@ -938,8 +920,7 @@ impl ValidatingArrayLoader {
arr.shift_remove(&package);
}
} else if constraint.as_string().unwrap_or("") != "self.version" {
- let constraint_str =
- constraint.as_string().unwrap_or("").to_string();
+ let constraint_str = constraint.as_string().unwrap_or("").to_string();
let link_constraint =
match self.version_parser.parse_constraints(&constraint_str) {
Ok(c) => c,
@@ -972,9 +953,7 @@ impl ValidatingArrayLoader {
&& link_constraint
.as_any()
.downcast_ref::<Constraint>()
- .map_or(false, |c| {
- ["==", "="].contains(&c.get_operator())
- })
+ .map_or(false, |c| ["==", "="].contains(&c.get_operator()))
&& Constraint::new(">=", "1.0.0.0-dev")
.matches(link_constraint.as_ref())
{
@@ -1063,7 +1042,13 @@ impl ValidatingArrayLoader {
}
if self.validate_array("autoload", false) && self.config.contains_key("autoload") {
- let types = ["psr-0", "psr-4", "classmap", "files", "exclude-from-classmap"];
+ let types = [
+ "psr-0",
+ "psr-4",
+ "classmap",
+ "files",
+ "exclude-from-classmap",
+ ];
let autoload_keys: Vec<String> = self.config["autoload"]
.as_array()
.map(|m| m.keys().cloned().collect())
@@ -1086,9 +1071,7 @@ impl ValidatingArrayLoader {
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) != "\\"
- {
+ if ns_str != "" && 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
@@ -1112,8 +1095,7 @@ impl ValidatingArrayLoader {
);
// Unset the psr-4 setting, since unsetting target-dir might
// interfere with other settings.
- if let Some(PhpMixed::Array(arr)) =
- self.config.get_mut("autoload").map(|v| v.as_mut())
+ if let Some(PhpMixed::Array(arr)) = self.config.get_mut("autoload").map(|v| v.as_mut())
{
arr.shift_remove("psr-4");
}
@@ -1205,8 +1187,9 @@ impl ValidatingArrayLoader {
if has_branch_alias {
let branch_alias_val = self.config["extra"].as_array().unwrap()["branch-alias"].clone();
if !is_array(&*branch_alias_val) {
- self.errors
- .push("extra.branch-alias : must be an array of versions => aliases".to_string());
+ 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 {
@@ -1255,9 +1238,7 @@ impl ValidatingArrayLoader {
0,
Some((target_branch_str.len() as i64) - 4),
);
- let validated_target_branch = self
- .version_parser
- .normalize_branch(&trimmed);
+ let validated_target_branch = self.version_parser.normalize_branch(&trimmed);
if substr(&validated_target_branch, -4, None) != "-dev" {
self.warnings.push(format!(
"extra.branch-alias.{} : the target branch ({}) must be a parseable number like 2.0-dev",
@@ -1311,15 +1292,13 @@ impl ValidatingArrayLoader {
)));
}
- let package = self
- .loader
- .load(
- self.config
- .iter()
- .map(|(k, v)| (k.clone(), (**v).clone()))
- .collect(),
- Some(class.to_string()),
- )?;
+ let package = self.loader.load(
+ self.config
+ .iter()
+ .map(|(k, v)| (k.clone(), (**v).clone()))
+ .collect(),
+ Some(class.to_string()),
+ )?;
self.config = IndexMap::new();
Ok(package)
@@ -1344,7 +1323,10 @@ impl ValidatingArrayLoader {
)
.unwrap_or(false)
{
- return Some(format!("{} is invalid, it should have a vendor name, a forward slash, and a package name. The vendor and package name can be words separated by -, . or _. The complete name should match \"^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{{0,2}})[a-z0-9]+)*$\".", name));
+ return Some(format!(
+ "{} is invalid, it should have a vendor name, a forward slash, and a package name. The vendor and package name can be words separated by -, . or _. The complete name should match \"^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{{0,2}})[a-z0-9]+)*$\".",
+ name
+ ));
}
let reserved_names = [
@@ -1401,7 +1383,10 @@ impl ValidatingArrayLoader {
let value = self.config[property].as_string().unwrap_or("").to_string();
if !Preg::is_match(&format!("{{^{}$}}u", regex), &value).unwrap_or(false) {
- let message = format!("{} : invalid value ({}), must match {}", property, value, regex);
+ let message = format!(
+ "{} : invalid value ({}), must match {}",
+ property, value, regex
+ );
if mandatory {
self.errors.push(message);
} else {
@@ -1428,11 +1413,13 @@ impl ValidatingArrayLoader {
}
let is_empty = !self.config.contains_key(property)
- || trim(self.config[property].as_string().unwrap_or(""), " \t\n\r\0\u{0B}") == "";
+ || trim(
+ self.config[property].as_string().unwrap_or(""),
+ " \t\n\r\0\u{0B}",
+ ) == "";
if is_empty {
if mandatory {
- self.errors
- .push(format!("{} : must be present", property));
+ self.errors.push(format!("{} : must be present", property));
}
self.config.shift_remove(property);