aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-20 18:34:54 +0900
committernsfisis <nsfisis@gmail.com>2026-06-20 18:34:54 +0900
commit81b9fc9d92bb74aa8428ae4db39bd84e8c16095c (patch)
tree3efb6476d797e2a95545c4c3abba468c3e3c8d52 /crates
parentc09cd630afb4bb0ca10e926f93bf706ca828ae85 (diff)
downloadphp-shirabe-81b9fc9d92bb74aa8428ae4db39bd84e8c16095c.tar.gz
php-shirabe-81b9fc9d92bb74aa8428ae4db39bd84e8c16095c.tar.zst
php-shirabe-81b9fc9d92bb74aa8428ae4db39bd84e8c16095c.zip
refactor(php-shim): drop Box wrapping from PhpMixed List/Array
The List and Array variants of PhpMixed boxed their elements unnecessarily. Store PhpMixed values directly and update all callers accordingly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates')
-rw-r--r--crates/shirabe-class-map-generator/src/class_map_generator.rs8
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/cursor.rs18
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/descriptor/application_description.rs7
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs64
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs12
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs17
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs2
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs8
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/input/array_input.rs4
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/input/input_option.rs2
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs22
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/question/question.rs10
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs39
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/terminal.rs15
-rw-r--r--crates/shirabe-php-shim/src/lib.rs95
-rw-r--r--crates/shirabe/src/advisory/audit_config.rs8
-rw-r--r--crates/shirabe/src/advisory/auditor.rs12
-rw-r--r--crates/shirabe/src/autoload/autoload_generator.rs52
-rw-r--r--crates/shirabe/src/autoload/class_loader.rs24
-rw-r--r--crates/shirabe/src/command/base_command.rs6
-rw-r--r--crates/shirabe/src/command/base_config_command.rs5
-rw-r--r--crates/shirabe/src/command/base_dependency_command.rs9
-rw-r--r--crates/shirabe/src/command/bump_command.rs6
-rw-r--r--crates/shirabe/src/command/check_platform_reqs_command.rs38
-rw-r--r--crates/shirabe/src/command/config_command.rs127
-rw-r--r--crates/shirabe/src/command/create_project_command.rs9
-rw-r--r--crates/shirabe/src/command/diagnose_command.rs56
-rw-r--r--crates/shirabe/src/command/init_command.rs48
-rw-r--r--crates/shirabe/src/command/licenses_command.rs56
-rw-r--r--crates/shirabe/src/command/package_discovery_trait.rs4
-rw-r--r--crates/shirabe/src/command/remove_command.rs2
-rw-r--r--crates/shirabe/src/command/repository_command.rs13
-rw-r--r--crates/shirabe/src/command/require_command.rs16
-rw-r--r--crates/shirabe/src/command/run_script_command.rs4
-rw-r--r--crates/shirabe/src/command/search_command.rs4
-rw-r--r--crates/shirabe/src/command/show_command.rs125
-rw-r--r--crates/shirabe/src/command/suggests_command.rs2
-rw-r--r--crates/shirabe/src/command/update_command.rs10
-rw-r--r--crates/shirabe/src/config.rs163
-rw-r--r--crates/shirabe/src/config/json_config_source.rs213
-rw-r--r--crates/shirabe/src/console/application.rs10
-rw-r--r--crates/shirabe/src/dependency_resolver/problem.rs6
-rw-r--r--crates/shirabe/src/downloader/download_manager.rs2
-rw-r--r--crates/shirabe/src/downloader/file_downloader.rs8
-rw-r--r--crates/shirabe/src/downloader/gzip_downloader.rs2
-rw-r--r--crates/shirabe/src/downloader/rar_downloader.rs2
-rw-r--r--crates/shirabe/src/downloader/xz_downloader.rs2
-rw-r--r--crates/shirabe/src/downloader/zip_downloader.rs4
-rw-r--r--crates/shirabe/src/event_dispatcher/event_dispatcher.rs6
-rw-r--r--crates/shirabe/src/factory.rs30
-rw-r--r--crates/shirabe/src/installed_versions.rs70
-rw-r--r--crates/shirabe/src/installer.rs2
-rw-r--r--crates/shirabe/src/installer/installation_manager.rs30
-rw-r--r--crates/shirabe/src/io/base_io.rs40
-rw-r--r--crates/shirabe/src/io/console_io.rs40
-rw-r--r--crates/shirabe/src/json/json_file.rs31
-rw-r--r--crates/shirabe/src/json/json_manipulator.rs111
-rw-r--r--crates/shirabe/src/package/alias_package.rs6
-rw-r--r--crates/shirabe/src/package/dumper/array_dumper.rs144
-rw-r--r--crates/shirabe/src/package/loader/array_loader.rs51
-rw-r--r--crates/shirabe/src/package/loader/json_loader.rs2
-rw-r--r--crates/shirabe/src/package/loader/root_package_loader.rs23
-rw-r--r--crates/shirabe/src/package/loader/validating_array_loader.rs221
-rw-r--r--crates/shirabe/src/package/locker.rs121
-rw-r--r--crates/shirabe/src/package/version/version_guesser.rs10
-rw-r--r--crates/shirabe/src/platform/hhvm_detector.rs2
-rw-r--r--crates/shirabe/src/plugin/plugin_manager.rs17
-rw-r--r--crates/shirabe/src/plugin/pre_file_download_event.rs6
-rw-r--r--crates/shirabe/src/repository/artifact_repository.rs16
-rw-r--r--crates/shirabe/src/repository/composer_repository.rs249
-rw-r--r--crates/shirabe/src/repository/filesystem_repository.rs87
-rw-r--r--crates/shirabe/src/repository/filter_repository.rs4
-rw-r--r--crates/shirabe/src/repository/package_repository.rs12
-rw-r--r--crates/shirabe/src/repository/path_repository.rs27
-rw-r--r--crates/shirabe/src/repository/platform_repository.rs20
-rw-r--r--crates/shirabe/src/repository/repository_factory.rs19
-rw-r--r--crates/shirabe/src/repository/repository_manager.rs5
-rw-r--r--crates/shirabe/src/repository/vcs/forgejo_driver.rs20
-rw-r--r--crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs56
-rw-r--r--crates/shirabe/src/repository/vcs/github_driver.rs30
-rw-r--r--crates/shirabe/src/repository/vcs/gitlab_driver.rs53
-rw-r--r--crates/shirabe/src/repository/vcs/svn_driver.rs5
-rw-r--r--crates/shirabe/src/repository/vcs/vcs_driver.rs19
-rw-r--r--crates/shirabe/src/repository/vcs_repository.rs10
-rw-r--r--crates/shirabe/src/self_update/versions.rs6
-rw-r--r--crates/shirabe/src/util/auth_helper.rs37
-rw-r--r--crates/shirabe/src/util/bitbucket.rs42
-rw-r--r--crates/shirabe/src/util/config_validator.rs18
-rw-r--r--crates/shirabe/src/util/filesystem.rs12
-rw-r--r--crates/shirabe/src/util/forgejo.rs9
-rw-r--r--crates/shirabe/src/util/git.rs19
-rw-r--r--crates/shirabe/src/util/gitlab.rs69
-rw-r--r--crates/shirabe/src/util/http/curl_downloader.rs193
-rw-r--r--crates/shirabe/src/util/http_downloader.rs19
-rw-r--r--crates/shirabe/src/util/no_proxy_pattern.rs2
-rw-r--r--crates/shirabe/src/util/perforce.rs57
-rw-r--r--crates/shirabe/src/util/platform.rs4
-rw-r--r--crates/shirabe/src/util/process_executor.rs34
-rw-r--r--crates/shirabe/src/util/remote_filesystem.rs26
-rw-r--r--crates/shirabe/src/util/stream_context_factory.rs62
-rw-r--r--crates/shirabe/src/util/svn.rs6
101 files changed, 1296 insertions, 2285 deletions
diff --git a/crates/shirabe-class-map-generator/src/class_map_generator.rs b/crates/shirabe-class-map-generator/src/class_map_generator.rs
index 45ee7d9..1ba9d86 100644
--- a/crates/shirabe-class-map-generator/src/class_map_generator.rs
+++ b/crates/shirabe-class-map-generator/src/class_map_generator.rs
@@ -77,9 +77,9 @@ impl ClassMapGenerator {
if !in_array(
PhpMixed::String(autoload_type.to_string()),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("psr-0".to_string())),
- Box::new(PhpMixed::String("psr-4".to_string())),
- Box::new(PhpMixed::String("classmap".to_string())),
+ PhpMixed::String("psr-0".to_string()),
+ PhpMixed::String("psr-4".to_string()),
+ PhpMixed::String("classmap".to_string()),
]),
true,
) {
@@ -161,7 +161,7 @@ impl ClassMapGenerator {
&PhpMixed::List(
self.extensions
.iter()
- .map(|e| Box::new(PhpMixed::String(e.clone())))
+ .map(|e| PhpMixed::String(e.clone()))
.collect(),
),
true,
diff --git a/crates/shirabe-external-packages/src/symfony/console/cursor.rs b/crates/shirabe-external-packages/src/symfony/console/cursor.rs
index 8f12efe..9b031ab 100644
--- a/crates/shirabe-external-packages/src/symfony/console/cursor.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/cursor.rs
@@ -196,19 +196,19 @@ impl Cursor {
"echo 1 >/dev/null",
&vec![
shirabe_php_shim::PhpMixed::List(vec![
- Box::new(shirabe_php_shim::PhpMixed::String("file".to_string())),
- Box::new(shirabe_php_shim::PhpMixed::String("/dev/tty".to_string())),
- Box::new(shirabe_php_shim::PhpMixed::String("r".to_string())),
+ shirabe_php_shim::PhpMixed::String("file".to_string()),
+ shirabe_php_shim::PhpMixed::String("/dev/tty".to_string()),
+ shirabe_php_shim::PhpMixed::String("r".to_string()),
]),
shirabe_php_shim::PhpMixed::List(vec![
- Box::new(shirabe_php_shim::PhpMixed::String("file".to_string())),
- Box::new(shirabe_php_shim::PhpMixed::String("/dev/tty".to_string())),
- Box::new(shirabe_php_shim::PhpMixed::String("w".to_string())),
+ shirabe_php_shim::PhpMixed::String("file".to_string()),
+ shirabe_php_shim::PhpMixed::String("/dev/tty".to_string()),
+ shirabe_php_shim::PhpMixed::String("w".to_string()),
]),
shirabe_php_shim::PhpMixed::List(vec![
- Box::new(shirabe_php_shim::PhpMixed::String("file".to_string())),
- Box::new(shirabe_php_shim::PhpMixed::String("/dev/tty".to_string())),
- Box::new(shirabe_php_shim::PhpMixed::String("w".to_string())),
+ shirabe_php_shim::PhpMixed::String("file".to_string()),
+ shirabe_php_shim::PhpMixed::String("/dev/tty".to_string()),
+ shirabe_php_shim::PhpMixed::String("w".to_string()),
]),
],
&mut pipes,
diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/application_description.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/application_description.rs
index d30e6ad..33f6a8e 100644
--- a/crates/shirabe-external-packages/src/symfony/console/descriptor/application_description.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/application_description.rs
@@ -136,12 +136,7 @@ impl ApplicationDescription {
entry.insert("id".to_string(), PhpMixed::String(namespace.clone()));
entry.insert(
"commands".to_string(),
- PhpMixed::List(
- names
- .into_iter()
- .map(|n| Box::new(PhpMixed::String(n)))
- .collect(),
- ),
+ PhpMixed::List(names.into_iter().map(PhpMixed::String).collect()),
);
self.namespaces.as_mut().unwrap().insert(namespace, entry);
}
diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs
index 9068a0a..381ee69 100644
--- a/crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/json_descriptor.rs
@@ -75,7 +75,7 @@ impl JsonDescriptor {
};
let mut description =
ApplicationDescription::new(application.clone(), described_namespace.clone(), true);
- let mut commands: Vec<Box<PhpMixed>> = vec![];
+ let mut commands: Vec<PhpMixed> = vec![];
let short = matches!(options.get("short"), Some(PhpMixed::Bool(true)));
let command_list: Vec<_> = description
@@ -84,25 +84,24 @@ impl JsonDescriptor {
.map(|c| c.borrow().clone_box())
.collect();
for mut command in command_list {
- commands.push(Box::new(PhpMixed::Array(
+ commands.push(PhpMixed::Array(
self.get_command_data(command.as_mut(), short)?
.into_iter()
- .map(|(k, v)| (k, Box::new(v)))
.collect(),
- )));
+ ));
}
let mut data: IndexMap<String, PhpMixed> = IndexMap::new();
if "UNKNOWN" != application.borrow().get_name() {
- let mut application_data: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
+ let mut application_data: IndexMap<String, PhpMixed> = IndexMap::new();
application_data.insert(
"name".to_string(),
- Box::new(PhpMixed::String(application.borrow().get_name())),
+ PhpMixed::String(application.borrow().get_name()),
);
if "UNKNOWN" != application.borrow().get_version() {
application_data.insert(
"version".to_string(),
- Box::new(PhpMixed::String(application.borrow().get_version())),
+ PhpMixed::String(application.borrow().get_version()),
);
}
data.insert("application".to_string(), PhpMixed::Array(application_data));
@@ -122,11 +121,7 @@ impl JsonDescriptor {
description
.get_namespaces()
.into_values()
- .map(|ns| {
- Box::new(PhpMixed::Array(
- ns.into_iter().map(|(k, v)| (k, Box::new(v))).collect(),
- ))
- })
+ .map(|ns| PhpMixed::Array(ns.into_iter().collect()))
.collect(),
),
);
@@ -148,11 +143,8 @@ impl JsonDescriptor {
};
self.write(
- &shirabe_php_shim::json_encode_ex(
- &PhpMixed::Array(data.into_iter().map(|(k, v)| (k, Box::new(v))).collect()),
- flags,
- )
- .unwrap_or_default(),
+ &shirabe_php_shim::json_encode_ex(&PhpMixed::Array(data.into_iter().collect()), flags)
+ .unwrap_or_default(),
false,
);
Ok(())
@@ -258,39 +250,36 @@ impl JsonDescriptor {
&self,
definition: &InputDefinition,
) -> anyhow::Result<IndexMap<String, PhpMixed>> {
- let mut input_arguments: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
+ let mut input_arguments: IndexMap<String, PhpMixed> = IndexMap::new();
for (name, argument) in definition.get_arguments() {
input_arguments.insert(
name.clone(),
- Box::new(PhpMixed::Array(
+ PhpMixed::Array(
self.get_input_argument_data(argument)?
.into_iter()
- .map(|(k, v)| (k, Box::new(v)))
.collect(),
- )),
+ ),
);
}
- let mut input_options: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
+ let mut input_options: IndexMap<String, PhpMixed> = IndexMap::new();
for (name, option) in definition.get_options() {
input_options.insert(
name.clone(),
- Box::new(PhpMixed::Array(
+ PhpMixed::Array(
self.get_input_option_data(option, false)?
.into_iter()
- .map(|(k, v)| (k, Box::new(v)))
.collect(),
- )),
+ ),
);
if option.is_negatable() {
input_options.insert(
format!("no-{}", name),
- Box::new(PhpMixed::Array(
+ PhpMixed::Array(
self.get_input_option_data(option, true)?
.into_iter()
- .map(|(k, v)| (k, Box::new(v)))
.collect(),
- )),
+ ),
);
}
}
@@ -326,26 +315,16 @@ impl JsonDescriptor {
command
.get_aliases()
.into_iter()
- .map(|a| Box::new(PhpMixed::String(a)))
+ .map(PhpMixed::String)
.collect(),
),
);
} else {
command.merge_application_definition(false);
- let mut usage = vec![Box::new(PhpMixed::String(command.get_synopsis(false)))];
- usage.extend(
- command
- .get_usages()
- .into_iter()
- .map(|u| Box::new(PhpMixed::String(u))),
- );
- usage.extend(
- command
- .get_aliases()
- .into_iter()
- .map(|a| Box::new(PhpMixed::String(a))),
- );
+ let mut usage = vec![PhpMixed::String(command.get_synopsis(false))];
+ usage.extend(command.get_usages().into_iter().map(PhpMixed::String));
+ usage.extend(command.get_aliases().into_iter().map(PhpMixed::String));
data.insert("usage".to_string(), PhpMixed::List(usage));
data.insert(
"help".to_string(),
@@ -356,7 +335,6 @@ impl JsonDescriptor {
PhpMixed::Array(
self.get_input_definition_data(command.get_definition())?
.into_iter()
- .map(|(k, v)| (k, Box::new(v)))
.collect(),
),
);
diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs
index 6590384..421cf52 100644
--- a/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/descriptor/text_descriptor.rs
@@ -342,7 +342,7 @@ impl TextDescriptor {
for namespace in namespaces.values() {
if let Some(PhpMixed::List(ns_commands)) = namespace.get("commands") {
for c in ns_commands {
- if let PhpMixed::String(name) = c.as_ref()
+ if let PhpMixed::String(name) = c
&& command_keys.contains(name)
{
merged.push(CommandOrString::String(name.clone()));
@@ -369,7 +369,7 @@ impl TextDescriptor {
let ns_commands: Vec<String> = match namespace.get("commands") {
Some(PhpMixed::List(names)) => names
.iter()
- .filter_map(|n| match n.as_ref() {
+ .filter_map(|n| match n {
PhpMixed::String(name) if commands.contains_key(name) => {
Some(name.clone())
}
@@ -467,8 +467,8 @@ impl TextDescriptor {
PhpMixed::Array(arr) => {
let mut arr = arr.clone();
for (_key, value) in arr.iter_mut() {
- if let PhpMixed::String(s) = value.as_ref() {
- **value = PhpMixed::String(OutputFormatter::escape(s)?);
+ if let PhpMixed::String(s) = &*value {
+ *value = PhpMixed::String(OutputFormatter::escape(s)?);
}
}
PhpMixed::Array(arr)
@@ -476,8 +476,8 @@ impl TextDescriptor {
PhpMixed::List(list) => {
let mut list = list.clone();
for value in list.iter_mut() {
- if let PhpMixed::String(s) = value.as_ref() {
- **value = PhpMixed::String(OutputFormatter::escape(s)?);
+ if let PhpMixed::String(s) = &*value {
+ *value = PhpMixed::String(OutputFormatter::escape(s)?);
}
}
PhpMixed::List(list)
diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs
index 1c01d70..c36f77a 100644
--- a/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/helper/question_helper.rs
@@ -155,7 +155,7 @@ impl QuestionHelper {
if matches!(r, PhpMixed::Bool(false)) {
let is_blocked = shirabe_php_shim::stream_get_meta_data(&input_stream)
.get("blocked")
- .map(|v| (**v).clone())
+ .cloned()
.unwrap_or(PhpMixed::Bool(true));
if !shirabe_php_shim::boolval(&is_blocked) {
@@ -236,23 +236,20 @@ impl QuestionHelper {
if !choice_question.is_multiselect() {
return choices
.get(&default.to_string())
- .map(|v| (**v).clone())
+ .cloned()
.unwrap_or(default);
}
let default_parts = shirabe_php_shim::explode(",", &default.to_string());
- let mut resolved: indexmap::IndexMap<String, Box<PhpMixed>> = indexmap::IndexMap::new();
+ let mut resolved: indexmap::IndexMap<String, PhpMixed> = indexmap::IndexMap::new();
for (k, v) in default_parts.iter().enumerate() {
let v = if question.is_trimmable() {
shirabe_php_shim::trim(v, None)
} else {
v.clone()
};
- let value = choices
- .get(&v)
- .map(|value| (**value).clone())
- .unwrap_or(PhpMixed::String(v));
- resolved.insert(k.to_string(), Box::new(value));
+ let value = choices.get(&v).cloned().unwrap_or(PhpMixed::String(v));
+ resolved.insert(k.to_string(), value);
}
return PhpMixed::Array(resolved);
@@ -306,7 +303,7 @@ impl QuestionHelper {
messages.push(format!(
" [<{tag}>{}{padding}</{tag}>] {}",
PhpMixed::String(key.clone()),
- (**value).clone(),
+ value.clone(),
));
}
@@ -849,7 +846,7 @@ impl QuestionHelper {
let stream_meta_data = shirabe_php_shim::stream_get_meta_data(input_stream);
let seekable = stream_meta_data
.get("seekable")
- .map(|v| (**v).clone())
+ .cloned()
.unwrap_or(PhpMixed::Bool(false));
let mode = stream_meta_data
.get("mode")
diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs
index 618398b..c1d8455 100644
--- a/crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/helper/symfony_question_helper.rs
@@ -92,7 +92,7 @@ impl SymfonyQuestionHelper {
OutputFormatter::escape(
&choices
.get(&default.to_string())
- .map(|v| (**v).clone())
+ .cloned()
.unwrap_or(default.clone())
.to_string(),
)
diff --git a/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs b/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs
index d3df9aa..d7ddafc 100644
--- a/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs
@@ -211,7 +211,7 @@ impl ArgvInput {
if self.inner.definition.has_argument(&PhpMixed::Int(c)) {
let arg = self.inner.definition.get_argument(&PhpMixed::Int(c))?;
let value = if arg.is_array() {
- PhpMixed::List(vec![Box::new(PhpMixed::String(token.to_string()))])
+ PhpMixed::List(vec![PhpMixed::String(token.to_string())])
} else {
PhpMixed::String(token.to_string())
};
@@ -229,7 +229,7 @@ impl ArgvInput {
{
let arg = self.inner.definition.get_argument(&PhpMixed::Int(c - 1))?;
if let Some(PhpMixed::List(list)) = self.inner.arguments.get_mut(arg.get_name()) {
- list.push(Box::new(PhpMixed::String(token.to_string())));
+ list.push(PhpMixed::String(token.to_string()));
}
// unexpected argument
@@ -390,12 +390,12 @@ impl ArgvInput {
if option.is_array() {
match self.inner.options.get_mut(name) {
Some(PhpMixed::List(list)) => {
- list.push(Box::new(value));
+ list.push(value);
}
_ => {
self.inner
.options
- .insert(name.to_string(), PhpMixed::List(vec![Box::new(value)]));
+ .insert(name.to_string(), PhpMixed::List(vec![value]));
}
}
} else {
diff --git a/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs b/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs
index cad26e8..3fc9abb 100644
--- a/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs
@@ -378,8 +378,8 @@ impl InputInterface for ArrayInput {
/// PHP `(array) $values` cast: a string becomes a single-element array.
fn to_array(values: PhpMixed) -> Vec<PhpMixed> {
match values {
- PhpMixed::List(list) => list.into_iter().map(|v| *v).collect(),
- PhpMixed::Array(array) => array.into_iter().map(|(_, v)| *v).collect(),
+ PhpMixed::List(list) => list.into_iter().collect(),
+ PhpMixed::Array(array) => array.into_iter().map(|(_, v)| v).collect(),
PhpMixed::Null => vec![],
other => vec![other],
}
diff --git a/crates/shirabe-external-packages/src/symfony/console/input/input_option.rs b/crates/shirabe-external-packages/src/symfony/console/input/input_option.rs
index a90bff0..bd93f49 100644
--- a/crates/shirabe-external-packages/src/symfony/console/input/input_option.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/input/input_option.rs
@@ -52,7 +52,7 @@ impl InputOption {
let parts: Vec<String> = arr
.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-external-packages/src/symfony/console/question/choice_question.rs b/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs
index e1368e5..64f0687 100644
--- a/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs
@@ -10,7 +10,7 @@ use shirabe_php_shim::PhpMixed;
#[derive(Debug)]
pub struct ChoiceQuestion {
inner: Question,
- choices: IndexMap<String, Box<PhpMixed>>,
+ choices: IndexMap<String, PhpMixed>,
multiselect: bool,
prompt: String,
error_message: String,
@@ -22,7 +22,7 @@ impl ChoiceQuestion {
/// `$default` The default answer to return.
pub fn new(
question: String,
- choices: IndexMap<String, Box<PhpMixed>>,
+ choices: IndexMap<String, PhpMixed>,
default: Option<PhpMixed>,
) -> Result<Self, LogicException> {
if choices.is_empty() {
@@ -44,14 +44,14 @@ impl ChoiceQuestion {
this.inner.set_validator(Some(validator));
// setAutocompleterValues never throws for an array argument.
this.inner
- .set_autocompleter_values(Some(PhpMixed::Array(choices)))
+ .set_autocompleter_values(Some(PhpMixed::Array(choices.clone())))
.expect("autocompleter cannot be set on a hidden question during construction");
Ok(this)
}
/// Returns available choices.
- pub fn get_choices(&self) -> &IndexMap<String, Box<PhpMixed>> {
+ pub fn get_choices(&self) -> &IndexMap<String, PhpMixed> {
&self.choices
}
@@ -151,7 +151,7 @@ impl ChoiceQuestion {
for value in &selected_choices {
let mut results: Vec<String> = Vec::new();
for (key, choice) in &choices {
- if (**choice) == *value {
+ if (*choice) == *value {
results.push(key.clone());
}
}
@@ -178,10 +178,10 @@ impl ChoiceQuestion {
if !is_assoc {
if let Some(found_key) = &result_key {
// $result = $choices[$result];
- result = (*choices[found_key]).clone();
+ result = choices[found_key].clone();
} else if let Some(found) = choices.get(&shirabe_php_shim::strval(value)) {
// isset($choices[$value])
- result = (**found).clone();
+ result = found.clone();
} else {
result = PhpMixed::Bool(false);
}
@@ -218,13 +218,11 @@ impl ChoiceQuestion {
}
if multiselect {
- return Ok(PhpMixed::List(
- multiselect_choices.into_iter().map(Box::new).collect(),
- ));
+ return Ok(PhpMixed::List(multiselect_choices));
}
Ok(shirabe_php_shim::current(PhpMixed::List(
- multiselect_choices.into_iter().map(Box::new).collect(),
+ multiselect_choices,
)))
})
}
@@ -232,7 +230,7 @@ impl ChoiceQuestion {
/// array_search operates over the choice values as strings; this projects the
/// choices map's values into the string-keyed form the shim expects.
-fn choices_as_str(choices: &IndexMap<String, Box<PhpMixed>>) -> IndexMap<String, String> {
+fn choices_as_str(choices: &IndexMap<String, PhpMixed>) -> IndexMap<String, String> {
choices
.iter()
.map(|(k, v)| (k.clone(), shirabe_php_shim::strval(v)))
diff --git a/crates/shirabe-external-packages/src/symfony/console/question/question.rs b/crates/shirabe-external-packages/src/symfony/console/question/question.rs
index 78ae9b2..9ec3aef 100644
--- a/crates/shirabe-external-packages/src/symfony/console/question/question.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/question/question.rs
@@ -133,13 +133,13 @@ impl Question {
// array_merge(array_keys($values), array_values($values))
let mut merged: Vec<PhpMixed> =
array.keys().map(|k| PhpMixed::String(k.clone())).collect();
- merged.extend(array.values().map(|v| (**v).clone()));
+ merged.extend(array.values().map(|v| v.clone()));
merged
} else {
// array_values($values)
match &values {
- PhpMixed::List(list) => list.iter().map(|v| (**v).clone()).collect(),
- PhpMixed::Array(array) => array.values().map(|v| (**v).clone()).collect(),
+ PhpMixed::List(list) => list.iter().cloned().collect(),
+ PhpMixed::Array(array) => array.values().map(|v| v.clone()).collect(),
_ => unreachable!(),
}
};
@@ -154,8 +154,8 @@ impl Question {
// Non-array iterables are not modeled by PhpMixed; extract any
// list/array elements, otherwise treat as an empty iterator.
let cached: Vec<PhpMixed> = match values {
- PhpMixed::List(list) => list.into_iter().map(|v| *v).collect(),
- PhpMixed::Array(array) => array.into_values().map(|v| *v).collect(),
+ PhpMixed::List(list) => list.into_iter().collect(),
+ PhpMixed::Array(array) => array.into_values().map(|v| v).collect(),
_ => Vec::new(),
};
Some(Box::new(move |_input: &str| Some(cached.clone())))
diff --git a/crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs b/crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs
index 3a04885..ce08f45 100644
--- a/crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/style/symfony_style.rs
@@ -99,12 +99,7 @@ impl SymfonyStyle {
self.auto_prepend_block();
let block = self.create_block(messages, r#type, style, prefix, padding, escape);
self.writeln(
- PhpMixed::List(
- block
- .into_iter()
- .map(|line| Box::new(PhpMixed::String(line)))
- .collect(),
- ),
+ PhpMixed::List(block.into_iter().map(PhpMixed::String).collect()),
OUTPUT_NORMAL,
);
self.new_line(1);
@@ -181,10 +176,7 @@ impl SymfonyStyle {
row.push(shirabe_php_shim::current(value));
}
- self.horizontal_table(
- headers,
- vec![PhpMixed::List(row.into_iter().map(Box::new).collect())],
- );
+ self.horizontal_table(headers, vec![PhpMixed::List(row.into_iter().collect())]);
}
pub fn progress_iterate(
@@ -506,11 +498,11 @@ impl StyleInterface for SymfonyStyle {
self.auto_prepend_block();
self.writeln(
PhpMixed::List(vec![
- Box::new(PhpMixed::String(format!(
+ PhpMixed::String(format!(
"<comment>{}</>",
PhpMixed::String(OutputFormatter::escape_trailing_backslash(message),),
- ))),
- Box::new(PhpMixed::String(format!(
+ )),
+ PhpMixed::String(format!(
"<comment>{}</>",
PhpMixed::String(shirabe_php_shim::str_repeat(
"=",
@@ -519,7 +511,7 @@ impl StyleInterface for SymfonyStyle {
message,
)) as usize,
)),
- ))),
+ )),
]),
OUTPUT_NORMAL,
);
@@ -531,11 +523,11 @@ impl StyleInterface for SymfonyStyle {
self.auto_prepend_block();
self.writeln(
PhpMixed::List(vec![
- Box::new(PhpMixed::String(format!(
+ PhpMixed::String(format!(
"<comment>{}</>",
PhpMixed::String(OutputFormatter::escape_trailing_backslash(message),),
- ))),
- Box::new(PhpMixed::String(format!(
+ )),
+ PhpMixed::String(format!(
"<comment>{}</>",
PhpMixed::String(shirabe_php_shim::str_repeat(
"-",
@@ -544,7 +536,7 @@ impl StyleInterface for SymfonyStyle {
message,
)) as usize,
)),
- ))),
+ )),
]),
OUTPUT_NORMAL,
);
@@ -560,7 +552,7 @@ impl StyleInterface for SymfonyStyle {
);
self.writeln(
- PhpMixed::List(elements.into_iter().map(Box::new).collect()),
+ PhpMixed::List(elements.into_iter().collect()),
OUTPUT_NORMAL,
);
self.new_line(1);
@@ -698,9 +690,8 @@ impl StyleInterface for SymfonyStyle {
default: Option<PhpMixed>,
) -> PhpMixed {
let default = if let Some(default) = default {
- let values = shirabe_php_shim::array_flip(&PhpMixed::List(
- choices.iter().cloned().map(Box::new).collect(),
- ));
+ let values =
+ shirabe_php_shim::array_flip(&PhpMixed::List(choices.iter().cloned().collect()));
// $default = $values[$default] ?? $default;
let _ = values;
Some(default)
@@ -710,10 +701,10 @@ impl StyleInterface for SymfonyStyle {
// PHP: return $this->askQuestion(new ChoiceQuestion($question, $choices, $default));
// ChoiceQuestion extends Question; see `confirm` for the polymorphism note.
- let choices_map: indexmap::IndexMap<String, Box<PhpMixed>> = choices
+ let choices_map: indexmap::IndexMap<String, PhpMixed> = choices
.into_iter()
.enumerate()
- .map(|(i, c)| (i.to_string(), Box::new(c)))
+ .map(|(i, c)| (i.to_string(), c))
.collect();
let _choice_question = ChoiceQuestion::new(question.to_string(), choices_map, default);
self.ask_question(todo!())
diff --git a/crates/shirabe-external-packages/src/symfony/console/terminal.rs b/crates/shirabe-external-packages/src/symfony/console/terminal.rs
index 9ac1f9e..377d344 100644
--- a/crates/shirabe-external-packages/src/symfony/console/terminal.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/terminal.rs
@@ -210,12 +210,12 @@ impl Terminal {
let descriptorspec: Vec<PhpMixed> = vec![
PhpMixed::List(vec![
- Box::new(PhpMixed::String("pipe".to_string())),
- Box::new(PhpMixed::String("w".to_string())),
+ PhpMixed::String("pipe".to_string()),
+ PhpMixed::String("w".to_string()),
]),
PhpMixed::List(vec![
- Box::new(PhpMixed::String("pipe".to_string())),
- Box::new(PhpMixed::String("w".to_string())),
+ PhpMixed::String("pipe".to_string()),
+ PhpMixed::String("w".to_string()),
]),
];
@@ -248,13 +248,10 @@ impl Terminal {
/// Indexes into the `$pipes` array populated by proc_open.
fn php_pipe(pipes: &PhpMixed, index: i64) -> PhpMixed {
match pipes {
- PhpMixed::List(list) => list
- .get(index as usize)
- .map(|v| (**v).clone())
- .unwrap_or(PhpMixed::Null),
+ PhpMixed::List(list) => list.get(index as usize).cloned().unwrap_or(PhpMixed::Null),
PhpMixed::Array(array) => array
.get(&index.to_string())
- .map(|v| (**v).clone())
+ .map(|v| v.clone())
.unwrap_or(PhpMixed::Null),
_ => PhpMixed::Null,
}
diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs
index aa80f53..fc425e7 100644
--- a/crates/shirabe-php-shim/src/lib.rs
+++ b/crates/shirabe-php-shim/src/lib.rs
@@ -14,8 +14,8 @@ pub enum PhpMixed {
Int(i64),
Float(f64),
String(String),
- List(Vec<Box<PhpMixed>>),
- Array(IndexMap<String, Box<PhpMixed>>),
+ List(Vec<PhpMixed>),
+ Array(IndexMap<String, PhpMixed>),
Object(ArrayObject),
}
@@ -126,28 +126,28 @@ impl PhpMixed {
}
}
- pub fn as_list(&self) -> Option<&Vec<Box<PhpMixed>>> {
+ pub fn as_list(&self) -> Option<&Vec<PhpMixed>> {
match self {
PhpMixed::List(l) => Some(l),
_ => None,
}
}
- pub fn as_array(&self) -> Option<&IndexMap<String, Box<PhpMixed>>> {
+ pub fn as_array(&self) -> Option<&IndexMap<String, PhpMixed>> {
match self {
PhpMixed::Array(a) => Some(a),
_ => None,
}
}
- pub fn as_array_mut(&mut self) -> Option<&mut IndexMap<String, Box<PhpMixed>>> {
+ pub fn as_array_mut(&mut self) -> Option<&mut IndexMap<String, PhpMixed>> {
match self {
PhpMixed::Array(a) => Some(a),
_ => None,
}
}
- pub fn as_list_mut(&mut self) -> Option<&mut Vec<Box<PhpMixed>>> {
+ pub fn as_list_mut(&mut self) -> Option<&mut Vec<PhpMixed>> {
match self {
PhpMixed::List(l) => Some(l),
_ => None,
@@ -171,7 +171,7 @@ impl PhpMixed {
}
pub fn get(&self, key: &str) -> Option<&PhpMixed> {
- self.as_array().and_then(|m| m.get(key).map(|v| v.as_ref()))
+ self.as_array().and_then(|m| m.get(key))
}
/// Treats PhpMixed::Null as None, everything else as Some.
@@ -275,12 +275,7 @@ where
T: Into<PhpMixed>,
{
fn from(value: IndexMap<String, T>) -> Self {
- PhpMixed::Array(
- value
- .into_iter()
- .map(|(k, v)| (k, Box::new(v.into())))
- .collect(),
- )
+ PhpMixed::Array(value.into_iter().map(|(k, v)| (k, v.into())).collect())
}
}
@@ -289,7 +284,7 @@ where
T: Into<PhpMixed>,
{
fn from(value: Vec<T>) -> Self {
- PhpMixed::List(value.into_iter().map(|v| Box::new(v.into())).collect())
+ PhpMixed::List(value.into_iter().map(|v| v.into()).collect())
}
}
@@ -689,7 +684,7 @@ pub fn pack(_format: &str, _values: &[PhpMixed]) -> Vec<u8> {
todo!()
}
-pub fn unpack(_format: &str, _data: &[u8]) -> Option<IndexMap<String, Box<PhpMixed>>> {
+pub fn unpack(_format: &str, _data: &[u8]) -> Option<IndexMap<String, PhpMixed>> {
todo!()
}
@@ -985,7 +980,7 @@ impl ZipArchive {
todo!()
}
- pub fn stat_index(&self, _index: i64) -> Option<IndexMap<String, Box<PhpMixed>>> {
+ pub fn stat_index(&self, _index: i64) -> Option<IndexMap<String, PhpMixed>> {
todo!()
}
@@ -1046,8 +1041,8 @@ pub trait JsonSerializable {
pub fn in_array(needle: PhpMixed, haystack: &PhpMixed, strict: bool) -> bool {
let values: Vec<&PhpMixed> = match haystack {
- PhpMixed::List(items) => items.iter().map(|item| item.as_ref()).collect(),
- PhpMixed::Array(map) => map.values().map(|item| item.as_ref()).collect(),
+ PhpMixed::List(items) => items.iter().collect(),
+ PhpMixed::Array(map) => map.values().collect(),
_ => return false,
};
@@ -1206,7 +1201,7 @@ pub fn substr_count(_haystack: &str, _needle: &str) -> i64 {
pub fn openssl_x509_parse(
_certificate: &str,
_short_names: bool,
-) -> Option<IndexMap<String, Box<PhpMixed>>> {
+) -> Option<IndexMap<String, PhpMixed>> {
todo!()
}
@@ -1214,7 +1209,7 @@ pub fn openssl_get_publickey(_certificate: &str) -> Option<PhpMixed> {
todo!()
}
-pub fn openssl_pkey_get_details(_key: PhpMixed) -> Option<IndexMap<String, Box<PhpMixed>>> {
+pub fn openssl_pkey_get_details(_key: PhpMixed) -> Option<IndexMap<String, PhpMixed>> {
todo!()
}
@@ -1284,7 +1279,7 @@ pub fn include_file(file: &str) -> PhpMixed {
// TODO(php-runtime): the callback should be registered in PHP runtime.
pub fn set_error_handler(_callback: fn(i64, &str, &str, i64) -> bool) {}
-pub fn debug_backtrace() -> Vec<IndexMap<String, Box<PhpMixed>>> {
+pub fn debug_backtrace() -> Vec<IndexMap<String, PhpMixed>> {
todo!()
}
@@ -1586,7 +1581,7 @@ pub struct CurlMultiHandle;
#[derive(Debug)]
pub struct CurlShareHandle;
-pub fn curl_version() -> Option<IndexMap<String, Box<PhpMixed>>> {
+pub fn curl_version() -> Option<IndexMap<String, PhpMixed>> {
todo!()
}
@@ -1930,15 +1925,14 @@ fn array_replace_recursive_value(base: PhpMixed, replacement: PhpMixed) -> PhpMi
}
fn array_replace_recursive_assoc(
- mut base: IndexMap<String, Box<PhpMixed>>,
- replacement: IndexMap<String, Box<PhpMixed>>,
-) -> IndexMap<String, Box<PhpMixed>> {
+ mut base: IndexMap<String, PhpMixed>,
+ replacement: IndexMap<String, PhpMixed>,
+) -> IndexMap<String, PhpMixed> {
for (key, replacement_value) in replacement {
let merged = match base.get(&key) {
- Some(base_value) => Box::new(array_replace_recursive_value(
- (**base_value).clone(),
- *replacement_value,
- )),
+ Some(base_value) => {
+ array_replace_recursive_value(base_value.clone(), replacement_value)
+ }
None => replacement_value,
};
base.insert(key, merged);
@@ -1947,13 +1941,12 @@ fn array_replace_recursive_assoc(
}
fn array_replace_recursive_list(
- mut base: Vec<Box<PhpMixed>>,
- replacement: Vec<Box<PhpMixed>>,
-) -> Vec<Box<PhpMixed>> {
+ mut base: Vec<PhpMixed>,
+ replacement: Vec<PhpMixed>,
+) -> Vec<PhpMixed> {
for (index, replacement_value) in replacement.into_iter().enumerate() {
if index < base.len() {
- *base[index] =
- array_replace_recursive_value((*base[index]).clone(), *replacement_value);
+ base[index] = array_replace_recursive_value(base[index].clone(), replacement_value);
} else {
base.push(replacement_value);
}
@@ -2019,18 +2012,20 @@ fn json_value_to_php_mixed(value: serde_json::Value, assoc: bool) -> PhpMixed {
serde_json::Value::Array(items) => PhpMixed::List(
items
.into_iter()
- .map(|item| Box::new(json_value_to_php_mixed(item, assoc)))
+ .map(|item| json_value_to_php_mixed(item, assoc))
.collect(),
),
serde_json::Value::Object(entries) => {
- let data: IndexMap<String, Box<PhpMixed>> = entries
+ let data: IndexMap<String, PhpMixed> = entries
.into_iter()
- .map(|(k, v)| (k, Box::new(json_value_to_php_mixed(v, assoc))))
+ .map(|(k, v)| (k, json_value_to_php_mixed(v, assoc)))
.collect();
if assoc {
PhpMixed::Array(data)
} else {
- PhpMixed::Object(ArrayObject { data })
+ PhpMixed::Object(ArrayObject {
+ data: data.into_iter().collect(),
+ })
}
}
}
@@ -2306,7 +2301,7 @@ where
}
pub fn array_filter_map<F>(
- _array: &IndexMap<String, Box<PhpMixed>>,
+ _array: &IndexMap<String, PhpMixed>,
_callback: F,
) -> IndexMap<String, PhpMixed>
where
@@ -2314,8 +2309,8 @@ where
{
_array
.iter()
- .filter(|(_, v)| _callback(v.as_ref()))
- .map(|(k, v)| (k.clone(), v.as_ref().clone()))
+ .filter(|&(_, v)| _callback(v))
+ .map(|(k, v)| (k.clone(), v.clone()))
.collect()
}
@@ -2604,7 +2599,7 @@ pub fn php_strip_whitespace(_path: &str) -> String {
}
// The shim does not raise PHP-level errors, so there is never a last error.
-pub fn error_get_last() -> Option<IndexMap<String, Box<PhpMixed>>> {
+pub fn error_get_last() -> Option<IndexMap<String, PhpMixed>> {
None
}
@@ -2856,7 +2851,7 @@ pub fn fread(_handle: PhpMixed, _length: i64) -> Option<String> {
todo!()
}
-pub fn lstat(_filename: &str) -> Option<IndexMap<String, Box<PhpMixed>>> {
+pub fn lstat(_filename: &str) -> Option<IndexMap<String, PhpMixed>> {
todo!()
}
@@ -2926,7 +2921,7 @@ pub const PHP_WINDOWS_VERSION_BUILD: i64 = 0;
#[derive(Debug, Clone)]
pub struct ArrayObject {
- data: IndexMap<String, Box<PhpMixed>>,
+ data: IndexMap<String, PhpMixed>,
}
impl ArrayObject {
@@ -2934,7 +2929,7 @@ impl ArrayObject {
todo!()
}
- pub fn to_array(&self) -> IndexMap<String, Box<PhpMixed>> {
+ pub fn to_array(&self) -> IndexMap<String, PhpMixed> {
self.data.clone()
}
@@ -2945,12 +2940,12 @@ impl ArrayObject {
#[derive(Debug)]
pub struct JsonObject {
- data: IndexMap<String, Box<PhpMixed>>,
+ data: IndexMap<String, PhpMixed>,
}
#[derive(Debug)]
pub struct StdClass {
- pub data: IndexMap<String, Box<PhpMixed>>,
+ pub data: IndexMap<String, PhpMixed>,
}
#[derive(Debug, Clone)]
@@ -3020,7 +3015,7 @@ pub const PHP_OS: &str = match std::env::consts::OS.as_bytes() {
pub fn instance_of<T>(_value: &PhpMixed) -> bool {
todo!()
}
-pub fn to_array(_value: PhpMixed) -> IndexMap<String, Box<PhpMixed>> {
+pub fn to_array(_value: PhpMixed) -> IndexMap<String, PhpMixed> {
todo!()
}
pub fn to_string(_value: &PhpMixed) -> String {
@@ -3219,7 +3214,7 @@ pub fn fgetc(_resource: &PhpResource) -> Option<String> {
pub fn ftell(_resource: &PhpResource) -> i64 {
todo!()
}
-pub fn stream_get_meta_data(_resource: &PhpResource) -> IndexMap<String, Box<PhpMixed>> {
+pub fn stream_get_meta_data(_resource: &PhpResource) -> IndexMap<String, PhpMixed> {
todo!()
}
pub fn stream_set_blocking(_resource: &PhpResource, _enable: bool) -> bool {
@@ -3359,7 +3354,7 @@ pub fn directory_iterator(_path: &str) -> Vec<DirectoryIteratorEntry> {
todo!()
}
-pub fn array_key_last(_array: &IndexMap<String, Box<PhpMixed>>) -> usize {
+pub fn array_key_last(_array: &IndexMap<String, PhpMixed>) -> usize {
todo!()
}
pub fn array_splice_mixed(
diff --git a/crates/shirabe/src/advisory/audit_config.rs b/crates/shirabe/src/advisory/audit_config.rs
index bcd0763..28e5e68 100644
--- a/crates/shirabe/src/advisory/audit_config.rs
+++ b/crates/shirabe/src/advisory/audit_config.rs
@@ -82,7 +82,7 @@ impl AuditConfig {
};
for (key, value) in entries {
- let (id, apply, reason) = match value.as_ref() {
+ let (id, apply, reason) = match value {
PhpMixed::String(reason_str) => {
(key.clone(), "all".to_string(), Some(reason_str.clone()))
}
@@ -136,21 +136,21 @@ impl AuditConfig {
let ignore_raw = audit_config
.and_then(|m| m.get("ignore"))
- .map(|v| *v.clone())
+ .cloned()
.unwrap_or_else(|| empty_array.clone());
let (ignore_list_for_audit, ignore_list_for_blocking) =
Self::parse_ignore_with_apply(&ignore_raw)?;
let ignore_abandoned_raw = audit_config
.and_then(|m| m.get("ignore-abandoned"))
- .map(|v| *v.clone())
+ .cloned()
.unwrap_or_else(|| empty_array.clone());
let (ignore_abandoned_for_audit, ignore_abandoned_for_blocking) =
Self::parse_ignore_with_apply(&ignore_abandoned_raw)?;
let ignore_severity_raw = audit_config
.and_then(|m| m.get("ignore-severity"))
- .map(|v| *v.clone())
+ .cloned()
.unwrap_or_else(|| empty_array.clone());
let (ignore_severity_for_audit, ignore_severity_for_blocking) =
Self::parse_ignore_with_apply(&ignore_severity_raw)?;
diff --git a/crates/shirabe/src/advisory/auditor.rs b/crates/shirabe/src/advisory/auditor.rs
index 5a41b30..411e83e 100644
--- a/crates/shirabe/src/advisory/auditor.rs
+++ b/crates/shirabe/src/advisory/auditor.rs
@@ -468,11 +468,7 @@ impl Auditor {
.set_horizontal(true)
.set_headers(headers.into_iter().map(|h| h.into()).collect());
table.add_row(ConsoleIO::sanitize(
- PhpMixed::List(
- row.into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
- ),
+ PhpMixed::List(row.into_iter().map(PhpMixed::String).collect()),
false,
))??;
table
@@ -595,10 +591,8 @@ impl Auditor {
};
table.add_row(ConsoleIO::sanitize(
PhpMixed::List(vec![
- Box::new(PhpMixed::String(
- self.get_package_name_with_link(pkg.clone().into()),
- )),
- Box::new(PhpMixed::String(replacement)),
+ PhpMixed::String(self.get_package_name_with_link(pkg.clone().into())),
+ PhpMixed::String(replacement),
]),
false,
));
diff --git a/crates/shirabe/src/autoload/autoload_generator.rs b/crates/shirabe/src/autoload/autoload_generator.rs
index c69cd34..7b02841 100644
--- a/crates/shirabe/src/autoload/autoload_generator.rs
+++ b/crates/shirabe/src/autoload/autoload_generator.rs
@@ -242,7 +242,7 @@ impl AutoloadGenerator {
PhpMixed::List(
dev_package_names
.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
+ .map(|s| PhpMixed::String(s.clone()))
.collect(),
)
} else {
@@ -379,7 +379,7 @@ impl AutoloadGenerator {
.unwrap_or_default();
for (namespace, paths) in &map {
let mut entry: IndexMap<String, PhpMixed> = IndexMap::new();
- entry.insert("paths".to_string(), (**paths).clone());
+ entry.insert("paths".to_string(), paths.clone());
entry.insert("type".to_string(), PhpMixed::String(psr_type.to_string()));
namespaces_to_scan
.entry(namespace.clone())
@@ -1405,7 +1405,7 @@ impl AutoloadGenerator {
let map = shirabe_php_shim::php_require(&format!("{}/autoload_namespaces.php", target_dir));
if let Some(map_arr) = map.as_array() {
for (namespace, path) in map_arr {
- let paths: Vec<String> = if let PhpMixed::List(items) = (**path).clone() {
+ let paths: Vec<String> = if let PhpMixed::List(items) = path.clone() {
items
.iter()
.map(|i| i.as_string().unwrap_or("").to_string())
@@ -1420,7 +1420,7 @@ impl AutoloadGenerator {
let map = shirabe_php_shim::php_require(&format!("{}/autoload_psr4.php", target_dir));
if let Some(map_arr) = map.as_array() {
for (namespace, path) in map_arr {
- let paths: Vec<String> = if let PhpMixed::List(items) = (**path).clone() {
+ let paths: Vec<String> = if let PhpMixed::List(items) = path.clone() {
items
.iter()
.map(|i| i.as_string().unwrap_or("").to_string())
@@ -1613,8 +1613,8 @@ impl AutoloadGenerator {
package_map: &Vec<(PackageInterfaceHandle, Option<String>)>,
r#type: &str,
root_package: RootPackageInterfaceHandle,
- ) -> IndexMap<String, Box<PhpMixed>> {
- let mut autoloads: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
+ ) -> IndexMap<String, PhpMixed> {
+ let mut autoloads: IndexMap<String, PhpMixed> = IndexMap::new();
let mut numeric_index: i64 = 0;
for item in package_map {
@@ -1630,22 +1630,11 @@ impl AutoloadGenerator {
let is_root = package.ptr_eq(&root_package.clone().into());
if self.dev_mode.unwrap_or(false) && is_root {
let merged = array_merge_recursive(vec![
- PhpMixed::Array(
- autoload
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
- PhpMixed::Array(
- root_package
- .get_dev_autoload()
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
+ PhpMixed::Array(autoload.into_iter().collect()),
+ PhpMixed::Array(root_package.get_dev_autoload().into_iter().collect()),
]);
autoload = match merged {
- PhpMixed::Array(m) => m.into_iter().map(|(k, v)| (k, *v)).collect(),
+ PhpMixed::Array(m) => m.into_iter().collect(),
_ => IndexMap::new(),
};
}
@@ -1673,9 +1662,9 @@ impl AutoloadGenerator {
namespace
};
// PHP: foreach ((array) $paths as $path) — handles scalar by wrapping in an array
- let path_list: Vec<PhpMixed> = match paths.as_ref() {
- PhpMixed::List(l) => l.iter().map(|b| (**b).clone()).collect(),
- PhpMixed::Array(a) => a.values().map(|b| (**b).clone()).collect(),
+ let path_list: Vec<PhpMixed> = match &paths {
+ PhpMixed::List(l) => l.iter().cloned().collect(),
+ PhpMixed::Array(a) => a.values().cloned().collect(),
other => vec![other.clone()],
};
for path in path_list {
@@ -1774,8 +1763,7 @@ impl AutoloadGenerator {
preg_quote(&strtr(&resolved_path, "\\", "/"), None),
p
);
- autoloads
- .insert(numeric_index.to_string(), Box::new(PhpMixed::String(entry)));
+ autoloads.insert(numeric_index.to_string(), PhpMixed::String(entry));
numeric_index += 1;
continue;
}
@@ -1793,15 +1781,13 @@ impl AutoloadGenerator {
if r#type == "files" {
autoloads.insert(
self.get_file_identifier(package.clone(), &path_str),
- Box::new(PhpMixed::String(relative_path)),
+ PhpMixed::String(relative_path),
);
continue;
}
if r#type == "classmap" {
- autoloads.insert(
- numeric_index.to_string(),
- Box::new(PhpMixed::String(relative_path)),
- );
+ autoloads
+ .insert(numeric_index.to_string(), PhpMixed::String(relative_path));
numeric_index += 1;
continue;
}
@@ -1809,9 +1795,9 @@ impl AutoloadGenerator {
// psr-0/psr-4: append to namespace's list
let entry = autoloads
.entry(namespace.clone())
- .or_insert_with(|| Box::new(PhpMixed::List(vec![])));
- if let PhpMixed::List(l) = entry.as_mut() {
- l.push(Box::new(PhpMixed::String(relative_path)));
+ .or_insert_with(|| PhpMixed::List(vec![]));
+ if let PhpMixed::List(l) = entry {
+ l.push(PhpMixed::String(relative_path));
}
}
}
diff --git a/crates/shirabe/src/autoload/class_loader.rs b/crates/shirabe/src/autoload/class_loader.rs
index 918b319..b19e618 100644
--- a/crates/shirabe/src/autoload/class_loader.rs
+++ b/crates/shirabe/src/autoload/class_loader.rs
@@ -495,11 +495,7 @@ impl ClassLoader {
pub fn as_array_iter(&self) -> Vec<(String, PhpMixed)> {
let key = |name: &str| format!("\0Composer\\Autoload\\ClassLoader\0{}", name);
let str_list = |v: &Vec<String>| {
- PhpMixed::List(
- v.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
- .collect(),
- )
+ PhpMixed::List(v.iter().map(|s| PhpMixed::String(s.clone())).collect())
};
vec![
@@ -518,12 +514,12 @@ impl ClassLoader {
.map(|(k, inner)| {
(
k.clone(),
- Box::new(PhpMixed::Array(
+ PhpMixed::Array(
inner
.iter()
- .map(|(k2, n)| (k2.clone(), Box::new(PhpMixed::Int(*n))))
+ .map(|(k2, n)| (k2.clone(), PhpMixed::Int(*n)))
.collect(),
- )),
+ ),
)
})
.collect(),
@@ -534,7 +530,7 @@ impl ClassLoader {
PhpMixed::Array(
self.prefix_dirs_psr4
.iter()
- .map(|(k, v)| (k.clone(), Box::new(str_list(v))))
+ .map(|(k, v)| (k.clone(), str_list(v)))
.collect(),
),
),
@@ -547,12 +543,12 @@ impl ClassLoader {
.map(|(k, inner)| {
(
k.clone(),
- Box::new(PhpMixed::Array(
+ PhpMixed::Array(
inner
.iter()
- .map(|(k2, v)| (k2.clone(), Box::new(str_list(v))))
+ .map(|(k2, v)| (k2.clone(), str_list(v)))
.collect(),
- )),
+ ),
)
})
.collect(),
@@ -565,7 +561,7 @@ impl ClassLoader {
PhpMixed::Array(
self.class_map
.iter()
- .map(|(k, v)| (k.clone(), Box::new(PhpMixed::String(v.clone()))))
+ .map(|(k, v)| (k.clone(), PhpMixed::String(v.clone())))
.collect(),
),
),
@@ -578,7 +574,7 @@ impl ClassLoader {
PhpMixed::Array(
self.missing_classes
.iter()
- .map(|(k, b)| (k.clone(), Box::new(PhpMixed::Bool(*b))))
+ .map(|(k, b)| (k.clone(), PhpMixed::Bool(*b)))
.collect(),
),
),
diff --git a/crates/shirabe/src/command/base_command.rs b/crates/shirabe/src/command/base_command.rs
index c6b5550..40253d4 100644
--- a/crates/shirabe/src/command/base_command.rs
+++ b/crates/shirabe/src/command/base_command.rs
@@ -613,9 +613,9 @@ impl BaseCommand for BaseCommandData {
}
let val = input.borrow().get_option(opt_name)?;
- let formats: Vec<Box<PhpMixed>> = Auditor::FORMATS
+ let formats: Vec<PhpMixed> = Auditor::FORMATS
.iter()
- .map(|s| Box::new(PhpMixed::String(s.to_string())))
+ .map(|s| PhpMixed::String(s.to_string()))
.collect();
if !in_array(val.clone(), &PhpMixed::List(formats), true) {
return Err(InvalidArgumentException {
@@ -824,7 +824,7 @@ pub fn base_command_initialize(
PhpMixed::List(
explode(",", &ignore_str)
.into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
+ .map(PhpMixed::String)
.collect(),
),
);
diff --git a/crates/shirabe/src/command/base_config_command.rs b/crates/shirabe/src/command/base_config_command.rs
index 00098f2..01952f6 100644
--- a/crates/shirabe/src/command/base_config_command.rs
+++ b/crates/shirabe/src/command/base_config_command.rs
@@ -89,10 +89,7 @@ pub trait BaseConfigCommand: BaseCommand {
.borrow()
.write(PhpMixed::Array({
let mut m = IndexMap::new();
- m.insert(
- "config".to_string(),
- Box::new(PhpMixed::Array(IndexMap::new())),
- );
+ m.insert("config".to_string(), PhpMixed::Array(IndexMap::new()));
m
}))?;
let _ = Silencer::call(|| {
diff --git a/crates/shirabe/src/command/base_dependency_command.rs b/crates/shirabe/src/command/base_dependency_command.rs
index 98a2622..6a892e8 100644
--- a/crates/shirabe/src/command/base_dependency_command.rs
+++ b/crates/shirabe/src/command/base_dependency_command.rs
@@ -111,7 +111,6 @@ pub trait BaseDependencyCommand: BaseCommand {
.cloned()
.unwrap_or_default()
.into_iter()
- .map(|(k, v)| (k, *v))
.collect();
repos.push(crate::repository::RepositoryInterfaceHandle::new(
PlatformRepository::new(vec![], platform_overrides)?,
@@ -379,13 +378,7 @@ pub trait BaseDependencyCommand: BaseCommand {
}
let table_as_mixed: Vec<PhpMixed> = table
.into_iter()
- .map(|row| {
- PhpMixed::List(
- row.into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
- )
- })
+ .map(|row| PhpMixed::List(row.into_iter().map(PhpMixed::String).collect()))
.collect();
self.render_table(table_as_mixed, output);
}
diff --git a/crates/shirabe/src/command/bump_command.rs b/crates/shirabe/src/command/bump_command.rs
index 1d5a81d..17605d6 100644
--- a/crates/shirabe/src/command/bump_command.rs
+++ b/crates/shirabe/src/command/bump_command.rs
@@ -242,9 +242,9 @@ impl BumpCommand {
for (package, version) in packages {
let section = composer_definition
.entry(key.to_string())
- .or_insert_with(|| Box::new(PhpMixed::Array(indexmap::IndexMap::new())));
- if let PhpMixed::Array(map) = section.as_mut() {
- map.insert(package.clone(), Box::new(PhpMixed::String(version.clone())));
+ .or_insert_with(|| PhpMixed::Array(indexmap::IndexMap::new()));
+ if let PhpMixed::Array(map) = section {
+ map.insert(package.clone(), PhpMixed::String(version.clone()));
}
}
}
diff --git a/crates/shirabe/src/command/check_platform_reqs_command.rs b/crates/shirabe/src/command/check_platform_reqs_command.rs
index bfd8b99..0f18557 100644
--- a/crates/shirabe/src/command/check_platform_reqs_command.rs
+++ b/crates/shirabe/src/command/check_platform_reqs_command.rs
@@ -72,65 +72,63 @@ impl CheckPlatformReqsCommand {
let mut row = IndexMap::new();
row.insert(
"name".to_string(),
- Box::new(PhpMixed::String(result.platform_package.clone())),
+ PhpMixed::String(result.platform_package.clone()),
);
row.insert(
"version".to_string(),
- Box::new(PhpMixed::String(result.version.clone())),
+ PhpMixed::String(result.version.clone()),
);
row.insert(
"status".to_string(),
- Box::new(PhpMixed::String(strip_tags(&result.status))),
+ PhpMixed::String(strip_tags(&result.status)),
);
if let Some(link) = &result.link {
let mut failed_req = IndexMap::new();
failed_req.insert(
"source".to_string(),
- Box::new(PhpMixed::String(link.get_source().to_string())),
+ PhpMixed::String(link.get_source().to_string()),
);
failed_req.insert(
"type".to_string(),
- Box::new(PhpMixed::String(link.get_description().to_string())),
+ PhpMixed::String(link.get_description().to_string()),
);
failed_req.insert(
"target".to_string(),
- Box::new(PhpMixed::String(link.get_target().to_string())),
+ PhpMixed::String(link.get_target().to_string()),
);
failed_req.insert(
"constraint".to_string(),
- Box::new(PhpMixed::String(link.get_pretty_constraint().to_string())),
+ PhpMixed::String(link.get_pretty_constraint().to_string()),
);
row.insert(
"failed_requirement".to_string(),
- Box::new(PhpMixed::Array(failed_req)),
+ PhpMixed::Array(failed_req),
);
} else {
- row.insert("failed_requirement".to_string(), Box::new(PhpMixed::Null));
+ row.insert("failed_requirement".to_string(), PhpMixed::Null);
}
let provider_str = strip_tags(&result.provider);
row.insert(
"provider".to_string(),
- Box::new(if provider_str.is_empty() {
+ if provider_str.is_empty() {
PhpMixed::Null
} else {
PhpMixed::String(provider_str)
- }),
+ },
);
PhpMixed::Array(row)
})
.collect();
- io.write(&JsonFile::encode(&PhpMixed::List(
- rows.into_iter().map(Box::new).collect(),
- )));
+ io.write(&JsonFile::encode(&PhpMixed::List(rows)));
} else {
let rows: Vec<PhpMixed> = results
.iter()
.map(|result| {
PhpMixed::List(vec![
- Box::new(PhpMixed::String(result.platform_package.clone())),
- Box::new(PhpMixed::String(result.version.clone())),
- Box::new(if let Some(link) = &result.link {
+ PhpMixed::String(result.platform_package.clone()),
+ PhpMixed::String(result.version.clone()),
+ if let Some(link) = &result.link {
PhpMixed::String(format!(
"{} {} {} ({})",
link.get_source(),
@@ -140,12 +138,12 @@ impl CheckPlatformReqsCommand {
))
} else {
PhpMixed::String(String::new())
- }),
- Box::new(PhpMixed::String(
+ },
+ PhpMixed::String(
format!("{} {}", result.status, result.provider)
.trim_end()
.to_string(),
- )),
+ ),
])
})
.collect();
diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs
index 556dbdd..f6dffb7 100644
--- a/crates/shirabe/src/command/config_command.rs
+++ b/crates/shirabe/src/command/config_command.rs
@@ -178,7 +178,7 @@ impl Command for ConfigCommand {
&& !self.auth_config_file.as_ref().unwrap().borrow().exists()
{
touch(self.auth_config_file.as_ref().unwrap().borrow().get_path());
- let mut empty_objs: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
+ let mut empty_objs: IndexMap<String, PhpMixed> = IndexMap::new();
for k in &[
"bitbucket-oauth",
"github-oauth",
@@ -188,10 +188,7 @@ impl Command for ConfigCommand {
"bearer",
"forgejo-token",
] {
- empty_objs.insert(
- k.to_string(),
- Box::new(PhpMixed::Object(ArrayObject::new(None))),
- );
+ empty_objs.insert(k.to_string(), PhpMixed::Object(ArrayObject::new(None)));
}
self.auth_config_file
.as_ref()
@@ -274,10 +271,7 @@ impl Command for ConfigCommand {
if input.borrow().get_option("global")?.as_bool() != Some(true) {
let config_read = self.config_file.as_ref().unwrap().borrow_mut().read()?;
let config_map = match config_read {
- PhpMixed::Array(m) => m
- .into_iter()
- .map(|(k, v)| (k, *v))
- .collect::<IndexMap<String, PhpMixed>>(),
+ PhpMixed::Array(m) => m,
_ => IndexMap::new(),
};
self.config.as_mut().unwrap().borrow_mut().merge(
@@ -313,7 +307,7 @@ impl Command for ConfigCommand {
let all_map = self.config.as_ref().unwrap().borrow_mut().all(0)?;
let raw_map = self.config.as_ref().unwrap().borrow().raw();
let to_mixed = |m: IndexMap<String, PhpMixed>| -> PhpMixed {
- PhpMixed::Array(m.into_iter().map(|(k, v)| (k, Box::new(v))).collect())
+ PhpMixed::Array(m.into_iter().collect())
};
self.list_configuration(
to_mixed(all_map),
@@ -399,7 +393,7 @@ impl Command for ConfigCommand {
.as_ref()
.and_then(|r| r.as_array().and_then(|a| a.get(&repo_key)))
{
- Some(v) => (**v).clone(),
+ Some(v) => v.clone(),
None => {
return Err(InvalidArgumentException {
message: format!("There is no {} repository defined", repo_key),
@@ -430,7 +424,7 @@ impl Command for ConfigCommand {
&& let Some(v) = arr.get(&new_key)
{
r#match = true;
- cursor = (**v).clone();
+ cursor = v.clone();
key_acc = None;
}
}
@@ -478,11 +472,11 @@ impl Command for ConfigCommand {
.and_then(|a| a.get(&setting_key))
.and_then(|v| v.as_array())
.and_then(|a| a.get("type"))
- .map(|v| (**v).clone());
+ .cloned();
if let Some(tv) = type_value {
let type_array = match &tv {
PhpMixed::List(_) | PhpMixed::Array(_) => tv,
- other => PhpMixed::List(vec![Box::new(other.clone())]),
+ other => PhpMixed::List(vec![other.clone()]),
};
let type_strings: Vec<String> = type_array
.as_list()
@@ -503,7 +497,12 @@ impl Command for ConfigCommand {
.is_some()
&& in_array(setting_key.as_str().into(), &properties.into(), true)
{
- value = (**raw_data.as_array().unwrap().get(&setting_key).unwrap()).clone();
+ value = raw_data
+ .as_array()
+ .unwrap()
+ .get(&setting_key)
+ .unwrap()
+ .clone();
source = self
.config_file
.as_ref()
@@ -744,15 +743,9 @@ impl Command for ConfigCommand {
}
if 2 == values.len() {
- let mut repo: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- repo.insert(
- "type".to_string(),
- Box::new(PhpMixed::String(values[0].clone())),
- );
- repo.insert(
- "url".to_string(),
- Box::new(PhpMixed::String(values[1].clone())),
- );
+ let mut repo: IndexMap<String, PhpMixed> = IndexMap::new();
+ repo.insert("type".to_string(), PhpMixed::String(values[0].clone()));
+ repo.insert("url".to_string(), PhpMixed::String(values[1].clone()));
self.config_source.as_mut().unwrap().add_repository(
&matches[1],
PhpMixed::Array(repo),
@@ -820,7 +813,7 @@ impl Command for ConfigCommand {
current_value = current_value
.as_array()
.and_then(|a| a.get(bit))
- .map(|v| (**v).clone())
+ .cloned()
.unwrap_or(PhpMixed::Null);
}
if is_array(&current_value) && is_array(&value) {
@@ -833,7 +826,7 @@ impl Command for ConfigCommand {
);
} else {
// PHP "+" operator on arrays: keep keys from left, fill from right
- let mut merged: IndexMap<String, Box<PhpMixed>> =
+ let mut merged: IndexMap<String, PhpMixed> =
value.as_array().cloned().unwrap_or_default();
if let Some(cv) = current_value.as_array() {
for (k, v) in cv {
@@ -945,12 +938,8 @@ impl Command for ConfigCommand {
return Ok(0);
}
- let mut value: PhpMixed = PhpMixed::List(
- values
- .iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
- .collect(),
- );
+ let mut value: PhpMixed =
+ PhpMixed::List(values.iter().map(|s| PhpMixed::String(s.clone())).collect());
if input.borrow().get_option("json")?.as_bool() == Some(true) {
value = JsonFile::parse_json(Some(&values[0]), Some("composer.json"))?;
if !is_array(&value) {
@@ -972,7 +961,7 @@ impl Command for ConfigCommand {
.and_then(|a| a.get("audit"))
.and_then(|v| v.as_array())
.and_then(|a| a.get(&key_suffix))
- .map(|v| (**v).clone())
+ .cloned()
.unwrap_or(PhpMixed::Null);
if !current_value.is_null() && is_array(&current_value) && is_array(&value) {
@@ -984,7 +973,7 @@ impl Command for ConfigCommand {
);
} else if !array_is_list(&current_value) && !array_is_list(&value) {
// Both are associative arrays (objects), merge them
- let mut merged: IndexMap<String, Box<PhpMixed>> =
+ let mut merged: IndexMap<String, PhpMixed> =
value.as_array().cloned().unwrap_or_default();
if let Some(cv) = current_value.as_array() {
for (k, v) in cv {
@@ -1048,14 +1037,14 @@ impl Command for ConfigCommand {
.as_mut()
.unwrap()
.remove_config_setting(&key);
- let mut obj: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
+ let mut obj: IndexMap<String, PhpMixed> = IndexMap::new();
obj.insert(
"consumer-key".to_string(),
- Box::new(PhpMixed::String(values[0].clone())),
+ PhpMixed::String(values[0].clone()),
);
obj.insert(
"consumer-secret".to_string(),
- Box::new(PhpMixed::String(values[1].clone())),
+ PhpMixed::String(values[1].clone()),
);
self.auth_config_source
.as_mut()
@@ -1066,15 +1055,9 @@ impl Command for ConfigCommand {
.as_mut()
.unwrap()
.remove_config_setting(&key);
- let mut obj: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- obj.insert(
- "username".to_string(),
- Box::new(PhpMixed::String(values[0].clone())),
- );
- obj.insert(
- "token".to_string(),
- Box::new(PhpMixed::String(values[1].clone())),
- );
+ let mut obj: IndexMap<String, PhpMixed> = IndexMap::new();
+ obj.insert("username".to_string(), PhpMixed::String(values[0].clone()));
+ obj.insert("token".to_string(), PhpMixed::String(values[1].clone()));
self.auth_config_source
.as_mut()
.unwrap()
@@ -1120,15 +1103,9 @@ impl Command for ConfigCommand {
.as_mut()
.unwrap()
.remove_config_setting(&key);
- let mut obj: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- obj.insert(
- "username".to_string(),
- Box::new(PhpMixed::String(values[0].clone())),
- );
- obj.insert(
- "password".to_string(),
- Box::new(PhpMixed::String(values[1].clone())),
- );
+ let mut obj: IndexMap<String, PhpMixed> = IndexMap::new();
+ obj.insert("username".to_string(), PhpMixed::String(values[0].clone()));
+ obj.insert("password".to_string(), PhpMixed::String(values[1].clone()));
self.auth_config_source
.as_mut()
.unwrap()
@@ -1143,7 +1120,7 @@ impl Command for ConfigCommand {
}
// Validate headers format
- let mut formatted_headers: Vec<Box<PhpMixed>> = vec![];
+ let mut formatted_headers: Vec<PhpMixed> = vec![];
for header in &values {
if !is_string(&PhpMixed::String(header.clone())) {
return Err(RuntimeException {
@@ -1168,7 +1145,7 @@ impl Command for ConfigCommand {
.into());
}
- formatted_headers.push(Box::new(PhpMixed::String(header.clone())));
+ formatted_headers.push(PhpMixed::String(header.clone()));
}
self.config_source
@@ -1194,15 +1171,9 @@ impl Command for ConfigCommand {
.as_mut()
.unwrap()
.remove_config_setting(&key);
- let mut obj: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- obj.insert(
- "username".to_string(),
- Box::new(PhpMixed::String(values[0].clone())),
- );
- obj.insert(
- "token".to_string(),
- Box::new(PhpMixed::String(values[1].clone())),
- );
+ let mut obj: IndexMap<String, PhpMixed> = IndexMap::new();
+ obj.insert("username".to_string(), PhpMixed::String(values[0].clone()));
+ obj.insert("token".to_string(), PhpMixed::String(values[1].clone()));
self.auth_config_source
.as_mut()
.unwrap()
@@ -1225,12 +1196,7 @@ impl Command for ConfigCommand {
}
let value: PhpMixed = if values.len() > 1 {
- PhpMixed::List(
- values
- .iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
- .collect(),
- )
+ PhpMixed::List(values.iter().map(|s| PhpMixed::String(s.clone())).collect())
} else {
PhpMixed::String(values[0].clone())
};
@@ -1354,12 +1320,8 @@ impl ConfigCommand {
method: &str,
) -> anyhow::Result<()> {
let (validator, normalizer) = callbacks;
- let values_mixed = PhpMixed::List(
- values
- .iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
- .collect(),
- );
+ let values_mixed =
+ PhpMixed::List(values.iter().map(|s| PhpMixed::String(s.clone())).collect());
let validation = validator(&values_mixed);
if validation.as_bool() != Some(true) {
let suffix = if !validation.is_null() && validation.as_bool() != Some(false) {
@@ -1413,12 +1375,9 @@ impl ConfigCommand {
continue;
}
- let raw_val = raw_contents_arr
- .get(key)
- .map(|v| (**v).clone())
- .unwrap_or(PhpMixed::Null);
+ let raw_val = raw_contents_arr.get(key).cloned().unwrap_or(PhpMixed::Null);
- let value_inner = (**value).clone();
+ let value_inner = value.clone();
if is_array(&value_inner)
&& (!is_numeric(&key_first_key(&value_inner).unwrap_or_default().into())
@@ -2177,7 +2136,7 @@ fn flatten_setting_keys(config: PhpMixed, prefix: &str) -> Vec<String> {
// sub-keys of repository-keys must not be added to completion
if is_array(value) && !array_is_list(value) && prefix != "repositories." {
keys.push(flatten_setting_keys(
- (**value).clone(),
+ value.clone(),
&format!("{}{}.", prefix, key),
));
}
diff --git a/crates/shirabe/src/command/create_project_command.rs b/crates/shirabe/src/command/create_project_command.rs
index 3322008..c3c82d4 100644
--- a/crates/shirabe/src/command/create_project_command.rs
+++ b/crates/shirabe/src/command/create_project_command.rs
@@ -410,7 +410,7 @@ impl CreateProjectCommand {
PhpMixed::Array(
repo_config
.iter()
- .map(|(k, v)| (k.clone(), Box::new(v.clone())))
+ .map(|(k, v)| (k.clone(), v.clone()))
.collect(),
),
false,
@@ -698,9 +698,8 @@ impl CreateProjectCommand {
config.borrow_mut().set_base_dir(Some(directory.clone()));
if !secure_http {
let mut merge_map: indexmap::IndexMap<String, PhpMixed> = indexmap::IndexMap::new();
- let mut inner_map: indexmap::IndexMap<String, Box<PhpMixed>> =
- indexmap::IndexMap::new();
- inner_map.insert("secure-http".to_string(), Box::new(PhpMixed::Bool(false)));
+ let mut inner_map: indexmap::IndexMap<String, PhpMixed> = indexmap::IndexMap::new();
+ inner_map.insert("secure-http".to_string(), PhpMixed::Bool(false));
merge_map.insert("config".to_string(), PhpMixed::Array(inner_map));
config
.borrow_mut()
@@ -843,7 +842,7 @@ impl CreateProjectCommand {
.entry("options".to_string())
.or_insert(PhpMixed::Array(indexmap::IndexMap::new()));
if let PhpMixed::Array(options_map) = options_entry {
- options_map.insert("symlink".to_string(), Box::new(PhpMixed::Bool(false)));
+ options_map.insert("symlink".to_string(), PhpMixed::Bool(false));
}
}
diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs
index 7f1aec5..739adad 100644
--- a/crates/shirabe/src/command/diagnose_command.rs
+++ b/crates/shirabe/src/command/diagnose_command.rs
@@ -144,8 +144,8 @@ impl Command for DiagnoseCommand {
ProcessExecutor::new(Some(io.clone())),
)));
}
- let mut config_inner: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- config_inner.insert("secure-http".to_string(), Box::new(PhpMixed::Bool(false)));
+ let mut config_inner = IndexMap::new();
+ config_inner.insert("secure-http".to_string(), PhpMixed::Bool(false));
let mut secure_http_wrap: IndexMap<String, PhpMixed> = IndexMap::new();
secure_http_wrap.insert("config".to_string(), PhpMixed::Array(config_inner));
let mut config = config;
@@ -187,10 +187,8 @@ impl Command for DiagnoseCommand {
.as_array()
.cloned()
.unwrap_or_default();
- let platform_overrides_unboxed: indexmap::IndexMap<String, PhpMixed> = platform_overrides
- .into_iter()
- .map(|(k, v)| (k, *v))
- .collect();
+ let platform_overrides_unboxed: indexmap::IndexMap<String, PhpMixed> =
+ platform_overrides.into_iter().collect();
let mut platform_repo =
PlatformRepository::new(vec![], platform_overrides_unboxed).unwrap();
let php_pkg = <PlatformRepository as crate::repository::RepositoryInterface>::find_package(
@@ -318,7 +316,7 @@ impl Command for DiagnoseCommand {
{
let repo_arr_unboxed: indexmap::IndexMap<String, PhpMixed> = repo_arr
.iter()
- .map(|(k, v)| (k.clone(), (**v).clone()))
+ .map(|(k, v)| (k.clone(), v.clone()))
.collect();
let composer_repo = ComposerRepository::new(
repo_arr_unboxed,
@@ -555,7 +553,7 @@ impl DiagnoseCommand {
return Ok(result);
}
- let mut result_list: Vec<Box<PhpMixed>> = vec![];
+ let mut result_list: Vec<PhpMixed> = vec![];
let mut tls_warning: Option<String> = None;
if proto == "https" && config.get("disable-tls").as_bool() == Some(true) {
tls_warning = Some("<warning>Composer is configured to disable SSL/TLS protection. This will leave remote HTTPS requests vulnerable to Man-In-The-Middle attacks.</warning>".to_string());
@@ -571,15 +569,15 @@ impl DiagnoseCommand {
let hints = HttpDownloader::get_exception_hints(&e).unwrap_or_default();
if !hints.is_empty() {
for hint in hints {
- result_list.push(Box::new(PhpMixed::String(hint)));
+ result_list.push(PhpMixed::String(hint));
}
}
- result_list.push(Box::new(PhpMixed::String(format!(
+ result_list.push(PhpMixed::String(format!(
"<error>[{}] {}</error>",
std::any::type_name_of_val(te),
te.message
- ))));
+ )));
} else {
return Err(e);
}
@@ -587,7 +585,7 @@ impl DiagnoseCommand {
}
if let Some(w) = tls_warning {
- result_list.push(Box::new(PhpMixed::String(w)));
+ result_list.push(PhpMixed::String(w));
}
if !result_list.is_empty() {
@@ -603,7 +601,7 @@ impl DiagnoseCommand {
return Ok(result);
}
- let mut result_list: Vec<Box<PhpMixed>> = vec![];
+ let mut result_list: Vec<PhpMixed> = vec![];
let mut tls_warning: Option<String> = None;
if str_starts_with(url, "https://") && config.get("disable-tls").as_bool() == Some(true) {
tls_warning = Some("<warning>Composer is configured to disable SSL/TLS protection. This will leave remote HTTPS requests vulnerable to Man-In-The-Middle attacks.</warning>".to_string());
@@ -622,15 +620,15 @@ impl DiagnoseCommand {
let hints = HttpDownloader::get_exception_hints(&e).unwrap_or_default();
if !hints.is_empty() {
for hint in hints {
- result_list.push(Box::new(PhpMixed::String(hint)));
+ result_list.push(PhpMixed::String(hint));
}
}
- result_list.push(Box::new(PhpMixed::String(format!(
+ result_list.push(PhpMixed::String(format!(
"<error>[{}] {}</error>",
std::any::type_name_of_val(te),
te.message
- ))));
+ )));
} else {
return Err(e);
}
@@ -638,7 +636,7 @@ impl DiagnoseCommand {
}
if let Some(w) = tls_warning {
- result_list.push(Box::new(PhpMixed::String(w)));
+ result_list.push(PhpMixed::String(w));
}
if !result_list.is_empty() {
@@ -682,12 +680,12 @@ impl DiagnoseCommand {
let first = provider_includes_arr
.values()
.next()
- .map(|v| (**v).clone())
+ .map(|v| v.clone())
.unwrap_or(PhpMixed::Null);
let hash_val = first
.as_array()
.and_then(|a| a.get("sha256"))
- .map(|v| (**v).clone())
+ .map(|v| v.clone())
.unwrap_or(PhpMixed::Null);
let path = str_replace(
"%hash%",
@@ -816,7 +814,7 @@ impl DiagnoseCommand {
.and_then(|a| a.get("resources"))
.and_then(|v| v.as_array())
.and_then(|a| a.get("core"))
- .map(|v| (**v).clone())
+ .map(|v| v.clone())
.unwrap_or(PhpMixed::Null))
}
@@ -848,7 +846,7 @@ impl DiagnoseCommand {
fn check_pub_keys(&mut self, config: &Config) -> anyhow::Result<PhpMixed> {
let home = config.get("home").as_string().unwrap_or("").to_string();
- let mut errors: Vec<Box<PhpMixed>> = vec![];
+ let mut errors: Vec<PhpMixed> = vec![];
let io = self.get_io();
if file_exists(&format!("{}/keys.tags.pub", home))
@@ -863,9 +861,9 @@ impl DiagnoseCommand {
Keys::fingerprint(&format!("{}/keys.tags.pub", home))?
));
} else {
- errors.push(Box::new(PhpMixed::String(
+ errors.push(PhpMixed::String(
"<error>Missing pubkey for tags verification</error>".to_string(),
- )));
+ ));
}
if file_exists(&format!("{}/keys.dev.pub", home)) {
@@ -874,15 +872,15 @@ impl DiagnoseCommand {
Keys::fingerprint(&format!("{}/keys.dev.pub", home))?
));
} else {
- errors.push(Box::new(PhpMixed::String(
+ errors.push(PhpMixed::String(
"<error>Missing pubkey for dev verification</error>".to_string(),
- )));
+ ));
}
if !errors.is_empty() {
- errors.push(Box::new(PhpMixed::String(
+ errors.push(PhpMixed::String(
"<error>Run composer self-update --update-keys to set them up</error>".to_string(),
- )));
+ ));
}
Ok(if !errors.is_empty() {
@@ -1109,7 +1107,7 @@ impl DiagnoseCommand {
had_error = true;
} else {
let result_list: Vec<PhpMixed> = match &result {
- PhpMixed::List(l) => l.iter().map(|b| (**b).clone()).collect(),
+ PhpMixed::List(l) => l.clone(),
other => vec![other.clone()],
};
for message in &result_list {
@@ -1121,7 +1119,7 @@ impl DiagnoseCommand {
}
}
// re-wrap so the final output loop works the same
- result = PhpMixed::List(result_list.into_iter().map(Box::new).collect());
+ result = PhpMixed::List(result_list);
}
if had_error {
diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs
index d7beaf8..f58952e 100644
--- a/crates/shirabe/src/command/init_command.rs
+++ b/crates/shirabe/src/command/init_command.rs
@@ -137,12 +137,11 @@ impl Command for InitCommand {
"license".to_string(),
"autoload".to_string(),
];
- let filtered_input: IndexMap<String, Box<PhpMixed>> = array_intersect_key(
+ let filtered_input: IndexMap<String, PhpMixed> = array_intersect_key(
&input.borrow().get_options(),
&array_flip_strings(&allowlist),
)
.into_iter()
- .map(|(k, v)| (k, Box::new(v)))
.collect();
let mut options = shirabe_php_shim::array_filter_map(&filtered_input, |val: &PhpMixed| {
!matches!(val, PhpMixed::Null) && !matches!(val, PhpMixed::List(l) if l.is_empty())
@@ -178,11 +177,7 @@ impl Command for InitCommand {
PhpMixed::List(
self.format_authors(&author)?
.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(),
),
);
@@ -211,12 +206,7 @@ impl Command for InitCommand {
.entry("repositories".to_string())
.or_insert_with(|| PhpMixed::List(vec![]));
if let PhpMixed::List(list) = entry {
- list.push(Box::new(PhpMixed::Array(
- repo_config
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- )));
+ list.push(PhpMixed::Array(repo_config.into_iter().collect()));
}
}
}
@@ -244,7 +234,7 @@ impl Command for InitCommand {
PhpMixed::Array(
formatted
.into_iter()
- .map(|(k, v)| (k, Box::new(PhpMixed::String(v))))
+ .map(|(k, v)| (k, PhpMixed::String(v)))
.collect(),
)
}
@@ -271,7 +261,7 @@ impl Command for InitCommand {
PhpMixed::Array(
formatted
.into_iter()
- .map(|(k, v)| (k, Box::new(PhpMixed::String(v))))
+ .map(|(k, v)| (k, PhpMixed::String(v)))
.collect(),
)
};
@@ -294,19 +284,15 @@ impl Command for InitCommand {
.unwrap_or("")
.to_string();
let namespace = self.namespace_from_package_name(&name).unwrap_or_default();
- let mut psr4: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- psr4.insert(format!("{}\\", namespace), Box::new(PhpMixed::String(ap)));
- let mut autoload_obj: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- autoload_obj.insert("psr-4".to_string(), Box::new(PhpMixed::Array(psr4)));
+ let mut psr4 = IndexMap::new();
+ psr4.insert(format!("{}\\", namespace), PhpMixed::String(ap));
+ let mut autoload_obj = IndexMap::new();
+ autoload_obj.insert("psr-4".to_string(), PhpMixed::Array(psr4));
options.insert("autoload".to_string(), PhpMixed::Array(autoload_obj));
}
let file_obj = JsonFile::new(Factory::get_composer_file()?, None, None)?;
- let options_for_encode: IndexMap<String, Box<PhpMixed>> = options
- .clone()
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect();
+ let options_for_encode: IndexMap<String, PhpMixed> = options.clone().into_iter().collect();
let json = JsonFile::encode(&PhpMixed::Array(options_for_encode.clone()));
if input.borrow().is_interactive() {
@@ -823,12 +809,7 @@ impl Command for InitCommand {
};
input.borrow_mut().set_option(
"require",
- PhpMixed::List(
- requirements
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
- ),
+ PhpMixed::List(requirements.into_iter().map(PhpMixed::String).collect()),
);
let question = "Would you like to define your dev dependencies (require-dev) interactively [<comment>yes</comment>]? ".to_string();
@@ -858,12 +839,7 @@ impl Command for InitCommand {
};
input.borrow_mut().set_option(
"require-dev",
- PhpMixed::List(
- dev_requirements
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
- ),
+ PhpMixed::List(dev_requirements.into_iter().map(PhpMixed::String).collect()),
);
// --autoload - input and validation
diff --git a/crates/shirabe/src/command/licenses_command.rs b/crates/shirabe/src/command/licenses_command.rs
index 1f054d1..46cbd02 100644
--- a/crates/shirabe/src/command/licenses_command.rs
+++ b/crates/shirabe/src/command/licenses_command.rs
@@ -226,19 +226,18 @@ impl Command for LicensesCommand {
pkg_licenses.join(", ")
};
table.add_row(PhpMixed::List(vec![
- Box::new(PhpMixed::String(name)),
- Box::new(PhpMixed::String(package.get_full_pretty_version(
+ PhpMixed::String(name),
+ PhpMixed::String(package.get_full_pretty_version(
true,
crate::package::DisplayMode::SourceRefIfDev,
- ))),
- Box::new(PhpMixed::String(licenses_str)),
+ )),
+ PhpMixed::String(licenses_str),
]));
}
table.render();
}
"json" => {
- let mut dependencies: IndexMap<String, IndexMap<String, PhpMixed>> =
- IndexMap::new();
+ let mut dependencies: IndexMap<String, PhpMixed> = IndexMap::new();
for package in &packages {
let pkg_licenses = if let Some(complete_pkg) = package.as_complete_package() {
complete_pkg.get_license()
@@ -255,14 +254,12 @@ impl Command for LicensesCommand {
);
dep_info.insert(
"license".to_string(),
- PhpMixed::List(
- pkg_licenses
- .into_iter()
- .map(|l| Box::new(PhpMixed::String(l)))
- .collect(),
- ),
+ PhpMixed::List(pkg_licenses.into_iter().map(PhpMixed::String).collect()),
+ );
+ dependencies.insert(
+ package.get_pretty_name().to_string(),
+ PhpMixed::Array(dep_info),
);
- dependencies.insert(package.get_pretty_name().to_string(), dep_info);
}
let mut output_map: IndexMap<String, PhpMixed> = IndexMap::new();
@@ -283,34 +280,11 @@ impl Command for LicensesCommand {
let root_licenses = root.get_license();
output_map.insert(
"license".to_string(),
- PhpMixed::List(
- root_licenses
- .into_iter()
- .map(|l| Box::new(PhpMixed::String(l)))
- .collect(),
- ),
- );
- output_map.insert(
- "dependencies".to_string(),
- PhpMixed::Array(
- dependencies
- .into_iter()
- .map(|(k, v)| {
- (
- k,
- Box::new(PhpMixed::Array(
- v.into_iter().map(|(k2, v2)| (k2, Box::new(v2))).collect(),
- )),
- )
- })
- .collect(),
- ),
+ PhpMixed::List(root_licenses.into_iter().map(PhpMixed::String).collect()),
);
+ output_map.insert("dependencies".to_string(), PhpMixed::Array(dependencies));
io.write(&JsonFile::encode(&PhpMixed::Array(
- output_map
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
+ output_map.into_iter().collect(),
)));
}
"summary" => {
@@ -336,8 +310,8 @@ impl Command for LicensesCommand {
.iter()
.map(|(license, count)| {
PhpMixed::List(vec![
- Box::new(PhpMixed::String(license.clone())),
- Box::new(PhpMixed::String(count.to_string())),
+ PhpMixed::String(license.clone()),
+ PhpMixed::String(count.to_string()),
])
})
.collect();
diff --git a/crates/shirabe/src/command/package_discovery_trait.rs b/crates/shirabe/src/command/package_discovery_trait.rs
index c182645..9be30f5 100644
--- a/crates/shirabe/src/command/package_discovery_trait.rs
+++ b/crates/shirabe/src/command/package_discovery_trait.rs
@@ -255,7 +255,7 @@ pub trait PackageDiscoveryTrait: BaseCommand {
&PhpMixed::List(
existing_packages
.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
+ .map(|s| PhpMixed::String(s.clone()))
.collect(),
),
true,
@@ -678,7 +678,7 @@ pub trait PackageDiscoveryTrait: BaseCommand {
&PhpMixed::List(
similar
.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
+ .map(|s| PhpMixed::String(s.clone()))
.collect(),
),
true,
diff --git a/crates/shirabe/src/command/remove_command.rs b/crates/shirabe/src/command/remove_command.rs
index c1ba536..4260369 100644
--- a/crates/shirabe/src/command/remove_command.rs
+++ b/crates/shirabe/src/command/remove_command.rs
@@ -339,7 +339,7 @@ impl Command for RemoveCommand {
.filter_map(|(k, v)| v.as_string().map(|_| (k.clone(), k.clone())))
.collect();
for (name, canonical) in entries {
- section.insert(strtolower(&name), Box::new(PhpMixed::String(canonical)));
+ section.insert(strtolower(&name), PhpMixed::String(canonical));
}
}
}
diff --git a/crates/shirabe/src/command/repository_command.rs b/crates/shirabe/src/command/repository_command.rs
index 6ea26d2..caca808 100644
--- a/crates/shirabe/src/command/repository_command.rs
+++ b/crates/shirabe/src/command/repository_command.rs
@@ -84,7 +84,7 @@ impl RepositoryCommand {
}
if !packagist_present {
let mut packagist_entry = IndexMap::new();
- packagist_entry.insert("packagist.org".to_string(), Box::new(PhpMixed::Bool(false)));
+ packagist_entry.insert("packagist.org".to_string(), PhpMixed::Bool(false));
repos.insert(repos.len().to_string(), PhpMixed::Array(packagist_entry));
}
@@ -102,7 +102,7 @@ impl RepositoryCommand {
if let PhpMixed::Array(ref repo_map) = *repo {
if repo_map.len() == 1
&& let Some(first_val) = repo_map.values().next()
- && matches!(**first_val, PhpMixed::Bool(false))
+ && matches!(*first_val, PhpMixed::Bool(false))
{
let first_key = repo_map.keys().next().unwrap();
io.write(&format!("[{}] <info>disabled</info>", first_key));
@@ -273,7 +273,7 @@ impl Command for RepositoryCommand {
.get_path()
.to_string();
let config_data_map: IndexMap<String, PhpMixed> = match config_data {
- PhpMixed::Array(m) => m.into_iter().map(|(k, v)| (k, *v)).collect(),
+ PhpMixed::Array(m) => m.into_iter().collect(),
_ => IndexMap::new(),
};
self.config
@@ -312,11 +312,8 @@ impl Command for RepositoryCommand {
}));
}
let mut m = IndexMap::new();
- m.insert(
- "type".to_string(),
- Box::new(PhpMixed::String(arg1_str.to_string())),
- );
- m.insert("url".to_string(), Box::new(PhpMixed::String(arg2.unwrap())));
+ m.insert("type".to_string(), PhpMixed::String(arg1_str.to_string()));
+ m.insert("url".to_string(), PhpMixed::String(arg2.unwrap()));
PhpMixed::Array(m)
};
diff --git a/crates/shirabe/src/command/require_command.rs b/crates/shirabe/src/command/require_command.rs
index a29f60d..f965350 100644
--- a/crates/shirabe/src/command/require_command.rs
+++ b/crates/shirabe/src/command/require_command.rs
@@ -284,7 +284,7 @@ impl Command for RequireCommand {
let platform_overrides = composer.get_config().borrow_mut().get("platform");
let platform_overrides_map: IndexMap<String, PhpMixed> = platform_overrides
.as_array()
- .map(|m| m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect())
+ .map(|m| m.iter().map(|(k, v)| (k.clone(), v.clone())).collect())
.unwrap_or_default();
// initialize self.repos as it is used by the PackageDiscoveryTrait
let platform_repo =
@@ -708,7 +708,7 @@ impl RequireCommand {
.and_then(|v| v.as_array())
{
for (k, v) in r {
- require.insert(k.clone(), (**v).clone());
+ require.insert(k.clone(), v.clone());
}
}
@@ -717,7 +717,7 @@ impl RequireCommand {
.and_then(|v| v.as_array())
{
for (k, v) in r {
- require_dev.insert(k.clone(), (**v).clone());
+ require_dev.insert(k.clone(), v.clone());
}
}
@@ -726,7 +726,7 @@ impl RequireCommand {
PhpMixed::List(
array_keys(&require)
.into_iter()
- .map(|k| Box::new(PhpMixed::String(k)))
+ .map(PhpMixed::String)
.collect(),
),
PhpMixed::String("require".to_string()),
@@ -735,7 +735,7 @@ impl RequireCommand {
PhpMixed::List(
array_keys(&require_dev)
.into_iter()
- .map(|k| Box::new(PhpMixed::String(k)))
+ .map(PhpMixed::String)
.collect(),
),
PhpMixed::String("require-dev".to_string()),
@@ -1196,16 +1196,16 @@ impl RequireCommand {
}
let composer_definition_mixed = json.borrow_mut().read().unwrap_or_default();
- let mut composer_definition: IndexMap<String, Box<PhpMixed>> = composer_definition_mixed
+ let mut composer_definition = composer_definition_mixed
.as_array()
.cloned()
.unwrap_or_default();
for (package, version) in new {
let section = composer_definition
.entry(require_key.to_string())
- .or_insert_with(|| Box::new(PhpMixed::Array(IndexMap::new())));
+ .or_insert_with(|| PhpMixed::Array(IndexMap::new()));
if let Some(section) = section.as_array_mut() {
- section.insert(package.clone(), Box::new(PhpMixed::String(version.clone())));
+ section.insert(package.clone(), PhpMixed::String(version.clone()));
}
if let Some(section) = composer_definition
.get_mut(remove_key)
diff --git a/crates/shirabe/src/command/run_script_command.rs b/crates/shirabe/src/command/run_script_command.rs
index 141b458..5a8f628 100644
--- a/crates/shirabe/src/command/run_script_command.rs
+++ b/crates/shirabe/src/command/run_script_command.rs
@@ -76,8 +76,8 @@ impl RunScriptCommand {
.iter()
.map(|(name, desc)| {
PhpMixed::List(vec![
- Box::new(PhpMixed::String(format!(" {}", name))),
- Box::new(PhpMixed::String(desc.clone())),
+ PhpMixed::String(format!(" {}", name)),
+ PhpMixed::String(desc.clone()),
])
})
.collect();
diff --git a/crates/shirabe/src/command/search_command.rs b/crates/shirabe/src/command/search_command.rs
index 19a215f..c7070dd 100644
--- a/crates/shirabe/src/command/search_command.rs
+++ b/crates/shirabe/src/command/search_command.rs
@@ -126,8 +126,8 @@ impl Command for SearchCommand {
if !in_array(
PhpMixed::String(format.clone()),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("text".to_string())),
- Box::new(PhpMixed::String("json".to_string())),
+ PhpMixed::String("text".to_string()),
+ PhpMixed::String("json".to_string()),
]),
false,
) {
diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs
index f7319ed..27ed8f1 100644
--- a/crates/shirabe/src/command/show_command.rs
+++ b/crates/shirabe/src/command/show_command.rs
@@ -202,8 +202,8 @@ impl Command for ShowCommand {
if !in_array(
PhpMixed::String(format.clone()),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("text".to_string())),
- Box::new(PhpMixed::String("json".to_string())),
+ PhpMixed::String("text".to_string()),
+ PhpMixed::String("json".to_string()),
]),
false,
) {
@@ -228,7 +228,7 @@ impl Command for ShowCommand {
.as_array()
.cloned()
{
- platform_overrides = p.into_iter().map(|(k, v)| (k, *v)).collect();
+ platform_overrides = p.into_iter().collect();
}
}
let platform_repo =
@@ -533,7 +533,7 @@ impl Command for ShowCommand {
&PhpMixed::List(
self.get_root_requires()
.into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
+ .map(PhpMixed::String)
.collect(),
),
true,
@@ -600,15 +600,10 @@ impl Command for ShowCommand {
let mut wrapper: IndexMap<String, PhpMixed> = IndexMap::new();
wrapper.insert(
"installed".to_string(),
- PhpMixed::List(vec![Box::new(PhpMixed::Array(
- array_tree
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ))]),
+ PhpMixed::List(vec![PhpMixed::Array(array_tree.into_iter().collect())]),
);
self.get_io().write(&JsonFile::encode(&PhpMixed::Array(
- wrapper.into_iter().map(|(k, v)| (k, Box::new(v))).collect(),
+ wrapper.into_iter().collect(),
)));
} else {
self.display_package_tree(vec![array_tree]);
@@ -714,7 +709,7 @@ impl Command for ShowCommand {
&PhpMixed::List(
root_requires
.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
+ .map(|s| PhpMixed::String(s.clone()))
.collect(),
),
true,
@@ -734,16 +729,12 @@ impl Command for ShowCommand {
PhpMixed::List(
array_tree
.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.get_io().write(&JsonFile::encode(&PhpMixed::Array(
- wrapper.into_iter().map(|(k, v)| (k, Box::new(v))).collect(),
+ wrapper.into_iter().collect(),
)));
} else {
self.display_package_tree(array_tree);
@@ -829,9 +820,7 @@ impl Command for ShowCommand {
Some(list) => in_array(
PhpMixed::String(p.get_name()),
&PhpMixed::List(
- list.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
- .collect(),
+ list.iter().map(|s| PhpMixed::String(s.clone())).collect(),
),
true,
),
@@ -997,7 +986,7 @@ impl Command for ShowCommand {
&PhpMixed::List(
self.get_root_requires()
.into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
+ .map(PhpMixed::String)
.collect(),
),
true,
@@ -1192,11 +1181,9 @@ impl Command for ShowCommand {
PhpMixed::List(
v.iter()
.map(|m| {
- Box::new(PhpMixed::Array(
- m.iter()
- .map(|(k, v)| (k.clone(), Box::new(v.clone())))
- .collect(),
- ))
+ PhpMixed::Array(
+ m.iter().map(|(k, v)| (k.clone(), v.clone())).collect(),
+ )
})
.collect(),
),
@@ -1204,10 +1191,7 @@ impl Command for ShowCommand {
}
let io = self.get_io();
io.write(&JsonFile::encode(&PhpMixed::Array(
- json_map
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
+ json_map.into_iter().collect(),
)));
} else {
if input.borrow().get_option("latest")?.as_bool() == Some(true)
@@ -1804,7 +1788,7 @@ impl ShowCommand {
if r#type == "psr-0" || r#type == "psr-4" {
if let PhpMixed::Array(map) = autoloads {
for (name, path) in map.iter() {
- let path_str = match &**path {
+ let path_str = match &*path {
PhpMixed::List(l) => l
.iter()
.filter_map(|p| p.as_string().map(|s| s.to_string()))
@@ -1957,10 +1941,7 @@ impl ShowCommand {
.into_iter()
.map(PhpMixed::String)
.collect();
- json.insert(
- "keywords".to_string(),
- PhpMixed::List(keywords.into_iter().map(Box::new).collect()),
- );
+ json.insert("keywords".to_string(), PhpMixed::List(keywords));
json.insert(
"type".to_string(),
PhpMixed::String(package.get_type().to_string()),
@@ -1978,7 +1959,7 @@ impl ShowCommand {
package
.get_names(true)
.into_iter()
- .map(|n| Box::new(PhpMixed::String(n)))
+ .map(PhpMixed::String)
.collect(),
),
);
@@ -2012,7 +1993,7 @@ impl ShowCommand {
);
json.insert(
"source".to_string(),
- PhpMixed::Array(src.into_iter().map(|(k, v)| (k, Box::new(v))).collect()),
+ PhpMixed::Array(src.into_iter().collect()),
);
}
@@ -2032,7 +2013,7 @@ impl ShowCommand {
);
json.insert(
"dist".to_string(),
- PhpMixed::Array(dst.into_iter().map(|(k, v)| (k, Box::new(v))).collect()),
+ PhpMixed::Array(dst.into_iter().collect()),
);
}
@@ -2082,7 +2063,7 @@ impl ShowCommand {
}
json.insert(
"suggests".to_string(),
- PhpMixed::Array(s.into_iter().map(|(k, v)| (k, Box::new(v))).collect()),
+ PhpMixed::Array(s.into_iter().collect()),
);
}
@@ -2093,7 +2074,7 @@ impl ShowCommand {
}
json.insert(
"support".to_string(),
- PhpMixed::Array(s.into_iter().map(|(k, v)| (k, Box::new(v))).collect()),
+ PhpMixed::Array(s.into_iter().collect()),
);
}
@@ -2106,7 +2087,7 @@ impl ShowCommand {
package
.get_include_paths()
.into_iter()
- .map(|p| Box::new(PhpMixed::String(p)))
+ .map(PhpMixed::String)
.collect(),
),
);
@@ -2115,7 +2096,7 @@ impl ShowCommand {
json = Self::append_links(json, package);
self.get_io().write(&JsonFile::encode(&PhpMixed::Array(
- json.into_iter().map(|(k, v)| (k, Box::new(v))).collect(),
+ json.into_iter().collect(),
)));
Ok(())
}
@@ -2143,10 +2124,7 @@ impl ShowCommand {
.into_iter()
.map(|(k, _)| PhpMixed::String(k))
.collect();
- json.insert(
- "versions".to_string(),
- PhpMixed::List(keys.into_iter().map(Box::new).collect()),
- );
+ json.insert("versions".to_string(), PhpMixed::List(keys));
json
}
@@ -2183,15 +2161,12 @@ impl ShowCommand {
m.insert("name".to_string(), PhpMixed::String(name));
m.insert("osi".to_string(), PhpMixed::String(license_id));
m.insert("url".to_string(), PhpMixed::String(url));
- PhpMixed::Array(m.into_iter().map(|(k, v)| (k, Box::new(v))).collect())
+ PhpMixed::Array(m.into_iter().collect())
}
}
})
.collect();
- json.insert(
- "licenses".to_string(),
- PhpMixed::List(mapped.into_iter().map(Box::new).collect()),
- );
+ json.insert("licenses".to_string(), PhpMixed::List(mapped));
}
json
@@ -2211,7 +2186,7 @@ impl ShowCommand {
if let PhpMixed::Array(map) = autoloads {
for (name, path) in map.iter() {
- let mut path_val = (**path).clone();
+ let mut path_val = path.clone();
let is_empty_path = match &path_val {
PhpMixed::String(s) => s.is_empty(),
PhpMixed::Null => true,
@@ -2230,10 +2205,7 @@ impl ShowCommand {
}
}
- autoload.insert(
- r#type.clone(),
- PhpMixed::Array(psr.into_iter().map(|(k, v)| (k, Box::new(v))).collect()),
- );
+ autoload.insert(r#type.clone(), PhpMixed::Array(psr.into_iter().collect()));
} else if r#type == "classmap" {
autoload.insert("classmap".to_string(), autoloads.clone());
}
@@ -2241,12 +2213,7 @@ impl ShowCommand {
json.insert(
"autoload".to_string(),
- PhpMixed::Array(
- autoload
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
+ PhpMixed::Array(autoload.into_iter().collect()),
);
}
@@ -2281,7 +2248,7 @@ impl ShowCommand {
}
json.insert(
link_type.to_string(),
- PhpMixed::Array(m.into_iter().map(|(k, v)| (k, Box::new(v))).collect()),
+ PhpMixed::Array(m.into_iter().collect()),
);
}
@@ -2378,7 +2345,7 @@ impl ShowCommand {
&PhpMixed::Array(
require
.iter()
- .map(|(k, v)| (k.clone(), Box::new((**v).clone())))
+ .map(|(k, v)| (k.clone(), v.clone()))
.collect(),
),
&packages_in_tree,
@@ -2432,22 +2399,13 @@ impl ShowCommand {
PhpMixed::List(
deep_children
.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(),
),
);
}
- children.push(PhpMixed::Array(
- tree_child_desc
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ));
+ children.push(PhpMixed::Array(tree_child_desc.into_iter().collect()));
}
let mut tree: IndexMap<String, PhpMixed> = IndexMap::new();
tree.insert(
@@ -2469,10 +2427,7 @@ impl ShowCommand {
);
if !children.is_empty() {
- tree.insert(
- "requires".to_string(),
- PhpMixed::List(children.into_iter().map(Box::new).collect()),
- );
+ tree.insert("requires".to_string(), PhpMixed::List(children));
}
tree
@@ -2524,7 +2479,7 @@ impl ShowCommand {
let circular_warn = if in_array(
PhpMixed::String(require_name.clone()),
- &PhpMixed::List(current_tree.iter().map(|v| Box::new(v.clone())).collect()),
+ &PhpMixed::List(current_tree.iter().cloned().collect()),
true,
) {
"(circular dependency aborted here)"
@@ -2578,7 +2533,7 @@ impl ShowCommand {
if !in_array(
PhpMixed::String(require_name.clone()),
- &PhpMixed::List(current_tree.iter().map(|v| Box::new(v.clone())).collect()),
+ &PhpMixed::List(current_tree.iter().cloned().collect()),
true,
) {
current_tree.push(PhpMixed::String(require_name.clone()));
@@ -2595,11 +2550,7 @@ impl ShowCommand {
PhpMixed::List(
deep_children
.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(),
),
);
diff --git a/crates/shirabe/src/command/suggests_command.rs b/crates/shirabe/src/command/suggests_command.rs
index 8766196..eb4e05d 100644
--- a/crates/shirabe/src/command/suggests_command.rs
+++ b/crates/shirabe/src/command/suggests_command.rs
@@ -151,7 +151,7 @@ impl Command for SuggestsCommand {
let platform_cfg = composer.get_config().borrow().get("platform");
let platform_overrides: IndexMap<String, PhpMixed> = platform_cfg
.as_array()
- .map(|m| m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect())
+ .map(|m| m.iter().map(|(k, v)| (k.clone(), v.clone())).collect())
.unwrap_or_default();
installed_repos.push(RepositoryInterfaceHandle::new(PlatformRepository::new(
vec![],
diff --git a/crates/shirabe/src/command/update_command.rs b/crates/shirabe/src/command/update_command.rs
index 4581ce1..42622bd 100644
--- a/crates/shirabe/src/command/update_command.rs
+++ b/crates/shirabe/src/command/update_command.rs
@@ -308,9 +308,9 @@ impl Command for UpdateCommand {
!in_array(
PhpMixed::String(package.clone()),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("lock".to_string())),
- Box::new(PhpMixed::String("nothing".to_string())),
- Box::new(PhpMixed::String("mirrors".to_string())),
+ PhpMixed::String("lock".to_string()),
+ PhpMixed::String("nothing".to_string()),
+ PhpMixed::String("mirrors".to_string()),
]),
true,
)
@@ -700,9 +700,7 @@ impl UpdateCommand {
let mut table = Table::new(output);
table.set_headers(vec![PhpMixed::String("Selected packages".to_string())]);
for package in &packages {
- table.add_row(PhpMixed::List(vec![Box::new(PhpMixed::String(
- package.clone(),
- ))]));
+ table.add_row(PhpMixed::List(vec![PhpMixed::String(package.clone())]));
}
table.render();
diff --git a/crates/shirabe/src/config.rs b/crates/shirabe/src/config.rs
index da1b170..7c6d477 100644
--- a/crates/shirabe/src/config.rs
+++ b/crates/shirabe/src/config.rs
@@ -69,23 +69,20 @@ impl Config {
"preferred-install".to_string(),
PhpMixed::String("dist".to_string()),
);
- let mut audit: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- audit.insert(
- "ignore".to_string(),
- Box::new(PhpMixed::Array(IndexMap::new())),
- );
+ let mut audit: IndexMap<String, PhpMixed> = IndexMap::new();
+ audit.insert("ignore".to_string(), PhpMixed::Array(IndexMap::new()));
audit.insert(
"abandoned".to_string(),
- Box::new(PhpMixed::String(Auditor::ABANDONED_FAIL.to_string())),
+ PhpMixed::String(Auditor::ABANDONED_FAIL.to_string()),
);
c.insert("audit".to_string(), PhpMixed::Array(audit));
c.insert("notify-on-install".to_string(), PhpMixed::Bool(true));
c.insert(
"github-protocols".to_string(),
PhpMixed::List(vec![
- Box::new(PhpMixed::String("https".to_string())),
- Box::new(PhpMixed::String("ssh".to_string())),
- Box::new(PhpMixed::String("git".to_string())),
+ PhpMixed::String("https".to_string()),
+ PhpMixed::String("ssh".to_string()),
+ PhpMixed::String("git".to_string()),
]),
);
c.insert("gitlab-protocol".to_string(), PhpMixed::Null);
@@ -141,7 +138,7 @@ impl Config {
);
c.insert(
"github-domains".to_string(),
- PhpMixed::List(vec![Box::new(PhpMixed::String("github.com".to_string()))]),
+ PhpMixed::List(vec![PhpMixed::String("github.com".to_string())]),
);
c.insert(
"bitbucket-expose-hostname".to_string(),
@@ -155,7 +152,7 @@ impl Config {
c.insert("github-expose-hostname".to_string(), PhpMixed::Bool(true));
c.insert(
"gitlab-domains".to_string(),
- PhpMixed::List(vec![Box::new(PhpMixed::String("gitlab.com".to_string()))]),
+ PhpMixed::List(vec![PhpMixed::String("gitlab.com".to_string())]),
);
c.insert(
"store-auths".to_string(),
@@ -198,7 +195,7 @@ impl Config {
);
c.insert(
"forgejo-domains".to_string(),
- PhpMixed::List(vec![Box::new(PhpMixed::String("codeberg.org".to_string()))]),
+ PhpMixed::List(vec![PhpMixed::String("codeberg.org".to_string())]),
);
c.insert(
"forgejo-token".to_string(),
@@ -210,14 +207,11 @@ impl Config {
/// @var array<string, mixed>
pub fn default_repositories() -> IndexMap<String, PhpMixed> {
let mut r: IndexMap<String, PhpMixed> = IndexMap::new();
- let mut packagist: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- packagist.insert(
- "type".to_string(),
- Box::new(PhpMixed::String("composer".to_string())),
- );
+ let mut packagist: IndexMap<String, PhpMixed> = IndexMap::new();
+ packagist.insert("type".to_string(), PhpMixed::String("composer".to_string()));
packagist.insert(
"url".to_string(),
- Box::new(PhpMixed::String("https://repo.packagist.org".to_string())),
+ PhpMixed::String("https://repo.packagist.org".to_string()),
);
r.insert("packagist.org".to_string(), PhpMixed::Array(packagist));
r
@@ -316,18 +310,18 @@ impl Config {
_ => IndexMap::new(),
};
for (key, val_box) in &config_section_map {
- let val = (**val_box).clone();
+ let val = val_box.clone();
if in_array(
PhpMixed::String(key.clone()),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("bitbucket-oauth".to_string())),
- Box::new(PhpMixed::String("github-oauth".to_string())),
- Box::new(PhpMixed::String("gitlab-oauth".to_string())),
- Box::new(PhpMixed::String("gitlab-token".to_string())),
- Box::new(PhpMixed::String("http-basic".to_string())),
- Box::new(PhpMixed::String("bearer".to_string())),
- Box::new(PhpMixed::String("client-certificate".to_string())),
- Box::new(PhpMixed::String("forgejo-token".to_string())),
+ PhpMixed::String("bitbucket-oauth".to_string()),
+ PhpMixed::String("github-oauth".to_string()),
+ PhpMixed::String("gitlab-oauth".to_string()),
+ PhpMixed::String("gitlab-token".to_string()),
+ PhpMixed::String("http-basic".to_string()),
+ PhpMixed::String("bearer".to_string()),
+ PhpMixed::String("client-certificate".to_string()),
+ PhpMixed::String("forgejo-token".to_string()),
]),
true,
) && self.config.contains_key(key)
@@ -338,9 +332,7 @@ impl Config {
self.set_source_of_config_value(&val, key, source);
} else if in_array(
PhpMixed::String(key.clone()),
- &PhpMixed::List(vec![Box::new(PhpMixed::String(
- "allow-plugins".to_string(),
- ))]),
+ &PhpMixed::List(vec![PhpMixed::String("allow-plugins".to_string())]),
true,
) && self.config.contains_key(key)
&& is_array(self.config.get(key).unwrap_or(&PhpMixed::Null))
@@ -357,8 +349,8 @@ impl Config {
} else if in_array(
PhpMixed::String(key.clone()),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("gitlab-domains".to_string())),
- Box::new(PhpMixed::String("github-domains".to_string())),
+ PhpMixed::String("gitlab-domains".to_string()),
+ PhpMixed::String("github-domains".to_string()),
]),
true,
) && self.config.contains_key(key)
@@ -375,12 +367,7 @@ impl Config {
let deduped = array_unique(&unique_list);
self.config.insert(
key.clone(),
- PhpMixed::List(
- deduped
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
- ),
+ PhpMixed::List(deduped.into_iter().map(PhpMixed::String).collect()),
);
self.set_source_of_config_value(&val, key, source);
} else if key == "preferred-install" && self.config.contains_key(key) {
@@ -389,13 +376,13 @@ impl Config {
if is_array(&val) || is_array(&existing) {
if is_string(&val) {
let mut m = IndexMap::new();
- m.insert("*".to_string(), Box::new(val.clone()));
+ m.insert("*".to_string(), val.clone());
val = PhpMixed::Array(m);
}
let existing = self.config.get(key).cloned().unwrap_or(PhpMixed::Null);
if is_string(&existing) {
let mut m = IndexMap::new();
- m.insert("*".to_string(), Box::new(existing));
+ m.insert("*".to_string(), existing);
self.config.insert(key.clone(), PhpMixed::Array(m));
self.source_of_config_value
.borrow_mut()
@@ -427,7 +414,6 @@ impl Config {
.and_then(|v| v.as_array())
.and_then(|m| m.get("ignore"))
.cloned()
- .map(|b| *b)
.unwrap_or(PhpMixed::List(vec![]));
let merged = array_merge(
self.config.get("audit").cloned().unwrap_or(PhpMixed::Null),
@@ -436,16 +422,14 @@ impl Config {
self.config.insert(key.clone(), merged);
self.set_source_of_config_value(&val, key, source);
let val_ignore = match &val {
- PhpMixed::Array(m) => m
- .get("ignore")
- .cloned()
- .map(|b| *b)
- .unwrap_or(PhpMixed::List(vec![])),
+ PhpMixed::Array(m) => {
+ m.get("ignore").cloned().unwrap_or(PhpMixed::List(vec![]))
+ }
_ => PhpMixed::List(vec![]),
};
let new_ignores = array_merge(current_ignores, val_ignore);
if let Some(PhpMixed::Array(audit)) = self.config.get_mut("audit") {
- audit.insert("ignore".to_string(), Box::new(new_ignores));
+ audit.insert("ignore".to_string(), new_ignores);
}
} else {
self.config.insert(key.clone(), val.clone());
@@ -467,7 +451,7 @@ impl Config {
.map(|(k, v)| (k.clone(), v.clone()))
.collect();
let new_repos_map: IndexMap<String, PhpMixed> = match &repositories_section {
- 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(),
_ => IndexMap::new(),
};
let new_repos: IndexMap<String, PhpMixed> = new_repos_map.into_iter().rev().collect();
@@ -523,12 +507,7 @@ impl Config {
}
let found_key = array_search_mixed(
repository,
- &PhpMixed::Array(
- self.repositories
- .iter()
- .map(|(k, v)| (k.clone(), Box::new(v.clone())))
- .collect(),
- ),
+ &PhpMixed::Array(self.repositories.clone()),
true,
)
.and_then(|v| v.as_string().map(|s| s.to_string()))
@@ -758,10 +737,10 @@ impl Config {
if !in_array(
PhpMixed::String(value.clone()),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("auto".to_string())),
- Box::new(PhpMixed::String("full".to_string())),
- Box::new(PhpMixed::String("proxy".to_string())),
- Box::new(PhpMixed::String("symlink".to_string())),
+ PhpMixed::String("auto".to_string()),
+ PhpMixed::String("full".to_string()),
+ PhpMixed::String("proxy".to_string()),
+ PhpMixed::String("symlink".to_string()),
]),
false,
) {
@@ -792,11 +771,11 @@ impl Config {
if !in_array(
PhpMixed::String(env_str.clone()),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("stash".to_string())),
- Box::new(PhpMixed::String("true".to_string())),
- Box::new(PhpMixed::String("false".to_string())),
- Box::new(PhpMixed::String("1".to_string())),
- Box::new(PhpMixed::String("0".to_string())),
+ PhpMixed::String("stash".to_string()),
+ PhpMixed::String("true".to_string()),
+ PhpMixed::String("false".to_string()),
+ PhpMixed::String("1".to_string()),
+ PhpMixed::String("0".to_string()),
]),
true,
) {
@@ -861,7 +840,7 @@ impl Config {
&PhpMixed::String("git".to_string()),
&PhpMixed::Array(
map.into_iter()
- .map(|(k, v)| (k, Box::new(PhpMixed::String(v))))
+ .map(|(k, v)| (k, PhpMixed::String(v)))
.collect(),
),
false,
@@ -887,10 +866,7 @@ impl Config {
}
Ok(PhpMixed::List(
- protos
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
+ protos.into_iter().map(PhpMixed::String).collect(),
))
}
@@ -916,7 +892,7 @@ impl Config {
&PhpMixed::List(
valid_choices
.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
+ .map(|s| PhpMixed::String(s.clone()))
.collect(),
),
true,
@@ -932,10 +908,7 @@ impl Config {
.into());
}
if let PhpMixed::Array(ref mut m) = result {
- m.insert(
- "abandoned".to_string(),
- Box::new(PhpMixed::String(abandoned_env_str)),
- );
+ m.insert("abandoned".to_string(), PhpMixed::String(abandoned_env_str));
}
}
@@ -946,8 +919,8 @@ impl Config {
if !in_array(
PhpMixed::String(env_str.clone()),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("0".to_string())),
- Box::new(PhpMixed::String("1".to_string())),
+ PhpMixed::String("0".to_string()),
+ PhpMixed::String("1".to_string()),
]),
true,
) {
@@ -963,7 +936,7 @@ impl Config {
if let PhpMixed::Array(ref mut m) = result {
m.insert(
"block-abandoned".to_string(),
- Box::new(PhpMixed::Bool(env_str == "1")),
+ PhpMixed::Bool(env_str == "1"),
);
}
}
@@ -987,17 +960,12 @@ impl Config {
let mut all: IndexMap<String, PhpMixed> = IndexMap::new();
all.insert(
"repositories".to_string(),
- PhpMixed::Array(
- self.get_repositories()
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
+ PhpMixed::Array(self.get_repositories()),
);
let keys: Vec<String> = self.config.keys().cloned().collect();
- let mut config_section: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
+ let mut config_section: IndexMap<String, PhpMixed> = IndexMap::new();
for key in keys {
- config_section.insert(key.clone(), Box::new(self.get_with_flags(&key, flags)?));
+ config_section.insert(key.clone(), self.get_with_flags(&key, flags)?);
}
all.insert("config".to_string(), PhpMixed::Array(config_section));
@@ -1024,7 +992,7 @@ impl Config {
let map = match config_value {
PhpMixed::Array(m) => m
.iter()
- .map(|(k, v)| (k.clone(), (**v).clone()))
+ .map(|(k, v)| (k.clone(), v.clone()))
.collect::<Vec<_>>(),
_ => vec![],
};
@@ -1039,22 +1007,9 @@ impl Config {
let mut result: IndexMap<String, PhpMixed> = IndexMap::new();
result.insert(
"repositories".to_string(),
- PhpMixed::Array(
- self.get_repositories()
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
- );
- result.insert(
- "config".to_string(),
- PhpMixed::Array(
- self.config
- .iter()
- .map(|(k, v)| (k.clone(), Box::new(v.clone())))
- .collect(),
- ),
+ PhpMixed::Array(self.get_repositories()),
);
+ result.insert("config".to_string(), PhpMixed::Array(self.config.clone()));
result
}
@@ -1163,10 +1118,10 @@ impl Config {
.map(PhpMixed::String)
.unwrap_or(PhpMixed::Null),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("http".to_string())),
- Box::new(PhpMixed::String("git".to_string())),
- Box::new(PhpMixed::String("ftp".to_string())),
- Box::new(PhpMixed::String("svn".to_string())),
+ PhpMixed::String("http".to_string()),
+ PhpMixed::String("git".to_string()),
+ PhpMixed::String("ftp".to_string()),
+ PhpMixed::String("svn".to_string()),
]),
false,
) {
diff --git a/crates/shirabe/src/config/json_config_source.rs b/crates/shirabe/src/config/json_config_source.rs
index 3ae302e..85bd12e 100644
--- a/crates/shirabe/src/config/json_config_source.rs
+++ b/crates/shirabe/src/config/json_config_source.rs
@@ -94,33 +94,28 @@ impl JsonConfigSource {
"support",
] {
if let PhpMixed::Array(map) = &mut config
- && let Some(boxed) = map.get(prop)
- && let PhpMixed::Array(inner) = boxed.as_ref()
+ && let Some(PhpMixed::Array(inner)) = map.get(prop)
&& inner.is_empty()
{
// PHP: $config[$prop] = new \stdClass;
- map.insert(prop.to_string(), Box::new(PhpMixed::Array(IndexMap::new())));
+ map.insert(prop.to_string(), PhpMixed::Array(IndexMap::new()));
}
}
for prop in ["psr-0", "psr-4"] {
if let PhpMixed::Array(map) = &mut config {
if let Some(autoload) = map.get_mut("autoload")
- && let PhpMixed::Array(autoload_map) = autoload.as_mut()
- && let Some(inner) = autoload_map.get(prop)
- && let PhpMixed::Array(inner_map) = inner.as_ref()
+ && let PhpMixed::Array(autoload_map) = autoload
+ && let Some(PhpMixed::Array(inner_map)) = autoload_map.get(prop)
&& inner_map.is_empty()
{
- autoload_map
- .insert(prop.to_string(), Box::new(PhpMixed::Array(IndexMap::new())));
+ autoload_map.insert(prop.to_string(), PhpMixed::Array(IndexMap::new()));
}
if let Some(autoload_dev) = map.get_mut("autoload-dev")
- && let PhpMixed::Array(autoload_dev_map) = autoload_dev.as_mut()
- && let Some(inner) = autoload_dev_map.get(prop)
- && let PhpMixed::Array(inner_map) = inner.as_ref()
+ && let PhpMixed::Array(autoload_dev_map) = autoload_dev
+ && let Some(PhpMixed::Array(inner_map)) = autoload_dev_map.get(prop)
&& inner_map.is_empty()
{
- autoload_dev_map
- .insert(prop.to_string(), Box::new(PhpMixed::Array(IndexMap::new())));
+ autoload_dev_map.insert(prop.to_string(), PhpMixed::Array(IndexMap::new()));
}
}
}
@@ -137,12 +132,11 @@ impl JsonConfigSource {
] {
if let PhpMixed::Array(map) = &mut config
&& let Some(cfg) = map.get_mut("config")
- && let PhpMixed::Array(cfg_map) = cfg.as_mut()
- && let Some(inner) = cfg_map.get(prop)
- && let PhpMixed::Array(inner_map) = inner.as_ref()
+ && let PhpMixed::Array(cfg_map) = cfg
+ && let Some(PhpMixed::Array(inner_map)) = cfg_map.get(prop)
&& inner_map.is_empty()
{
- cfg_map.insert(prop.to_string(), Box::new(PhpMixed::Array(IndexMap::new())));
+ cfg_map.insert(prop.to_string(), PhpMixed::Array(IndexMap::new()));
}
}
self.file.borrow().write(config)?;
@@ -187,37 +181,37 @@ impl JsonConfigSource {
/// ```php
/// if (!array_is_list($config['repositories'] ?? [])) { convert the keyed map to a list }
/// ```
- fn normalize_repositories_to_list(root: &mut IndexMap<String, Box<PhpMixed>>) {
- let map = match root.get("repositories").map(|b| b.as_ref()) {
+ fn normalize_repositories_to_list(root: &mut IndexMap<String, PhpMixed>) {
+ let map = match root.get("repositories") {
Some(PhpMixed::Array(m)) if !m.is_empty() => m.clone(),
_ => return,
};
- let mut list: Vec<Box<PhpMixed>> = Vec::new();
+ let mut list: Vec<PhpMixed> = Vec::new();
for (repository_index, repository) in map {
- match repository.as_ref() {
+ match &repository {
PhpMixed::Array(repo_map) => {
let mut entry = repo_map.clone();
if !entry.contains_key("name") {
let mut with_name = IndexMap::new();
with_name.insert(
"name".to_string(),
- Box::new(PhpMixed::String(repository_index.clone())),
+ PhpMixed::String(repository_index.clone()),
);
for (k, v) in entry {
with_name.insert(k, v);
}
entry = with_name;
}
- list.push(Box::new(PhpMixed::Array(entry)));
+ list.push(PhpMixed::Array(entry));
}
_ => {
let mut single = IndexMap::new();
single.insert(repository_index.clone(), repository.clone());
- list.push(Box::new(PhpMixed::Array(single)));
+ list.push(PhpMixed::Array(single));
}
}
}
- root.insert("repositories".to_string(), Box::new(PhpMixed::List(list)));
+ root.insert("repositories".to_string(), PhpMixed::List(list));
}
/// PHP:
@@ -229,53 +223,50 @@ impl JsonConfigSource {
/// ),
/// );
/// ```
- fn dedupe_repositories_by_name(root: &mut IndexMap<String, Box<PhpMixed>>, name: &str) {
- let items: Vec<Box<PhpMixed>> = match root.get("repositories").map(|b| b.as_ref()) {
+ fn dedupe_repositories_by_name(root: &mut IndexMap<String, PhpMixed>, name: &str) {
+ let items: Vec<PhpMixed> = match root.get("repositories") {
Some(PhpMixed::List(items)) => items.clone(),
Some(PhpMixed::Array(map)) => map.values().cloned().collect(),
_ => return,
};
- let filtered: Vec<Box<PhpMixed>> = items
+ let filtered: Vec<PhpMixed> = items
.into_iter()
.filter(|val| {
- let name_set = val.as_ref().get("name").is_some();
- let name_eq = val.as_ref().get("name").and_then(|v| v.as_string()) == Some(name);
- let is_repo_false = matches!(val.as_ref(), PhpMixed::Array(m)
- if m.len() == 1 && matches!(m.get(name).map(|b| b.as_ref()), Some(PhpMixed::Bool(false))));
+ let name_set = val.get("name").is_some();
+ let name_eq = val.get("name").and_then(|v| v.as_string()) == Some(name);
+ let is_repo_false = matches!(val, PhpMixed::Array(m)
+ if m.len() == 1 && matches!(m.get(name), Some(PhpMixed::Bool(false))));
!name_set || !name_eq || !is_repo_false
})
.collect();
- root.insert(
- "repositories".to_string(),
- Box::new(PhpMixed::List(filtered)),
- );
+ root.insert("repositories".to_string(), PhpMixed::List(filtered));
}
/// Set a value at a nested key path, creating intermediate maps as needed.
- fn set_nested(root: &mut IndexMap<String, Box<PhpMixed>>, path: &[&str], value: PhpMixed) {
+ fn set_nested(root: &mut IndexMap<String, PhpMixed>, path: &[&str], value: PhpMixed) {
let (last, heads) = path.split_last().unwrap();
let mut cursor = root;
for seg in heads {
let entry = cursor
.entry(seg.to_string())
- .or_insert_with(|| Box::new(PhpMixed::Array(IndexMap::new())));
- if !matches!(entry.as_ref(), PhpMixed::Array(_)) {
- **entry = PhpMixed::Array(IndexMap::new());
+ .or_insert_with(|| PhpMixed::Array(IndexMap::new()));
+ if !matches!(entry, PhpMixed::Array(_)) {
+ *entry = PhpMixed::Array(IndexMap::new());
}
- cursor = match entry.as_mut() {
+ cursor = match entry {
PhpMixed::Array(m) => m,
_ => unreachable!(),
};
}
- cursor.insert(last.to_string(), Box::new(value));
+ cursor.insert(last.to_string(), value);
}
/// Unset a value at a nested key path; a no-op if the path is absent.
- fn unset_nested(root: &mut IndexMap<String, Box<PhpMixed>>, path: &[&str]) {
+ fn unset_nested(root: &mut IndexMap<String, PhpMixed>, path: &[&str]) {
let (last, heads) = path.split_last().unwrap();
let mut cursor = root;
for seg in heads {
- cursor = match cursor.get_mut(*seg).map(|b| b.as_mut()) {
+ cursor = match cursor.get_mut(*seg) {
Some(PhpMixed::Array(m)) => m,
_ => return,
};
@@ -315,40 +306,28 @@ impl ConfigSourceInterface for JsonConfigSource {
Self::normalize_repositories_to_list(root);
if matches!(config, PhpMixed::Bool(false)) {
- if let Some(PhpMixed::List(list)) =
- root.get_mut("repositories").map(|b| b.as_mut())
- {
+ if let Some(PhpMixed::List(list)) = root.get_mut("repositories") {
for repository in list.iter_mut() {
- if repository.as_ref().get("name").and_then(|v| v.as_string())
- == Some(name)
- {
+ if repository.get("name").and_then(|v| v.as_string()) == Some(name) {
let mut replaced = IndexMap::new();
- replaced.insert(name.to_string(), Box::new(PhpMixed::Bool(false)));
- **repository = PhpMixed::Array(replaced);
+ replaced.insert(name.to_string(), PhpMixed::Bool(false));
+ *repository = PhpMixed::Array(replaced);
return Ok(());
}
- if let PhpMixed::Array(m) = repository.as_ref()
+ if let PhpMixed::Array(m) = &*repository
&& m.len() == 1
- && matches!(
- m.get(name).map(|b| b.as_ref()),
- Some(PhpMixed::Bool(false))
- )
+ && matches!(m.get(name), Some(PhpMixed::Bool(false)))
{
return Ok(());
}
}
} else {
- root.insert(
- "repositories".to_string(),
- Box::new(PhpMixed::List(Vec::new())),
- );
+ root.insert("repositories".to_string(), PhpMixed::List(Vec::new()));
}
let mut entry = IndexMap::new();
- entry.insert(name.to_string(), Box::new(PhpMixed::Bool(false)));
- if let Some(PhpMixed::List(list)) =
- root.get_mut("repositories").map(|b| b.as_mut())
- {
- list.push(Box::new(PhpMixed::Array(entry)));
+ entry.insert(name.to_string(), PhpMixed::Bool(false));
+ if let Some(PhpMixed::List(list)) = root.get_mut("repositories") {
+ list.push(PhpMixed::Array(entry));
}
return Ok(());
}
@@ -359,10 +338,7 @@ impl ConfigSourceInterface for JsonConfigSource {
&& !rc.contains_key("name")
{
let mut with_name = IndexMap::new();
- with_name.insert(
- "name".to_string(),
- Box::new(PhpMixed::String(name.to_string())),
- );
+ with_name.insert("name".to_string(), PhpMixed::String(name.to_string()));
for (k, v) in rc.clone() {
with_name.insert(k, v);
}
@@ -371,21 +347,14 @@ impl ConfigSourceInterface for JsonConfigSource {
Self::dedupe_repositories_by_name(root, name);
- if !matches!(
- root.get("repositories").map(|b| b.as_ref()),
- Some(PhpMixed::List(_))
- ) {
- root.insert(
- "repositories".to_string(),
- Box::new(PhpMixed::List(Vec::new())),
- );
+ if !matches!(root.get("repositories"), Some(PhpMixed::List(_))) {
+ root.insert("repositories".to_string(), PhpMixed::List(Vec::new()));
}
- if let Some(PhpMixed::List(list)) = root.get_mut("repositories").map(|b| b.as_mut())
- {
+ if let Some(PhpMixed::List(list)) = root.get_mut("repositories") {
if append {
- list.push(Box::new(repo_config));
+ list.push(repo_config);
} else {
- list.insert(0, Box::new(repo_config));
+ list.insert(0, repo_config);
}
}
Ok(())
@@ -411,20 +380,17 @@ impl ConfigSourceInterface for JsonConfigSource {
Self::dedupe_repositories_by_name(root, name);
let mut index_to_insert: Option<usize> = None;
- if let Some(PhpMixed::List(list)) = root.get("repositories").map(|b| b.as_ref()) {
+ if let Some(PhpMixed::List(list)) = root.get("repositories") {
for (i, repository) in list.iter().enumerate() {
- if repository.as_ref().get("name").and_then(|v| v.as_string())
+ if repository.get("name").and_then(|v| v.as_string())
== Some(reference_name)
{
index_to_insert = Some(i);
break;
}
- if let PhpMixed::Array(m) = repository.as_ref()
+ if let PhpMixed::Array(m) = repository
&& m.len() == 1
- && matches!(
- m.get(reference_name).map(|b| b.as_ref()),
- Some(PhpMixed::Bool(false))
- )
+ && matches!(m.get(reference_name), Some(PhpMixed::Bool(false)))
{
index_to_insert = Some(i);
break;
@@ -448,25 +414,21 @@ impl ConfigSourceInterface for JsonConfigSource {
&& !rc.contains_key("name")
{
let mut with_name = IndexMap::new();
- with_name.insert(
- "name".to_string(),
- Box::new(PhpMixed::String(name.to_string())),
- );
+ with_name.insert("name".to_string(), PhpMixed::String(name.to_string()));
for (k, v) in rc.clone() {
with_name.insert(k, v);
}
repo_config = PhpMixed::Array(with_name);
}
- if let Some(PhpMixed::List(list)) = root.get_mut("repositories").map(|b| b.as_mut())
- {
+ if let Some(PhpMixed::List(list)) = root.get_mut("repositories") {
let raw = index_to_insert as i64 + offset;
let pos = if raw < 0 {
(list.len() as i64 + raw).max(0)
} else {
raw.min(list.len() as i64)
} as usize;
- list.insert(pos, Box::new(repo_config));
+ list.insert(pos, repo_config);
}
Ok(())
},
@@ -480,17 +442,12 @@ impl ConfigSourceInterface for JsonConfigSource {
let Some(root) = cfg.as_array_mut() else {
return Ok(());
};
- match root.get_mut("repositories").map(|b| b.as_mut()) {
+ match root.get_mut("repositories") {
Some(PhpMixed::List(list)) => {
for repository in list.iter_mut() {
- if repository.as_ref().get("name").and_then(|v| v.as_string())
- == Some(name)
- {
- if let PhpMixed::Array(m) = repository.as_mut() {
- m.insert(
- "url".to_string(),
- Box::new(PhpMixed::String(url.to_string())),
- );
+ if repository.get("name").and_then(|v| v.as_string()) == Some(name) {
+ if let PhpMixed::Array(m) = repository {
+ m.insert("url".to_string(), PhpMixed::String(url.to_string()));
}
return Ok(());
}
@@ -500,20 +457,16 @@ impl ConfigSourceInterface for JsonConfigSource {
let mut target: Option<String> = None;
for (index, repository) in map.iter() {
if index == name
- || repository.as_ref().get("name").and_then(|v| v.as_string())
- == Some(name)
+ || repository.get("name").and_then(|v| v.as_string()) == Some(name)
{
target = Some(index.clone());
break;
}
}
if let Some(k) = target
- && let Some(PhpMixed::Array(m)) = map.get_mut(&k).map(|b| b.as_mut())
+ && let Some(PhpMixed::Array(m)) = map.get_mut(&k)
{
- m.insert(
- "url".to_string(),
- Box::new(PhpMixed::String(url.to_string())),
- );
+ m.insert("url".to_string(), PhpMixed::String(url.to_string()));
}
}
_ => {}
@@ -531,19 +484,17 @@ impl ConfigSourceInterface for JsonConfigSource {
return Ok(());
};
let had_key = matches!(
- root.get("repositories").map(|b| b.as_ref()),
+ root.get("repositories"),
Some(PhpMixed::Array(m)) if m.contains_key(name)
);
if had_key {
- if let Some(PhpMixed::Array(m)) =
- root.get_mut("repositories").map(|b| b.as_mut())
- {
+ if let Some(PhpMixed::Array(m)) = root.get_mut("repositories") {
m.shift_remove(name);
}
} else {
Self::dedupe_repositories_by_name(root, name);
}
- let is_empty = match root.get("repositories").map(|b| b.as_ref()) {
+ let is_empty = match root.get("repositories") {
Some(PhpMixed::List(l)) => l.is_empty(),
Some(PhpMixed::Array(m)) => m.is_empty(),
_ => false,
@@ -645,29 +596,29 @@ impl ConfigSourceInterface for JsonConfigSource {
let first = bits[0];
let entry = root
.entry(first.to_string())
- .or_insert_with(|| Box::new(PhpMixed::Array(IndexMap::new())));
- if !matches!(entry.as_ref(), PhpMixed::Array(_)) {
- **entry = PhpMixed::Array(IndexMap::new());
+ .or_insert_with(|| PhpMixed::Array(IndexMap::new()));
+ if !matches!(entry, PhpMixed::Array(_)) {
+ *entry = PhpMixed::Array(IndexMap::new());
}
- let mut cursor = match entry.as_mut() {
+ let mut cursor = match entry {
PhpMixed::Array(m) => m,
_ => unreachable!(),
};
for bit in &bits {
let e = cursor
.entry(bit.to_string())
- .or_insert_with(|| Box::new(PhpMixed::Array(IndexMap::new())));
- if !matches!(e.as_ref(), PhpMixed::Array(_)) {
- **e = PhpMixed::Array(IndexMap::new());
+ .or_insert_with(|| PhpMixed::Array(IndexMap::new()));
+ if !matches!(e, PhpMixed::Array(_)) {
+ *e = PhpMixed::Array(IndexMap::new());
}
- cursor = match e.as_mut() {
+ cursor = match e {
PhpMixed::Array(m) => m,
_ => unreachable!(),
};
}
- cursor.insert(last.to_string(), Box::new(value));
+ cursor.insert(last.to_string(), value);
} else {
- root.insert(name.to_string(), Box::new(value));
+ root.insert(name.to_string(), value);
}
Ok(())
},
@@ -693,12 +644,10 @@ impl ConfigSourceInterface for JsonConfigSource {
let Some(entry) = root.get_mut(first) else {
return Ok(());
};
- let mut cursor: &mut PhpMixed = entry.as_mut();
+ let mut cursor: &mut PhpMixed = entry;
for bit in &bits {
cursor = match cursor {
- PhpMixed::Array(m) if m.contains_key(*bit) => {
- m.get_mut(*bit).unwrap().as_mut()
- }
+ PhpMixed::Array(m) if m.contains_key(*bit) => m.get_mut(*bit).unwrap(),
_ => return Ok(()),
};
}
@@ -743,7 +692,7 @@ impl ConfigSourceInterface for JsonConfigSource {
let Some(root) = cfg.as_array_mut() else {
return Ok(());
};
- let empty = match root.get(r#type).map(|b| b.as_ref()) {
+ let empty = match root.get(r#type) {
Some(PhpMixed::Array(m)) => m.is_empty(),
Some(PhpMixed::List(l)) => l.is_empty(),
_ => false,
diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs
index 9c3ef01..6d6ec0e 100644
--- a/crates/shirabe/src/console/application.rs
+++ b/crates/shirabe/src/console/application.rs
@@ -447,7 +447,7 @@ impl Application {
let no_composer_json_commands_pm = PhpMixed::List(
no_composer_json_commands
.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
+ .map(|s| PhpMixed::String(s.clone()))
.collect(),
);
if new_work_dir.is_none()
@@ -547,9 +547,9 @@ impl Application {
// avoid loading plugins/initializing the Composer instance earlier than necessary if no plugin command is needed
// if showing the version, we never need plugin commands
let mnp_list = PhpMixed::List(vec![
- Box::new(PhpMixed::String("".to_string())),
- Box::new(PhpMixed::String("list".to_string())),
- Box::new(PhpMixed::String("help".to_string())),
+ PhpMixed::String("".to_string()),
+ PhpMixed::String("list".to_string()),
+ PhpMixed::String("help".to_string()),
]);
let may_need_plugin_command = !input
.borrow()
@@ -1111,7 +1111,7 @@ impl Application {
let avast_detect_pm = PhpMixed::List(
avast_detect
.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
+ .map(|s| PhpMixed::String(s.clone()))
.collect(),
);
if is_array(&avast_detect_pm) && !avast_detect.is_empty() {
diff --git a/crates/shirabe/src/dependency_resolver/problem.rs b/crates/shirabe/src/dependency_resolver/problem.rs
index 0075b5e..b65a2c9 100644
--- a/crates/shirabe/src/dependency_resolver/problem.rs
+++ b/crates/shirabe/src/dependency_resolver/problem.rs
@@ -231,7 +231,7 @@ impl Problem {
&PhpMixed::List(
deduplicatable_rule_types
.iter()
- .map(|t| Box::new(PhpMixed::Int(*t)))
+ .map(|t| PhpMixed::Int(*t))
.collect(),
),
true,
@@ -937,8 +937,8 @@ impl Problem {
if in_array(
PhpMixed::String(candidate.get_version().to_string()),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("dev-default".to_string())),
- Box::new(PhpMixed::String("dev-main".to_string())),
+ PhpMixed::String("dev-default".to_string()),
+ PhpMixed::String("dev-main".to_string()),
]),
true,
) {
diff --git a/crates/shirabe/src/downloader/download_manager.rs b/crates/shirabe/src/downloader/download_manager.rs
index 3d4fe9b..23b025f 100644
--- a/crates/shirabe/src/downloader/download_manager.rs
+++ b/crates/shirabe/src/downloader/download_manager.rs
@@ -510,7 +510,7 @@ impl DownloadManager {
&PhpMixed::List(
sources
.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
+ .map(|s| PhpMixed::String(s.clone()))
.collect(),
),
true,
diff --git a/crates/shirabe/src/downloader/file_downloader.rs b/crates/shirabe/src/downloader/file_downloader.rs
index 3c4f7e2..4c30f9e 100644
--- a/crates/shirabe/src/downloader/file_downloader.rs
+++ b/crates/shirabe/src/downloader/file_downloader.rs
@@ -338,10 +338,10 @@ impl DownloaderInterface for FileDownloader {
&& !in_array(
PhpMixed::Int(te.get_code()),
&PhpMixed::List(vec![
- Box::new(PhpMixed::Int(500)),
- Box::new(PhpMixed::Int(502)),
- Box::new(PhpMixed::Int(503)),
- Box::new(PhpMixed::Int(504)),
+ PhpMixed::Int(500),
+ PhpMixed::Int(502),
+ PhpMixed::Int(503),
+ PhpMixed::Int(504),
]),
true,
)
diff --git a/crates/shirabe/src/downloader/gzip_downloader.rs b/crates/shirabe/src/downloader/gzip_downloader.rs
index 05ac244..f59fe11 100644
--- a/crates/shirabe/src/downloader/gzip_downloader.rs
+++ b/crates/shirabe/src/downloader/gzip_downloader.rs
@@ -116,7 +116,7 @@ impl ArchiveDownloader for GzipDownloader {
PhpMixed::List(
command
.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
+ .map(|s| PhpMixed::String(s.clone()))
.collect(),
),
Some(&mut process_output),
diff --git a/crates/shirabe/src/downloader/rar_downloader.rs b/crates/shirabe/src/downloader/rar_downloader.rs
index f2c89c3..29ea491 100644
--- a/crates/shirabe/src/downloader/rar_downloader.rs
+++ b/crates/shirabe/src/downloader/rar_downloader.rs
@@ -89,7 +89,7 @@ impl ArchiveDownloader for RarDownloader {
PhpMixed::List(
command
.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
+ .map(|s| PhpMixed::String(s.clone()))
.collect(),
),
Some(&mut process_output),
diff --git a/crates/shirabe/src/downloader/xz_downloader.rs b/crates/shirabe/src/downloader/xz_downloader.rs
index f7611fd..d79f9bc 100644
--- a/crates/shirabe/src/downloader/xz_downloader.rs
+++ b/crates/shirabe/src/downloader/xz_downloader.rs
@@ -76,7 +76,7 @@ impl ArchiveDownloader for XzDownloader {
PhpMixed::List(
command
.iter()
- .map(|s| Box::new(PhpMixed::String(s.to_string())))
+ .map(|s| PhpMixed::String(s.to_string()))
.collect(),
),
Some(&mut ignored_output),
diff --git a/crates/shirabe/src/downloader/zip_downloader.rs b/crates/shirabe/src/downloader/zip_downloader.rs
index 04e71b4..3d72377 100644
--- a/crates/shirabe/src/downloader/zip_downloader.rs
+++ b/crates/shirabe/src/downloader/zip_downloader.rs
@@ -259,9 +259,7 @@ impl ZipDownloader {
.unwrap();
match response_headers.get(&package.get_name()) {
Some(list) => PhpMixed::List(
- list.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
- .collect(),
+ list.iter().map(|s| PhpMixed::String(s.clone())).collect(),
),
None => PhpMixed::List(vec![]),
}
diff --git a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs
index fb3a17c..3ad6ad9 100644
--- a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs
+++ b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs
@@ -1094,10 +1094,10 @@ impl EventDispatcher {
if is_array(cb)
&& let PhpMixed::Array(map) = cb
{
- let entries: Vec<&Box<PhpMixed>> = map.values().collect();
+ let entries: Vec<&PhpMixed> = map.values().collect();
if entries.len() >= 2 {
- let first = entries[0].as_ref();
- let second = entries[1].as_ref();
+ let first = entries[0];
+ let second = entries[1];
let prefix = if is_string(first) {
if let PhpMixed::String(s) = first {
s.clone()
diff --git a/crates/shirabe/src/factory.rs b/crates/shirabe/src/factory.rs
index 73407bc..0c83d5d 100644
--- a/crates/shirabe/src/factory.rs
+++ b/crates/shirabe/src/factory.rs
@@ -259,7 +259,7 @@ impl Factory {
);
defaults.insert(
"config".to_string(),
- PhpMixed::Array(inner.into_iter().map(|(k, v)| (k, Box::new(v))).collect()),
+ PhpMixed::Array(inner.into_iter().collect()),
);
config.merge(&defaults, Config::SOURCE_DEFAULT);
@@ -281,10 +281,7 @@ impl Factory {
None,
)?;
let read_data = match file.read()? {
- PhpMixed::Array(map) => map
- .into_iter()
- .map(|(k, v)| (k, *v))
- .collect::<IndexMap<_, _>>(),
+ PhpMixed::Array(map) => map.into_iter().collect::<IndexMap<_, _>>(),
_ => IndexMap::new(),
};
let file_path_owned = file.get_path().to_string();
@@ -339,18 +336,13 @@ impl Factory {
None,
)?;
let read_data: IndexMap<String, PhpMixed> = match auth_file.read()? {
- PhpMixed::Array(map) => map.into_iter().map(|(k, v)| (k, *v)).collect(),
+ PhpMixed::Array(map) => map.into_iter().collect(),
_ => IndexMap::new(),
};
let mut wrapped: IndexMap<String, PhpMixed> = IndexMap::new();
wrapped.insert(
"config".to_string(),
- PhpMixed::Array(
- read_data
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
+ PhpMixed::Array(read_data.into_iter().collect()),
);
let auth_path_owned = auth_file.get_path().to_string();
config.merge(&wrapped, &auth_path_owned);
@@ -510,7 +502,7 @@ impl Factory {
local_config_data = file
.read()?
.as_array()
- .map(|m| m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect())
+ .map(|m| m.iter().map(|(k, v)| (k.clone(), v.clone())).collect())
.unwrap_or_default();
local_config_source = file.get_path().to_string();
} else if let Some(LocalConfigInput::Data(data)) = local_config {
@@ -784,7 +776,7 @@ impl Factory {
let lock_contents = JsonFile::encode(&PhpMixed::Array(
local_config_data
.iter()
- .map(|(k, v)| (k.clone(), Box::new(v.clone())))
+ .map(|(k, v)| (k.clone(), v.clone()))
.collect(),
));
let locker = Locker::new(
@@ -1017,7 +1009,7 @@ impl Factory {
.map(|(k, v)| {
(
k,
- match *v {
+ match v {
PhpMixed::String(s) => s,
_ => String::new(),
},
@@ -1375,7 +1367,7 @@ impl Factory {
);
http_downloader_options.insert(
"ssl".to_string(),
- PhpMixed::Array(ssl_map.into_iter().map(|(k, v)| (k, Box::new(v))).collect()),
+ PhpMixed::Array(ssl_map.into_iter().collect()),
);
}
if "" != config.borrow_mut().get_str("capath").unwrap_or_default() {
@@ -1384,12 +1376,10 @@ impl Factory {
.and_then(|v| v.as_array())
.cloned()
.unwrap_or_default();
- let mut ssl_map: IndexMap<String, Box<PhpMixed>> = existing_ssl;
+ let mut ssl_map = existing_ssl;
ssl_map.insert(
"capath".to_string(),
- Box::new(PhpMixed::String(
- config.borrow_mut().get_str("capath").unwrap_or_default(),
- )),
+ PhpMixed::String(config.borrow_mut().get_str("capath").unwrap_or_default()),
);
http_downloader_options.insert("ssl".to_string(), PhpMixed::Array(ssl_map));
}
diff --git a/crates/shirabe/src/installed_versions.rs b/crates/shirabe/src/installed_versions.rs
index fb1f73f..c4ef526 100644
--- a/crates/shirabe/src/installed_versions.rs
+++ b/crates/shirabe/src/installed_versions.rs
@@ -55,12 +55,7 @@ impl InstalledVersions {
.cloned()
.unwrap_or_default();
// PHP: array_keys($installed['versions'])
- let keys: Vec<String> = array_keys(
- &versions
- .into_iter()
- .map(|(k, v)| (k, *v))
- .collect::<IndexMap<String, PhpMixed>>(),
- );
+ let keys: Vec<String> = array_keys(&versions);
packages.push(keys);
}
@@ -74,26 +69,12 @@ impl InstalledVersions {
&PhpMixed::List(
packages
.into_iter()
- .map(|p| {
- Box::new(PhpMixed::List(
- p.into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
- ))
- })
+ .map(|p| PhpMixed::List(p.into_iter().map(PhpMixed::String).collect()))
.collect(),
),
);
let flipped = array_flip(&merged);
- array_keys(
- &flipped
- .as_array()
- .cloned()
- .unwrap_or_default()
- .into_iter()
- .map(|(k, v)| (k, *v))
- .collect::<IndexMap<String, PhpMixed>>(),
- )
+ array_keys(&flipped.as_array().cloned().unwrap_or_default())
}
/// Returns a list of all package names with a specific type e.g. 'library'
@@ -139,7 +120,7 @@ impl InstalledVersions {
let dev_requirement = package
.as_array()
.and_then(|a| a.get("dev_requirement"))
- .map(|v| v.as_ref().clone())
+ .cloned()
.unwrap_or(PhpMixed::Null);
return include_dev_requirements
|| matches!(dev_requirement, PhpMixed::Null)
@@ -197,15 +178,8 @@ impl InstalledVersions {
}
if pkg.contains_key("aliases") {
ranges = array_merge(
- PhpMixed::List(
- ranges
- .iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
- .collect(),
- ),
- pkg.get("aliases")
- .map(|v| (**v).clone())
- .unwrap_or(PhpMixed::Null),
+ PhpMixed::List(ranges.iter().map(|s| PhpMixed::String(s.clone())).collect()),
+ pkg.get("aliases").cloned().unwrap_or(PhpMixed::Null),
)
.as_list()
.map(|l| {
@@ -217,15 +191,8 @@ impl InstalledVersions {
}
if pkg.contains_key("replaced") {
ranges = array_merge(
- PhpMixed::List(
- ranges
- .iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
- .collect(),
- ),
- pkg.get("replaced")
- .map(|v| (**v).clone())
- .unwrap_or(PhpMixed::Null),
+ PhpMixed::List(ranges.iter().map(|s| PhpMixed::String(s.clone())).collect()),
+ pkg.get("replaced").cloned().unwrap_or(PhpMixed::Null),
)
.as_list()
.map(|l| {
@@ -237,15 +204,8 @@ impl InstalledVersions {
}
if pkg.contains_key("provided") {
ranges = array_merge(
- PhpMixed::List(
- ranges
- .iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
- .collect(),
- ),
- pkg.get("provided")
- .map(|v| (**v).clone())
- .unwrap_or(PhpMixed::Null),
+ PhpMixed::List(ranges.iter().map(|s| PhpMixed::String(s.clone())).collect()),
+ pkg.get("provided").cloned().unwrap_or(PhpMixed::Null),
)
.as_list()
.map(|l| {
@@ -386,7 +346,6 @@ impl InstalledVersions {
.into_iter()
.next()
.and_then(|d| d.get("root").and_then(|v| v.as_array()).cloned())
- .map(|m| m.into_iter().map(|(k, v)| (k, *v)).collect())
.unwrap_or_default()
}
@@ -480,11 +439,8 @@ impl InstalledVersions {
} else if is_file(&format!("{}/composer/installed.php", vendor_dir)) {
let required =
require_php_file(&format!("{}/composer/installed.php", vendor_dir,));
- let required_map: IndexMap<String, PhpMixed> = required
- .as_array()
- .cloned()
- .map(|m| m.into_iter().map(|(k, v)| (k, *v)).collect())
- .unwrap_or_default();
+ let required_map: IndexMap<String, PhpMixed> =
+ required.as_array().cloned().unwrap_or_default();
INSTALLED_BY_VENDOR
.lock()
.unwrap()
@@ -515,7 +471,7 @@ impl InstalledVersions {
*installed_static = required
.as_array()
.cloned()
- .map(|m| m.into_iter().map(|(k, v)| (k, *v)).collect());
+ .map(|m| m.into_iter().collect());
} else {
*installed_static = Some(IndexMap::new());
}
diff --git a/crates/shirabe/src/installer.rs b/crates/shirabe/src/installer.rs
index 3e64dd9..31af702 100644
--- a/crates/shirabe/src/installer.rs
+++ b/crates/shirabe/src/installer.rs
@@ -899,7 +899,6 @@ impl Installer {
.cloned()
.unwrap_or_default()
.into_iter()
- .map(|(k, v)| (k, *v))
.collect();
let updated_lock = self.locker.borrow_mut().set_lock_data(
lock_transaction.get_new_lock_packages(false, self.update_mirrors),
@@ -1271,7 +1270,6 @@ impl Installer {
.cloned()
.unwrap_or_default()
.into_iter()
- .map(|(k, v)| (k, *v))
.collect()
} else {
self.locker
diff --git a/crates/shirabe/src/installer/installation_manager.rs b/crates/shirabe/src/installer/installation_manager.rs
index 4d813a5..e149b41 100644
--- a/crates/shirabe/src/installer/installation_manager.rs
+++ b/crates/shirabe/src/installer/installation_manager.rs
@@ -659,9 +659,9 @@ impl InstallationManager {
http.insert("method".to_string(), PhpMixed::String("POST".to_string()));
http.insert(
"header".to_string(),
- PhpMixed::List(vec![Box::new(PhpMixed::String(
+ PhpMixed::List(vec![PhpMixed::String(
"Content-type: application/x-www-form-urlencoded".to_string(),
- ))]),
+ )]),
);
let params_vec: Vec<(&str, &str)> = params
.iter()
@@ -674,9 +674,7 @@ impl InstallationManager {
http.insert("timeout".to_string(), PhpMixed::Int(3));
opts.insert(
"http".to_string(),
- PhpMixed::Array(
- http.into_iter().map(|(k, v)| (k, Box::new(v))).collect(),
- ),
+ PhpMixed::Array(http.into_iter().collect()),
);
tokio::runtime::Runtime::new().unwrap().block_on(
@@ -714,12 +712,7 @@ impl InstallationManager {
}
}
if let Some(PhpMixed::List(downloads)) = post_data.get_mut("downloads") {
- downloads.push(Box::new(PhpMixed::Array(
- package_notification
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- )));
+ downloads.push(PhpMixed::Array(package_notification.into_iter().collect()));
}
}
@@ -729,26 +722,21 @@ impl InstallationManager {
http.insert("method".to_string(), PhpMixed::String("POST".to_string()));
http.insert(
"header".to_string(),
- PhpMixed::List(vec![Box::new(PhpMixed::String(
+ PhpMixed::List(vec![PhpMixed::String(
"Content-Type: application/json".to_string(),
- ))]),
+ )]),
);
http.insert(
"content".to_string(),
PhpMixed::String(
- json_encode(&PhpMixed::Array(
- post_data
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ))
- .unwrap_or_default(),
+ json_encode(&PhpMixed::Array(post_data.into_iter().collect()))
+ .unwrap_or_default(),
),
);
http.insert("timeout".to_string(), PhpMixed::Int(6));
opts.insert(
"http".to_string(),
- PhpMixed::Array(http.into_iter().map(|(k, v)| (k, Box::new(v))).collect()),
+ PhpMixed::Array(http.into_iter().collect()),
);
tokio::runtime::Runtime::new().unwrap().block_on(
diff --git a/crates/shirabe/src/io/base_io.rs b/crates/shirabe/src/io/base_io.rs
index f8e4d32..99c3d70 100644
--- a/crates/shirabe/src/io/base_io.rs
+++ b/crates/shirabe/src/io/base_io.rs
@@ -13,10 +13,10 @@ use shirabe_php_shim::{
UnexpectedValueException, array_merge, in_array, json_encode_ex,
};
-fn log_context(context: &[(&str, &str)]) -> IndexMap<String, Box<PhpMixed>> {
+fn log_context(context: &[(&str, &str)]) -> IndexMap<String, PhpMixed> {
context
.iter()
- .map(|(k, v)| (k.to_string(), Box::new(PhpMixed::String(v.to_string()))))
+ .map(|(k, v)| (k.to_string(), PhpMixed::String(v.to_string())))
.collect()
}
@@ -132,11 +132,11 @@ pub trait BaseIO: IOInterface {
);
let merged = array_merge(
github_domains.unwrap_or(PhpMixed::List(vec![])),
- PhpMixed::List(vec![Box::new(PhpMixed::String(domain.clone()))]),
+ PhpMixed::List(vec![PhpMixed::String(domain.clone())]),
);
let mut inner = IndexMap::new();
- inner.insert("github-domains".to_string(), Box::new(merged));
- let mut config_outer: IndexMap<String, PhpMixed> = IndexMap::new();
+ inner.insert("github-domains".to_string(), merged);
+ let mut config_outer = IndexMap::new();
config_outer.insert("config".to_string(), PhpMixed::Array(inner));
config.merge(&config_outer, "implicit-due-to-auth");
}
@@ -178,10 +178,10 @@ pub trait BaseIO: IOInterface {
);
let merged = array_merge(
gitlab_domains.unwrap_or(PhpMixed::List(vec![])),
- PhpMixed::List(vec![Box::new(PhpMixed::String(domain.clone()))]),
+ PhpMixed::List(vec![PhpMixed::String(domain.clone())]),
);
let mut inner = IndexMap::new();
- inner.insert("gitlab-domains".to_string(), Box::new(merged));
+ inner.insert("gitlab-domains".to_string(), merged);
let mut config_outer: IndexMap<String, PhpMixed> = IndexMap::new();
config_outer.insert("config".to_string(), PhpMixed::Array(inner));
config.merge(&config_outer, "implicit-due-to-auth");
@@ -219,10 +219,10 @@ pub trait BaseIO: IOInterface {
);
let merged = array_merge(
gitlab_domains.unwrap_or(PhpMixed::List(vec![])),
- PhpMixed::List(vec![Box::new(PhpMixed::String(domain.clone()))]),
+ PhpMixed::List(vec![PhpMixed::String(domain.clone())]),
);
let mut inner = IndexMap::new();
- inner.insert("gitlab-domains".to_string(), Box::new(merged));
+ inner.insert("gitlab-domains".to_string(), merged);
let mut config_outer: IndexMap<String, PhpMixed> = IndexMap::new();
config_outer.insert("config".to_string(), PhpMixed::Array(inner));
config.merge(&config_outer, "implicit-due-to-auth");
@@ -267,10 +267,10 @@ pub trait BaseIO: IOInterface {
);
let merged = array_merge(
forgejo_domains.unwrap_or(PhpMixed::List(vec![])),
- PhpMixed::List(vec![Box::new(PhpMixed::String(domain.clone()))]),
+ PhpMixed::List(vec![PhpMixed::String(domain.clone())]),
);
let mut inner = IndexMap::new();
- inner.insert("forgejo-domains".to_string(), Box::new(merged));
+ inner.insert("forgejo-domains".to_string(), merged);
let mut config_outer: IndexMap<String, PhpMixed> = IndexMap::new();
config_outer.insert("config".to_string(), PhpMixed::Array(inner));
config.merge(&config_outer, "implicit-due-to-auth");
@@ -344,17 +344,15 @@ pub trait BaseIO: IOInterface {
.and_then(|v| v.as_string())
.map(|s| s.to_string());
- let mut ssl_options: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
+ let mut ssl_options = IndexMap::new();
if let Some(cert) = local_cert {
- ssl_options
- .insert("local_cert".to_string(), Box::new(PhpMixed::String(cert)));
+ ssl_options.insert("local_cert".to_string(), PhpMixed::String(cert));
}
if let Some(pk) = local_pk {
- ssl_options.insert("local_pk".to_string(), Box::new(PhpMixed::String(pk)));
+ ssl_options.insert("local_pk".to_string(), PhpMixed::String(pk));
}
if let Some(pass) = passphrase {
- ssl_options
- .insert("passphrase".to_string(), Box::new(PhpMixed::String(pass)));
+ ssl_options.insert("passphrase".to_string(), PhpMixed::String(pass));
}
if !ssl_options.contains_key("local_cert") {
@@ -465,10 +463,10 @@ pub trait BaseIO: IOInterface {
if in_array(
level.clone(),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String(LogLevel::EMERGENCY.to_string())),
- Box::new(PhpMixed::String(LogLevel::ALERT.to_string())),
- Box::new(PhpMixed::String(LogLevel::CRITICAL.to_string())),
- Box::new(PhpMixed::String(LogLevel::ERROR.to_string())),
+ PhpMixed::String(LogLevel::EMERGENCY.to_string()),
+ PhpMixed::String(LogLevel::ALERT.to_string()),
+ PhpMixed::String(LogLevel::CRITICAL.to_string()),
+ PhpMixed::String(LogLevel::ERROR.to_string()),
]),
false,
) {
diff --git a/crates/shirabe/src/io/console_io.rs b/crates/shirabe/src/io/console_io.rs
index e061401..25ec02d 100644
--- a/crates/shirabe/src/io/console_io.rs
+++ b/crates/shirabe/src/io/console_io.rs
@@ -117,12 +117,7 @@ impl ConsoleIO {
)
})
.collect();
- PhpMixed::List(
- mapped
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
- )
+ PhpMixed::List(mapped.into_iter().map(PhpMixed::String).collect())
} else {
messages
};
@@ -326,12 +321,7 @@ impl ConsoleIO {
_ => {}
}
- PhpMixed::Array(
- sanitized
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- )
+ PhpMixed::Array(sanitized.into_iter().collect())
}
/// Ensures a string is valid UTF-8, replacing invalid byte sequences with '?'
@@ -576,12 +566,7 @@ impl IOInterfaceImmutable for ConsoleIO {
error_message: String,
multiselect: bool,
) -> PhpMixed {
- let choices: PhpMixed = PhpMixed::List(
- choices
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
- );
+ let choices: PhpMixed = PhpMixed::List(choices.into_iter().map(PhpMixed::String).collect());
let _helper = self
.helper_set
.get("question")
@@ -590,17 +575,17 @@ impl IOInterfaceImmutable for ConsoleIO {
.as_string()
.unwrap_or("")
.to_string();
- // ChoiceQuestion::new expects an IndexMap<String, Box<PhpMixed>>; project the
+ // ChoiceQuestion::new expects an IndexMap<String, PhpMixed>; project the
// sanitized choice list/map into the keyed form, preserving keys.
let sanitized_choices_mixed = Self::sanitize(choices.clone(), true);
- let sanitized_choices: IndexMap<String, Box<PhpMixed>> = match sanitized_choices_mixed {
+ let sanitized_choices: IndexMap<String, PhpMixed> = match sanitized_choices_mixed {
PhpMixed::List(l) => l
.into_iter()
.enumerate()
.map(|(i, b)| (i.to_string(), b))
.collect(),
PhpMixed::Array(a) => a,
- other => indexmap! { "0".to_string() => Box::new(other) },
+ other => indexmap! { "0".to_string() => other },
};
let sanitized_default = if is_string(&default) {
Some(Self::sanitize(default, true))
@@ -657,14 +642,14 @@ impl IOInterfaceImmutable for ConsoleIO {
}
let mut results: Vec<String> = vec![];
- let result_list = result.as_list().cloned().unwrap_or_default();
+ let result_list: Vec<PhpMixed> = result.as_list().cloned().unwrap_or_default();
let choice_list: Vec<(String, PhpMixed)> = match &choices {
PhpMixed::List(l) => l
.iter()
.enumerate()
- .map(|(i, v)| (i.to_string(), (**v).clone()))
+ .map(|(i, v)| (i.to_string(), v.clone()))
.collect(),
- PhpMixed::Array(a) => a.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect(),
+ PhpMixed::Array(a) => a.iter().map(|(k, v)| (k.clone(), v.clone())).collect(),
_ => vec![],
};
for (index, choice) in &choice_list {
@@ -673,12 +658,7 @@ impl IOInterfaceImmutable for ConsoleIO {
}
}
- PhpMixed::List(
- results
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
- )
+ PhpMixed::List(results.into_iter().map(PhpMixed::String).collect())
}
fn get_authentications(&self) -> IndexMap<String, IndexMap<String, Option<String>>> {
diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs
index 22b104b..167a163 100644
--- a/crates/shirabe/src/json/json_file.rs
+++ b/crates/shirabe/src/json/json_file.rs
@@ -352,15 +352,10 @@ impl JsonFile {
// A string-keyed `PhpMixed::Array` serializes as a JSON object, matching the (object) cast.
let mut schema_data: PhpMixed = {
let mut m = indexmap::IndexMap::new();
- m.insert(
- "$ref".to_string(),
- Box::new(PhpMixed::String(schema_file.clone())),
- );
+ m.insert("$ref".to_string(), PhpMixed::String(schema_file.clone()));
m.insert(
"$schema".to_string(),
- Box::new(PhpMixed::String(
- "https://json-schema.org/draft-04/schema#".to_string(),
- )),
+ PhpMixed::String("https://json-schema.org/draft-04/schema#".to_string()),
);
PhpMixed::Array(m)
};
@@ -368,32 +363,24 @@ impl JsonFile {
if schema == Self::STRICT_SCHEMA && is_composer_schema_file {
schema_data = json_decode(&file_get_contents(&schema_file).unwrap_or_default(), false)?;
if let PhpMixed::Array(map) = &mut schema_data {
- map.insert(
- "additionalProperties".to_string(),
- Box::new(PhpMixed::Bool(false)),
- );
+ map.insert("additionalProperties".to_string(), PhpMixed::Bool(false));
map.insert(
"required".to_string(),
- Box::new(PhpMixed::List(vec![
- Box::new(PhpMixed::String("name".to_string())),
- Box::new(PhpMixed::String("description".to_string())),
- ])),
+ PhpMixed::List(vec![
+ PhpMixed::String("name".to_string()),
+ PhpMixed::String("description".to_string()),
+ ]),
);
}
} else if schema == Self::AUTH_SCHEMA && is_composer_schema_file {
let mut m = indexmap::IndexMap::new();
m.insert(
"$ref".to_string(),
- Box::new(PhpMixed::String(format!(
- "{}#/properties/config",
- schema_file,
- ))),
+ PhpMixed::String(format!("{}#/properties/config", schema_file,)),
);
m.insert(
"$schema".to_string(),
- Box::new(PhpMixed::String(
- "https://json-schema.org/draft-04/schema#".to_string(),
- )),
+ PhpMixed::String("https://json-schema.org/draft-04/schema#".to_string()),
);
schema_data = PhpMixed::Array(m);
}
diff --git a/crates/shirabe/src/json/json_manipulator.rs b/crates/shirabe/src/json/json_manipulator.rs
index a753c93..75f933c 100644
--- a/crates/shirabe/src/json/json_manipulator.rs
+++ b/crates/shirabe/src/json/json_manipulator.rs
@@ -76,10 +76,10 @@ impl JsonManipulator {
// no link of that type yet
if decoded.as_array().and_then(|a| a.get(r#type)).is_none() {
- let mut arr: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
+ let mut arr: IndexMap<String, PhpMixed> = IndexMap::new();
arr.insert(
package.to_string(),
- Box::new(PhpMixed::String(constraint.to_string())),
+ PhpMixed::String(constraint.to_string()),
);
return self.add_main_key(r#type, PhpMixed::Array(arr));
}
@@ -228,11 +228,8 @@ impl JsonManipulator {
&& !name.is_empty()
{
// PHP: ['name' => $name] + $config — preserve $config keys
- let mut merged: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- merged.insert(
- "name".to_string(),
- Box::new(PhpMixed::String(name.to_string())),
- );
+ let mut merged: IndexMap<String, PhpMixed> = IndexMap::new();
+ merged.insert("name".to_string(), PhpMixed::String(name.to_string()));
if let Some(arr) = config.as_array() {
for (k, v) in arr {
if !merged.contains_key(k) {
@@ -242,8 +239,8 @@ impl JsonManipulator {
}
PhpMixed::Array(merged)
} else if config.as_bool() == Some(false) {
- let mut m: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- m.insert(name.to_string(), Box::new(PhpMixed::Bool(false)));
+ let mut m: IndexMap<String, PhpMixed> = IndexMap::new();
+ m.insert(name.to_string(), PhpMixed::Bool(false));
PhpMixed::Array(m)
} else {
config
@@ -255,17 +252,17 @@ impl JsonManipulator {
fn do_convert_repositories_from_assoc_to_list(&mut self) -> anyhow::Result<bool> {
let decoded = json_decode(&self.contents, false)?;
- let repositories_value: Option<Box<PhpMixed>> = decoded
+ let repositories_value: Option<PhpMixed> = decoded
.as_object()
.and_then(|o| o.to_array().get("repositories").cloned());
let is_std_class = repositories_value
.as_ref()
- .map(|v| (&**v as &dyn std::any::Any).is::<StdClass>())
+ .map(|v| (v as &dyn std::any::Any).is::<StdClass>())
.unwrap_or(false);
if is_std_class {
// delete from bottom to top, to ensure keys stay the same
- let repos_arr: IndexMap<String, Box<PhpMixed>> = repositories_value
+ let repos_arr: IndexMap<String, PhpMixed> = repositories_value
.as_ref()
.and_then(|v| v.as_array().cloned())
.unwrap_or_default();
@@ -281,25 +278,25 @@ impl JsonManipulator {
// re-add in order
for (repository_name, repository) in &repos_arr {
- let is_obj = (&**repository as &dyn std::any::Any).is::<StdClass>();
+ let is_obj = (repository as &dyn std::any::Any).is::<StdClass>();
if !is_obj {
- let mut m: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
+ let mut m: IndexMap<String, PhpMixed> = IndexMap::new();
m.insert(repository_name.clone(), repository.clone());
if !self.add_list_item("repositories", PhpMixed::Array(m), true)? {
return Ok(false);
}
} else if is_numeric(&PhpMixed::String(repository_name.clone())) {
- if !self.add_list_item("repositories", (**repository).clone(), true)? {
+ if !self.add_list_item("repositories", repository.clone(), true)? {
return Ok(false);
}
} else {
- let repo: IndexMap<String, Box<PhpMixed>> =
+ let repo: IndexMap<String, PhpMixed> =
repository.as_array().cloned().unwrap_or_default();
// prepend name property
- let mut prepended: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
+ let mut prepended: IndexMap<String, PhpMixed> = IndexMap::new();
prepended.insert(
"name".to_string(),
- Box::new(PhpMixed::String(repository_name.clone())),
+ PhpMixed::String(repository_name.clone()),
);
for (k, v) in &repo {
if !prepended.contains_key(k) {
@@ -468,11 +465,8 @@ impl JsonManipulator {
&& !is_numeric(&PhpMixed::String(name.to_string()))
&& !name.is_empty()
{
- let mut merged: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- merged.insert(
- "name".to_string(),
- Box::new(PhpMixed::String(name.to_string())),
- );
+ let mut merged: IndexMap<String, PhpMixed> = IndexMap::new();
+ merged.insert("name".to_string(), PhpMixed::String(name.to_string()));
if let Some(arr) = config.as_array() {
for (k, v) in arr {
if !merged.contains_key(k) {
@@ -482,8 +476,8 @@ impl JsonManipulator {
}
PhpMixed::Array(merged)
} else if config.as_bool() == Some(false) {
- let mut m: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- m.insert("name".to_string(), Box::new(PhpMixed::Bool(false)));
+ let mut m: IndexMap<String, PhpMixed> = IndexMap::new();
+ m.insert("name".to_string(), PhpMixed::Bool(false));
PhpMixed::Array(m)
} else {
config
@@ -498,15 +492,15 @@ impl JsonManipulator {
fn do_remove_repository(&mut self, name: &str) -> anyhow::Result<bool> {
let decoded = json_decode(&self.contents, false)?;
- let repositories_value: Option<Box<PhpMixed>> = decoded
+ let repositories_value: Option<PhpMixed> = decoded
.as_object()
.and_then(|o| o.to_array().get("repositories").cloned());
let is_assoc = repositories_value
.as_ref()
- .map(|v| (&**v as &dyn std::any::Any).is::<StdClass>())
+ .map(|v| (v as &dyn std::any::Any).is::<StdClass>())
.unwrap_or(false);
- let repos: IndexMap<String, Box<PhpMixed>> = repositories_value
+ let repos: IndexMap<String, PhpMixed> = repositories_value
.as_ref()
.and_then(|v| v.as_array().cloned())
.unwrap_or_default();
@@ -548,7 +542,7 @@ impl JsonManipulator {
return Ok(true);
}
} else {
- let repository_as_array: IndexMap<String, Box<PhpMixed>> =
+ let repository_as_array: IndexMap<String, PhpMixed> =
repository.as_array().cloned().unwrap_or_default();
if repository_as_array
@@ -632,9 +626,9 @@ impl JsonManipulator {
if in_array(
PhpMixed::String(main_node.to_string()),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("config".to_string())),
- Box::new(PhpMixed::String("extra".to_string())),
- Box::new(PhpMixed::String("scripts".to_string())),
+ PhpMixed::String("config".to_string()),
+ PhpMixed::String("extra".to_string()),
+ PhpMixed::String("scripts".to_string()),
]),
false,
) && strpos(name, ".").is_some()
@@ -650,14 +644,14 @@ impl JsonManipulator {
// no main node yet
if decoded.as_array().and_then(|a| a.get(main_node)).is_none() {
if let Some(ref sub) = sub_name {
- let mut inner: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- inner.insert(sub.clone(), Box::new(value.clone()));
- let mut outer: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- outer.insert(name_owned.clone(), Box::new(PhpMixed::Array(inner)));
+ let mut inner: IndexMap<String, PhpMixed> = IndexMap::new();
+ inner.insert(sub.clone(), value.clone());
+ let mut outer: IndexMap<String, PhpMixed> = IndexMap::new();
+ outer.insert(name_owned.clone(), PhpMixed::Array(inner));
self.add_main_key(main_node, PhpMixed::Array(outer))?;
} else {
- let mut outer: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- outer.insert(name_owned.clone(), Box::new(value.clone()));
+ let mut outer: IndexMap<String, PhpMixed> = IndexMap::new();
+ outer.insert(name_owned.clone(), value.clone());
self.add_main_key(main_node, PhpMixed::Array(outer))?;
}
@@ -712,10 +706,7 @@ impl JsonManipulator {
cur_val = PhpMixed::Array(IndexMap::new());
}
if let Some(arr) = cur_val.as_array_mut() {
- arr.insert(
- sub_name_capture.clone().unwrap(),
- Box::new(value_local.clone()),
- );
+ arr.insert(sub_name_capture.clone().unwrap(), value_local.clone());
}
value_local = cur_val;
}
@@ -748,8 +739,8 @@ impl JsonManipulator {
if content_present {
let mut value_local = value.clone();
if let Some(ref sub) = sub_name {
- let mut wrap: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- wrap.insert(sub.clone(), Box::new(value_local.clone()));
+ let mut wrap: IndexMap<String, PhpMixed> = IndexMap::new();
+ wrap.insert(sub.clone(), value_local.clone());
value_local = PhpMixed::Array(wrap);
}
@@ -793,8 +784,8 @@ impl JsonManipulator {
} else {
let mut value_local = value.clone();
if let Some(ref sub) = sub_name {
- let mut wrap: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- wrap.insert(sub.clone(), Box::new(value_local.clone()));
+ let mut wrap: IndexMap<String, PhpMixed> = IndexMap::new();
+ wrap.insert(sub.clone(), value_local.clone());
value_local = PhpMixed::Array(wrap);
}
@@ -844,7 +835,7 @@ impl JsonManipulator {
// no node or empty node
let main_node_value = decoded.as_array().and_then(|a| a.get(main_node));
- if main_node_value.map(|v| empty(v.as_ref())).unwrap_or(true) {
+ if main_node_value.map(|v| empty(v)).unwrap_or(true) {
return Ok(true);
}
@@ -873,9 +864,9 @@ impl JsonManipulator {
if in_array(
PhpMixed::String(main_node.to_string()),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("config".to_string())),
- Box::new(PhpMixed::String("extra".to_string())),
- Box::new(PhpMixed::String("scripts".to_string())),
+ PhpMixed::String("config".to_string()),
+ PhpMixed::String("extra".to_string()),
+ PhpMixed::String("scripts".to_string()),
]),
false,
) && strpos(name, ".").is_some()
@@ -1005,16 +996,13 @@ impl JsonManipulator {
.map(|a| a.is_empty())
.unwrap_or(false);
if now_empty {
- arr.insert(
- name_owned.clone(),
- Box::new(PhpMixed::Object(ArrayObject::new(None))),
- );
+ arr.insert(name_owned.clone(), PhpMixed::Object(ArrayObject::new(None)));
}
}
let val = cur_val
.as_array()
.and_then(|a| a.get(&name_owned))
- .map(|v| (**v).clone())
+ .cloned()
.unwrap_or(PhpMixed::Null);
self.add_sub_node(main_node, &name_owned, val, true)?;
}
@@ -1056,7 +1044,7 @@ impl JsonManipulator {
if now_empty {
arr.insert(
name_capture.clone(),
- Box::new(PhpMixed::Object(ArrayObject::new(None))),
+ PhpMixed::Object(ArrayObject::new(None)),
);
}
}
@@ -1327,7 +1315,7 @@ impl JsonManipulator {
// no node or empty node
let main_node_value = decoded.as_array().and_then(|a| a.get(main_node));
- if main_node_value.map(|v| empty(v.as_ref())).unwrap_or(true) {
+ if main_node_value.map(|v| empty(v)).unwrap_or(true) {
return Ok(true);
}
@@ -1566,10 +1554,7 @@ impl JsonManipulator {
return Ok(true);
}
- let value = decoded_arr
- .get(key)
- .map(|v| (**v).clone())
- .unwrap_or(PhpMixed::Null);
+ let value = decoded_arr.get(key).cloned().unwrap_or(PhpMixed::Null);
if is_array(&value) && value.as_array().map(|a| a.len()).unwrap_or(0) == 0 {
return self.remove_main_key(key);
}
@@ -1585,7 +1570,7 @@ impl JsonManipulator {
{
// PHP: (array) $data — coerce to array
if let Some(obj) = data.as_object() {
- data = PhpMixed::Array(obj.to_array());
+ data = PhpMixed::Array(obj.to_array().into_iter().collect());
}
was_object = true;
}
@@ -1658,7 +1643,7 @@ impl ManipulatorFormatter {
|| (&data as &dyn std::any::Any).is::<ArrayObject>()
{
if let Some(obj) = data.as_object() {
- data = PhpMixed::Array(obj.to_array());
+ data = PhpMixed::Array(obj.to_array().into_iter().collect());
}
was_object = true;
}
diff --git a/crates/shirabe/src/package/alias_package.rs b/crates/shirabe/src/package/alias_package.rs
index 657b007..c0e71ec 100644
--- a/crates/shirabe/src/package/alias_package.rs
+++ b/crates/shirabe/src/package/alias_package.rs
@@ -135,9 +135,9 @@ impl AliasPackage {
if in_array(
PhpMixed::String(link_type.to_string()),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String(Link::TYPE_CONFLICT.to_string())),
- Box::new(PhpMixed::String(Link::TYPE_PROVIDE.to_string())),
- Box::new(PhpMixed::String(Link::TYPE_REPLACE.to_string())),
+ PhpMixed::String(Link::TYPE_CONFLICT.to_string()),
+ PhpMixed::String(Link::TYPE_PROVIDE.to_string()),
+ PhpMixed::String(Link::TYPE_REPLACE.to_string()),
]),
true,
) {
diff --git a/crates/shirabe/src/package/dumper/array_dumper.rs b/crates/shirabe/src/package/dumper/array_dumper.rs
index 7bf62f2..ec33340 100644
--- a/crates/shirabe/src/package/dumper/array_dumper.rs
+++ b/crates/shirabe/src/package/dumper/array_dumper.rs
@@ -9,12 +9,9 @@ use crate::package::SUPPORTED_LINK_TYPES;
/// Serializes a Mirror back into the PHP array shape `{url, preferred}`.
fn mirror_to_php(mirror: Mirror) -> PhpMixed {
- let mut entry: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- entry.insert("url".to_string(), Box::new(PhpMixed::String(mirror.url)));
- entry.insert(
- "preferred".to_string(),
- Box::new(PhpMixed::Bool(mirror.preferred)),
- );
+ let mut entry: IndexMap<String, PhpMixed> = IndexMap::new();
+ entry.insert("url".to_string(), PhpMixed::String(mirror.url));
+ entry.insert("preferred".to_string(), PhpMixed::Bool(mirror.preferred));
PhpMixed::Array(entry)
}
@@ -55,21 +52,19 @@ impl ArrayDumper {
}
if let Some(source_type) = package.get_source_type() {
- let mut source: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
+ let mut source = IndexMap::new();
source.insert(
"type".to_string(),
- Box::new(PhpMixed::String(source_type.to_string())),
+ PhpMixed::String(source_type.to_string()),
);
source.insert(
"url".to_string(),
- Box::new(PhpMixed::String(
- package.get_source_url().unwrap_or_default(),
- )),
+ PhpMixed::String(package.get_source_url().unwrap_or_default()),
);
if let Some(reference) = package.get_source_reference() {
source.insert(
"reference".to_string(),
- Box::new(PhpMixed::String(reference.to_string())),
+ PhpMixed::String(reference.to_string()),
);
}
if let Some(mirrors) = package.get_source_mirrors()
@@ -77,52 +72,46 @@ impl ArrayDumper {
{
source.insert(
"mirrors".to_string(),
- Box::new(PhpMixed::Array(
+ PhpMixed::Array(
mirrors
.into_iter()
.enumerate()
- .map(|(i, m)| (i.to_string(), Box::new(mirror_to_php(m))))
+ .map(|(i, m)| (i.to_string(), mirror_to_php(m)))
.collect(),
- )),
+ ),
);
}
data.insert("source".to_string(), PhpMixed::Array(source));
}
if let Some(dist_type) = package.get_dist_type() {
- let mut dist: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- dist.insert(
- "type".to_string(),
- Box::new(PhpMixed::String(dist_type.to_string())),
- );
+ let mut dist: IndexMap<String, PhpMixed> = IndexMap::new();
+ dist.insert("type".to_string(), PhpMixed::String(dist_type.to_string()));
dist.insert(
"url".to_string(),
- Box::new(PhpMixed::String(package.get_dist_url().unwrap_or_default())),
+ PhpMixed::String(package.get_dist_url().unwrap_or_default()),
);
if let Some(reference) = package.get_dist_reference() {
dist.insert(
"reference".to_string(),
- Box::new(PhpMixed::String(reference.to_string())),
+ PhpMixed::String(reference.to_string()),
);
}
if let Some(shasum) = package.get_dist_sha1_checksum() {
- dist.insert(
- "shasum".to_string(),
- Box::new(PhpMixed::String(shasum.to_string())),
- );
+ dist.insert("shasum".to_string(), PhpMixed::String(shasum.to_string()));
}
if let Some(mirrors) = package.get_dist_mirrors()
&& !mirrors.is_empty()
{
dist.insert(
"mirrors".to_string(),
- Box::new(PhpMixed::Array(
+ PhpMixed::Array(
mirrors
.into_iter()
.enumerate()
- .map(|(i, m)| (i.to_string(), Box::new(mirror_to_php(m))))
+ .map(|(i, m)| (i.to_string(), mirror_to_php(m)))
.collect(),
- )),
+ ),
);
}
data.insert("dist".to_string(), PhpMixed::Array(dist));
@@ -133,11 +122,11 @@ impl ArrayDumper {
if links.is_empty() {
continue;
}
- let mut link_map: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
+ let mut link_map: IndexMap<String, PhpMixed> = IndexMap::new();
for link in links.values() {
link_map.insert(
link.get_target().to_string(),
- Box::new(PhpMixed::String(link.get_pretty_constraint().to_string())),
+ PhpMixed::String(link.get_pretty_constraint().to_string()),
);
}
link_map.sort_keys();
@@ -153,7 +142,7 @@ impl ArrayDumper {
PhpMixed::Array(
sorted_suggests
.into_iter()
- .map(|(k, v)| (k, Box::new(PhpMixed::String(v))))
+ .map(|(k, v)| (k, PhpMixed::String(v)))
.collect(),
),
);
@@ -175,12 +164,7 @@ impl ArrayDumper {
if !binaries.is_empty() {
data.insert(
"bin".to_string(),
- PhpMixed::List(
- binaries
- .into_iter()
- .map(|b| Box::new(PhpMixed::String(b)))
- .collect(),
- ),
+ PhpMixed::List(binaries.into_iter().map(PhpMixed::String).collect()),
);
}
let pkg_type = package.get_type();
@@ -191,7 +175,7 @@ impl ArrayDumper {
if !extra.is_empty() {
data.insert(
"extra".to_string(),
- PhpMixed::Array(extra.into_iter().map(|(k, v)| (k, Box::new(v))).collect()),
+ PhpMixed::Array(extra.into_iter().collect()),
);
}
if let Some(installation_source) = package.get_installation_source() {
@@ -204,24 +188,14 @@ impl ArrayDumper {
if !autoload.is_empty() {
data.insert(
"autoload".to_string(),
- PhpMixed::Array(
- autoload
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
+ PhpMixed::Array(autoload.into_iter().collect()),
);
}
let dev_autoload = package.get_dev_autoload();
if !dev_autoload.is_empty() {
data.insert(
"autoload-dev".to_string(),
- PhpMixed::Array(
- dev_autoload
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
+ PhpMixed::Array(dev_autoload.into_iter().collect()),
);
}
if let Some(notification_url) = package.get_notification_url() {
@@ -234,12 +208,7 @@ impl ArrayDumper {
if !include_paths.is_empty() {
data.insert(
"include-path".to_string(),
- PhpMixed::List(
- include_paths
- .into_iter()
- .map(|p| Box::new(PhpMixed::String(p)))
- .collect(),
- ),
+ PhpMixed::List(include_paths.into_iter().map(PhpMixed::String).collect()),
);
}
let php_ext = package.get_php_ext();
@@ -249,7 +218,7 @@ impl ArrayDumper {
PhpMixed::Array(
php_ext
.iter()
- .map(|(k, v)| (k.clone(), Box::new(v.clone())))
+ .map(|(k, v)| (k.clone(), v.clone()))
.collect(),
),
);
@@ -263,7 +232,7 @@ impl ArrayDumper {
if let PhpMixed::Array(archive) = entry {
archive.insert(
"name".to_string(),
- Box::new(PhpMixed::String(archive_name.to_string())),
+ PhpMixed::String(archive_name.to_string()),
);
}
}
@@ -275,12 +244,9 @@ impl ArrayDumper {
if let PhpMixed::Array(archive) = entry {
archive.insert(
"exclude".to_string(),
- Box::new(PhpMixed::List(
- archive_excludes
- .into_iter()
- .map(|e| Box::new(PhpMixed::String(e)))
- .collect(),
- )),
+ PhpMixed::List(
+ archive_excludes.into_iter().map(PhpMixed::String).collect(),
+ ),
);
}
}
@@ -296,11 +262,7 @@ impl ArrayDumper {
.map(|(k, v)| {
(
k,
- Box::new(PhpMixed::List(
- v.into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
- )),
+ PhpMixed::List(v.into_iter().map(PhpMixed::String).collect()),
)
})
.collect(),
@@ -311,12 +273,7 @@ impl ArrayDumper {
if !license.is_empty() {
data.insert(
"license".to_string(),
- PhpMixed::List(
- license
- .into_iter()
- .map(|l| Box::new(PhpMixed::String(l)))
- .collect(),
- ),
+ PhpMixed::List(license.into_iter().map(PhpMixed::String).collect()),
);
}
let authors = complete_pkg.get_authors();
@@ -327,11 +284,11 @@ impl ArrayDumper {
authors
.into_iter()
.map(|a| {
- Box::new(PhpMixed::Array(
+ PhpMixed::Array(
a.into_iter()
- .map(|(k, v)| (k, Box::new(PhpMixed::String(v))))
+ .map(|(k, v)| (k, PhpMixed::String(v)))
.collect(),
- ))
+ )
})
.collect(),
),
@@ -354,24 +311,14 @@ impl ArrayDumper {
keywords.sort();
data.insert(
"keywords".to_string(),
- PhpMixed::List(
- keywords
- .into_iter()
- .map(|k| Box::new(PhpMixed::String(k)))
- .collect(),
- ),
+ PhpMixed::List(keywords.into_iter().map(PhpMixed::String).collect()),
);
}
let repositories = complete_pkg.get_repositories();
if !repositories.is_empty() {
data.insert(
"repositories".to_string(),
- PhpMixed::Array(
- repositories
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
+ PhpMixed::Array(repositories.into_iter().collect()),
);
}
let support = complete_pkg.get_support();
@@ -381,7 +328,7 @@ impl ArrayDumper {
PhpMixed::Array(
support
.into_iter()
- .map(|(k, v)| (k, Box::new(PhpMixed::String(v))))
+ .map(|(k, v)| (k, PhpMixed::String(v)))
.collect(),
),
);
@@ -393,11 +340,7 @@ impl ArrayDumper {
PhpMixed::List(
funding
.into_iter()
- .map(|f| {
- Box::new(PhpMixed::Array(
- f.into_iter().map(|(k, v)| (k, Box::new(v))).collect(),
- ))
- })
+ .map(|f| PhpMixed::Array(f.into_iter().collect()))
.collect(),
),
);
@@ -426,12 +369,7 @@ impl ArrayDumper {
if !transport_options.is_empty() {
data.insert(
"transport-options".to_string(),
- PhpMixed::Array(
- transport_options
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
+ PhpMixed::Array(transport_options.into_iter().collect()),
);
}
diff --git a/crates/shirabe/src/package/loader/array_loader.rs b/crates/shirabe/src/package/loader/array_loader.rs
index 889624d..0411645 100644
--- a/crates/shirabe/src/package/loader/array_loader.rs
+++ b/crates/shirabe/src/package/loader/array_loader.rs
@@ -92,14 +92,14 @@ impl CompleteOrRootPackage {
fn php_to_map(value: &PhpMixed) -> IndexMap<String, PhpMixed> {
match value {
- PhpMixed::Array(m) => m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect(),
+ PhpMixed::Array(m) => m.clone(),
_ => IndexMap::new(),
}
}
fn php_to_string_vec(value: &PhpMixed) -> Vec<String> {
match value {
- PhpMixed::List(l) => l.iter().map(|v| strval(v)).collect(),
+ PhpMixed::List(l) => l.iter().map(strval).collect(),
PhpMixed::Array(m) => m.values().map(|v| strval(v)).collect(),
_ => Vec::new(),
}
@@ -121,8 +121,8 @@ fn apply_link_setter(package: &mut Package, method: &str, links: IndexMap<String
fn php_to_mirrors(value: &PhpMixed) -> Vec<Mirror> {
let entries: Vec<&PhpMixed> = match value {
- PhpMixed::List(l) => l.iter().map(|v| v.as_ref()).collect(),
- PhpMixed::Array(m) => m.values().map(|v| v.as_ref()).collect(),
+ PhpMixed::List(l) => l.iter().collect(),
+ PhpMixed::Array(m) => m.values().collect(),
_ => Vec::new(),
};
entries
@@ -180,10 +180,7 @@ impl LoaderInterface for ArrayLoader {
package.get_pretty_version(),
opts.method,
match entry.unwrap() {
- PhpMixed::Array(arr) => arr
- .iter()
- .map(|(k, v)| (k.clone(), (**v).clone()))
- .collect(),
+ PhpMixed::Array(arr) => arr.clone(),
_ => IndexMap::new(),
},
)?;
@@ -231,13 +228,7 @@ impl ArrayLoader {
return Err(UnexpectedValueException {
message: format!(
"Unknown package has no name defined ({}).",
- json_encode(&PhpMixed::Array(
- config
- .iter()
- .map(|(k, v)| (k.clone(), Box::new(v.clone())))
- .collect(),
- ))
- .unwrap_or_default()
+ json_encode(&PhpMixed::Array(config.clone())).unwrap_or_default()
),
code: 0,
}
@@ -347,18 +338,18 @@ impl ArrayLoader {
if let Some(bin) = config.get("bin").cloned() {
let mut bin_list = match bin {
PhpMixed::Array(_) | PhpMixed::List(_) => bin,
- other => PhpMixed::List(vec![Box::new(other)]),
+ other => PhpMixed::List(vec![other]),
};
if let PhpMixed::List(ref mut list) = bin_list {
for item in list.iter_mut() {
if let Some(s) = item.as_string() {
- **item = 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 = PhpMixed::String(ltrim(s, Some("/")));
+ *v = PhpMixed::String(ltrim(s, Some("/")));
}
}
}
@@ -477,7 +468,7 @@ impl ArrayLoader {
if let Some(r) = reason.as_string()
&& trim(r, None) == "self.version"
{
- **reason = PhpMixed::String(package.get_pretty_version().to_string());
+ *reason = PhpMixed::String(package.get_pretty_version().to_string());
let _ = target;
}
}
@@ -553,9 +544,9 @@ impl ArrayLoader {
&& let PhpMixed::Array(mut scripts_map) = scripts
{
for (event, listeners) in scripts_map.iter_mut() {
- let listeners_array = match listeners.as_ref() {
+ let listeners_array = match &*listeners {
PhpMixed::Array(_) | PhpMixed::List(_) => listeners.clone(),
- other => Box::new(PhpMixed::List(vec![Box::new(other.clone())])),
+ other => PhpMixed::List(vec![other.clone()]),
};
*listeners = listeners_array;
let _ = event;
@@ -602,7 +593,7 @@ impl ArrayLoader {
&& matches!(keywords, PhpMixed::Array(_) | PhpMixed::List(_))
{
let keywords_vec: Vec<String> = match keywords {
- PhpMixed::List(list) => list.iter().map(|v| strval(v)).collect(),
+ PhpMixed::List(list) => list.iter().map(strval).collect(),
PhpMixed::Array(map) => map.values().map(|v| strval(v)).collect(),
_ => vec![],
};
@@ -632,7 +623,7 @@ impl ArrayLoader {
{
let authors_vec: Vec<IndexMap<String, String>> = list
.iter()
- .filter_map(|v| match v.as_ref() {
+ .filter_map(|v| match v {
PhpMixed::Array(m) => Some(
m.iter()
.map(|(k, v)| (k.clone(), v.as_string().unwrap_or("").to_string()))
@@ -660,10 +651,8 @@ impl ArrayLoader {
{
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())
- }
+ .filter_map(|v| match v {
+ PhpMixed::Array(m) => Some(m.clone()),
_ => None,
})
.collect();
@@ -722,9 +711,7 @@ impl ArrayLoader {
if let Some(entry) = config.get(*r#type) {
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.clone(),
_ => continue,
};
for (pretty_target, constraint) in entries {
@@ -892,8 +879,8 @@ impl ArrayLoader {
PhpMixed::Array(m) => m.get("branch-alias").cloned(),
_ => None,
})
- .and_then(|v| match v.as_ref() {
- PhpMixed::Array(m) => Some(m.clone()),
+ .and_then(|v| match v {
+ PhpMixed::Array(m) => Some(m),
_ => None,
});
diff --git a/crates/shirabe/src/package/loader/json_loader.rs b/crates/shirabe/src/package/loader/json_loader.rs
index fa0e914..d48a2fe 100644
--- a/crates/shirabe/src/package/loader/json_loader.rs
+++ b/crates/shirabe/src/package/loader/json_loader.rs
@@ -33,7 +33,7 @@ impl JsonLoader {
};
let config: IndexMap<String, PhpMixed> = match config {
- PhpMixed::Array(m) => m.into_iter().map(|(k, v)| (k, *v)).collect(),
+ PhpMixed::Array(m) => m,
_ => {
return Err(TypeError {
message: "Composer\\Package\\Loader\\LoaderInterface::load(): Argument #1 ($config) must be of type array".to_string(),
diff --git a/crates/shirabe/src/package/loader/root_package_loader.rs b/crates/shirabe/src/package/loader/root_package_loader.rs
index 2d3bd0a..50374d2 100644
--- a/crates/shirabe/src/package/loader/root_package_loader.rs
+++ b/crates/shirabe/src/package/loader/root_package_loader.rs
@@ -129,27 +129,18 @@ impl RootPackageLoader {
if let Some(commit_hash) = commit {
let mut source = IndexMap::new();
- source.insert(
- "type".to_string(),
- Box::new(PhpMixed::String(String::new())),
- );
- source.insert("url".to_string(), Box::new(PhpMixed::String(String::new())));
+ source.insert("type".to_string(), PhpMixed::String(String::new()));
+ source.insert("url".to_string(), PhpMixed::String(String::new()));
source.insert(
"reference".to_string(),
- Box::new(PhpMixed::String(commit_hash.clone())),
+ PhpMixed::String(commit_hash.clone()),
);
config.insert("source".to_string(), PhpMixed::Array(source));
let mut dist = IndexMap::new();
- dist.insert(
- "type".to_string(),
- Box::new(PhpMixed::String(String::new())),
- );
- dist.insert("url".to_string(), Box::new(PhpMixed::String(String::new())));
- dist.insert(
- "reference".to_string(),
- Box::new(PhpMixed::String(commit_hash)),
- );
+ dist.insert("type".to_string(), PhpMixed::String(String::new()));
+ dist.insert("url".to_string(), PhpMixed::String(String::new()));
+ dist.insert("reference".to_string(), PhpMixed::String(commit_hash));
config.insert("dist".to_string(), PhpMixed::Array(dist));
}
}
@@ -249,7 +240,7 @@ impl RootPackageLoader {
real_package.set_config(
pkg_config
.iter()
- .map(|(k, v)| (k.clone(), (**v).clone()))
+ .map(|(k, v)| (k.clone(), v.clone()))
.collect(),
);
}
diff --git a/crates/shirabe/src/package/loader/validating_array_loader.rs b/crates/shirabe/src/package/loader/validating_array_loader.rs
index 490c0a9..cb7b7ae 100644
--- a/crates/shirabe/src/package/loader/validating_array_loader.rs
+++ b/crates/shirabe/src/package/loader/validating_array_loader.rs
@@ -28,7 +28,7 @@ pub struct ValidatingArrayLoader {
version_parser: VersionParser,
errors: Vec<String>,
warnings: Vec<String>,
- config: IndexMap<String, Box<PhpMixed>>,
+ config: IndexMap<String, PhpMixed>,
flags: i64,
}
@@ -64,7 +64,7 @@ impl ValidatingArrayLoader {
pub fn load(
&mut self,
- config: IndexMap<String, Box<PhpMixed>>,
+ config: IndexMap<String, PhpMixed>,
class: &str,
) -> anyhow::Result<crate::package::PackageInterfaceHandle> {
self.errors = Vec::new();
@@ -86,7 +86,7 @@ impl ValidatingArrayLoader {
if !is_string(&version_val) {
self.config.insert(
"version".to_string(),
- Box::new(PhpMixed::String(php_to_string(&version_val))),
+ PhpMixed::String(php_to_string(&version_val)),
);
}
let version_str = self
@@ -113,16 +113,16 @@ impl ValidatingArrayLoader {
.cloned()
&& let Some(platform_val) = config_section.get("platform")
{
- let platform_array: IndexMap<String, Box<PhpMixed>> = match platform_val.as_ref() {
+ let platform_array: IndexMap<String, PhpMixed> = match platform_val {
PhpMixed::Array(m) => m.clone(),
other => {
let mut m = IndexMap::new();
- m.insert("0".to_string(), Box::new(other.clone()));
+ m.insert("0".to_string(), other.clone());
m
}
};
for (key, platform) in &platform_array {
- if let PhpMixed::Bool(false) = platform.as_ref() {
+ if let PhpMixed::Bool(false) = platform {
continue;
}
if !is_string(platform) {
@@ -181,11 +181,11 @@ impl ValidatingArrayLoader {
let license_val = self.config["license"].clone();
// validate main data types
if is_array(&license_val) || is_string(&license_val) {
- let mut licenses: IndexMap<String, Box<PhpMixed>> = match license_val.as_ref() {
+ let mut licenses: IndexMap<String, PhpMixed> = match &license_val {
PhpMixed::Array(m) => m.clone(),
other => {
let mut m = IndexMap::new();
- m.insert("0".to_string(), Box::new(other.clone()));
+ m.insert("0".to_string(), other.clone());
m
}
};
@@ -196,7 +196,7 @@ impl ValidatingArrayLoader {
if !is_string(&license) {
self.warnings.push(format!(
"License {} should be a string.",
- PhpMixed::String(json_encode(&*license).unwrap_or_default()),
+ PhpMixed::String(json_encode(&license).unwrap_or_default()),
));
licenses.shift_remove(index);
}
@@ -238,19 +238,17 @@ impl ValidatingArrayLoader {
}
}
- let reindexed: Vec<Box<PhpMixed>> = array_values(&licenses);
- let mut reindexed_map: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
+ let reindexed: Vec<PhpMixed> = array_values(&licenses);
+ let mut reindexed_map: IndexMap<String, PhpMixed> = IndexMap::new();
for (i, v) in reindexed.into_iter().enumerate() {
reindexed_map.insert(i.to_string(), v);
}
- self.config.insert(
- "license".to_string(),
- Box::new(PhpMixed::Array(reindexed_map)),
- );
+ self.config
+ .insert("license".to_string(), PhpMixed::Array(reindexed_map));
} else {
self.warnings.push(format!(
"License must be a string or array of strings, got {}.",
- PhpMixed::String(json_encode(&*license_val).unwrap_or_default(),),
+ PhpMixed::String(json_encode(&license_val).unwrap_or_default(),),
));
self.config.shift_remove("license");
}
@@ -269,9 +267,7 @@ 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") {
m.shift_remove(key);
}
continue;
@@ -285,10 +281,9 @@ impl ValidatingArrayLoader {
"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(PhpMixed::Array(authors)) = self.config.get_mut("authors")
&& let Some(author_entry) = authors.get_mut(key)
- && let PhpMixed::Array(am) = author_entry.as_mut()
+ && let PhpMixed::Array(am) = author_entry
{
am.shift_remove(author_data);
}
@@ -306,10 +301,9 @@ impl ValidatingArrayLoader {
"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(PhpMixed::Array(authors)) = self.config.get_mut("authors")
&& let Some(author_entry) = authors.get_mut(key)
- && let PhpMixed::Array(am) = author_entry.as_mut()
+ && let PhpMixed::Array(am) = author_entry
{
am.shift_remove("homepage");
}
@@ -326,10 +320,9 @@ impl ValidatingArrayLoader {
"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(PhpMixed::Array(authors)) = self.config.get_mut("authors")
&& let Some(author_entry) = authors.get_mut(key)
- && let PhpMixed::Array(am) = author_entry.as_mut()
+ && let PhpMixed::Array(am) = author_entry
{
am.shift_remove("email");
}
@@ -343,8 +336,7 @@ impl ValidatingArrayLoader {
.map(|m| m.len())
.unwrap_or(0);
if current_author_len == 0
- && let Some(PhpMixed::Array(authors)) =
- self.config.get_mut("authors").map(|v| v.as_mut())
+ && let Some(PhpMixed::Array(authors)) = self.config.get_mut("authors")
{
authors.shift_remove(key);
}
@@ -378,9 +370,7 @@ impl ValidatingArrayLoader {
{
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())
- {
+ if let Some(PhpMixed::Array(support)) = self.config.get_mut("support") {
support.shift_remove(key);
}
}
@@ -400,9 +390,7 @@ impl ValidatingArrayLoader {
"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())
- {
+ if let Some(PhpMixed::Array(support)) = self.config.get_mut("support") {
support.shift_remove("email");
}
}
@@ -421,9 +409,7 @@ impl ValidatingArrayLoader {
"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())
- {
+ if let Some(PhpMixed::Array(support)) = self.config.get_mut("support") {
support.shift_remove("irc");
}
}
@@ -445,9 +431,7 @@ impl ValidatingArrayLoader {
"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())
- {
+ if let Some(PhpMixed::Array(support)) = self.config.get_mut("support") {
support.shift_remove(key);
}
}
@@ -474,9 +458,7 @@ impl ValidatingArrayLoader {
key,
get_debug_type(&funding_option)
));
- if let Some(PhpMixed::Array(funding)) =
- self.config.get_mut("funding").map(|v| v.as_mut())
- {
+ if let Some(PhpMixed::Array(funding)) = self.config.get_mut("funding") {
funding.shift_remove(key);
}
continue;
@@ -493,10 +475,9 @@ impl ValidatingArrayLoader {
"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(PhpMixed::Array(funding)) = self.config.get_mut("funding")
&& let Some(entry) = funding.get_mut(key)
- && let PhpMixed::Array(em) = entry.as_mut()
+ && let PhpMixed::Array(em) = entry
{
em.shift_remove(funding_data);
}
@@ -514,10 +495,9 @@ impl ValidatingArrayLoader {
"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(PhpMixed::Array(funding)) = self.config.get_mut("funding")
&& let Some(entry) = funding.get_mut(key)
- && let PhpMixed::Array(em) = entry.as_mut()
+ && let PhpMixed::Array(em) = entry
{
em.shift_remove("url");
}
@@ -531,8 +511,7 @@ impl ValidatingArrayLoader {
.map(|m| m.is_empty())
.unwrap_or(true);
if entry_empty
- && let Some(PhpMixed::Array(funding)) =
- self.config.get_mut("funding").map(|v| v.as_mut())
+ && let Some(PhpMixed::Array(funding)) = self.config.get_mut("funding")
{
funding.shift_remove(key);
}
@@ -557,9 +536,9 @@ impl ValidatingArrayLoader {
}
if self.config.contains_key("php-ext") {
- let mut php_ext: IndexMap<String, Box<PhpMixed>> =
- match self.config.shift_remove("php-ext").unwrap().as_ref() {
- PhpMixed::Array(m) => m.clone(),
+ let mut php_ext: IndexMap<String, PhpMixed> =
+ match self.config.shift_remove("php-ext").unwrap() {
+ PhpMixed::Array(m) => m,
_ => IndexMap::new(),
};
@@ -605,7 +584,7 @@ impl ValidatingArrayLoader {
if let Some(v) = php_ext.get("build-path").cloned()
&& !is_string(&v)
- && !matches!(v.as_ref(), PhpMixed::Null)
+ && !matches!(v, PhpMixed::Null)
{
self.errors.push(format!(
"php-ext.build-path : should be a string or null, {} given",
@@ -628,7 +607,7 @@ impl ValidatingArrayLoader {
"pre-packaged-source",
"pre-packaged-binary",
];
- let defined_download_url_methods: IndexMap<String, Box<PhpMixed>> =
+ let defined_download_url_methods: IndexMap<String, PhpMixed> =
if is_array(&v) {
v.as_array().unwrap().clone()
} else {
@@ -709,7 +688,7 @@ impl ValidatingArrayLoader {
get_debug_type(&os_family)
));
if let Some(PhpMixed::Array(arr)) =
- php_ext.get_mut(field_name).map(|v| v.as_mut())
+ php_ext.get_mut(field_name)
{
arr.shift_remove(key);
}
@@ -724,7 +703,7 @@ impl ValidatingArrayLoader {
valid_os_families.join(", ")
));
if let Some(PhpMixed::Array(arr)) =
- php_ext.get_mut(field_name).map(|v| v.as_mut())
+ php_ext.get_mut(field_name)
{
arr.shift_remove(key);
}
@@ -767,7 +746,7 @@ impl ValidatingArrayLoader {
get_debug_type(&option)
));
if let Some(PhpMixed::Array(arr)) =
- php_ext.get_mut("configure-options").map(|v| v.as_mut())
+ php_ext.get_mut("configure-options")
{
arr.shift_remove(key);
}
@@ -781,7 +760,7 @@ impl ValidatingArrayLoader {
key
));
if let Some(PhpMixed::Array(arr)) =
- php_ext.get_mut("configure-options").map(|v| v.as_mut())
+ php_ext.get_mut("configure-options")
{
arr.shift_remove(key);
}
@@ -796,7 +775,7 @@ impl ValidatingArrayLoader {
get_debug_type(&name_val)
));
if let Some(PhpMixed::Array(arr)) =
- php_ext.get_mut("configure-options").map(|v| v.as_mut())
+ php_ext.get_mut("configure-options")
{
arr.shift_remove(key);
}
@@ -812,9 +791,9 @@ impl ValidatingArrayLoader {
get_debug_type(&needs_value)
));
if let Some(PhpMixed::Array(co)) =
- php_ext.get_mut("configure-options").map(|v| v.as_mut())
+ php_ext.get_mut("configure-options")
&& let Some(entry) = co.get_mut(key)
- && let PhpMixed::Array(em) = entry.as_mut()
+ && let PhpMixed::Array(em) = entry
{
em.shift_remove("needs-value");
}
@@ -829,9 +808,9 @@ impl ValidatingArrayLoader {
get_debug_type(&description)
));
if let Some(PhpMixed::Array(co)) =
- php_ext.get_mut("configure-options").map(|v| v.as_mut())
+ php_ext.get_mut("configure-options")
&& let Some(entry) = co.get_mut(key)
- && let PhpMixed::Array(em) = entry.as_mut()
+ && let PhpMixed::Array(em) = entry
{
em.shift_remove("description");
}
@@ -852,7 +831,7 @@ 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)));
+ .insert("php-ext".to_string(), PhpMixed::Array(php_ext));
}
}
}
@@ -876,9 +855,7 @@ impl ValidatingArrayLoader {
"{}.{} : 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())
- {
+ if let Some(PhpMixed::Array(arr)) = self.config.get_mut(link_type) {
arr.shift_remove(&package);
}
continue;
@@ -896,29 +873,27 @@ impl ValidatingArrayLoader {
"{}.{} : invalid value, must be a string containing a version constraint",
link_type, package
));
- if let Some(PhpMixed::Array(arr)) =
- self.config.get_mut(link_type).map(|v| v.as_mut())
- {
+ if let Some(PhpMixed::Array(arr)) = self.config.get_mut(link_type) {
arr.shift_remove(&package);
}
} else if constraint.as_string().unwrap_or("") != "self.version" {
let constraint_str = constraint.as_string().unwrap_or("").to_string();
- let link_constraint =
- match self.version_parser.parse_constraints(&constraint_str) {
- Ok(c) => c,
- Err(e) => {
- self.errors.push(format!(
- "{}.{} : invalid version constraint ({})",
- link_type, package, e
- ));
- if let Some(PhpMixed::Array(arr)) =
- self.config.get_mut(link_type).map(|v| v.as_mut())
- {
- arr.shift_remove(&package);
- }
- continue;
+ let link_constraint = match self
+ .version_parser
+ .parse_constraints(&constraint_str)
+ {
+ Ok(c) => c,
+ Err(e) => {
+ self.errors.push(format!(
+ "{}.{} : invalid version constraint ({})",
+ link_type, package, e
+ ));
+ if let Some(PhpMixed::Array(arr)) = self.config.get_mut(link_type) {
+ arr.shift_remove(&package);
}
- };
+ continue;
+ }
+ };
// check requires for unbound constraints on non-platform packages
if (self.flags & Self::CHECK_UNBOUND_CONSTRAINTS) != 0
@@ -970,23 +945,15 @@ impl ValidatingArrayLoader {
.and_then(|v| v.as_array())
.cloned()
.unwrap_or_default();
- let replace_map_flat: IndexMap<String, PhpMixed> = replace_map
- .iter()
- .map(|(k, v)| (k.clone(), (**v).clone()))
- .collect();
- let conflict_map_flat: IndexMap<String, PhpMixed> = conflict_map
- .iter()
- .map(|(k, v)| (k.clone(), (**v).clone()))
- .collect();
+ let replace_map_flat: IndexMap<String, PhpMixed> = replace_map;
+ let conflict_map_flat: IndexMap<String, PhpMixed> = conflict_map;
let keys = array_intersect_key(&replace_map_flat, &conflict_map_flat);
if !keys.is_empty() {
self.errors.push(format!(
"{}.{} : you cannot conflict with a package that is also replaced, as replace already creates an implicit conflict rule",
link_type, package
));
- if let Some(PhpMixed::Array(arr)) =
- self.config.get_mut(link_type).map(|v| v.as_mut())
- {
+ if let Some(PhpMixed::Array(arr)) = self.config.get_mut(link_type) {
arr.shift_remove(&package);
}
}
@@ -1006,9 +973,7 @@ impl ValidatingArrayLoader {
"suggest.{} : invalid value, must be a string describing why the package is suggested",
package
));
- if let Some(PhpMixed::Array(arr)) =
- self.config.get_mut("suggest").map(|v| v.as_mut())
- {
+ if let Some(PhpMixed::Array(arr)) = self.config.get_mut("suggest") {
arr.shift_remove(package);
}
}
@@ -1054,9 +1019,7 @@ impl ValidatingArrayLoader {
r#type,
types.join(", ")
));
- 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") {
arr.shift_remove(r#type);
}
}
@@ -1088,8 +1051,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") {
arr.shift_remove("psr-4");
}
}
@@ -1191,13 +1153,12 @@ impl ValidatingArrayLoader {
self.warnings.push(format!(
"extra.branch-alias.{} : the target branch ({}) must be a string, \"{}\" received.",
source_branch,
- json_encode(&**target_branch).unwrap_or_default(),
+ json_encode(target_branch).unwrap_or_default(),
get_debug_type(target_branch)
));
- if let Some(PhpMixed::Array(extra)) =
- self.config.get_mut("extra").map(|v| v.as_mut())
+ if let Some(PhpMixed::Array(extra)) = self.config.get_mut("extra")
&& let Some(ba) = extra.get_mut("branch-alias")
- && let PhpMixed::Array(bam) = ba.as_mut()
+ && let PhpMixed::Array(bam) = ba
{
bam.shift_remove(source_branch);
}
@@ -1212,10 +1173,9 @@ impl ValidatingArrayLoader {
"extra.branch-alias.{} : the target branch ({}) must end in -dev",
source_branch, target_branch_str
));
- if let Some(PhpMixed::Array(extra)) =
- self.config.get_mut("extra").map(|v| v.as_mut())
+ if let Some(PhpMixed::Array(extra)) = self.config.get_mut("extra")
&& let Some(ba) = extra.get_mut("branch-alias")
- && let PhpMixed::Array(bam) = ba.as_mut()
+ && let PhpMixed::Array(bam) = ba
{
bam.shift_remove(source_branch);
}
@@ -1234,10 +1194,9 @@ impl ValidatingArrayLoader {
"extra.branch-alias.{} : the target branch ({}) must be a parseable number like 2.0-dev",
source_branch, target_branch_str
));
- if let Some(PhpMixed::Array(extra)) =
- self.config.get_mut("extra").map(|v| v.as_mut())
+ if let Some(PhpMixed::Array(extra)) = self.config.get_mut("extra")
&& let Some(ba) = extra.get_mut("branch-alias")
- && let PhpMixed::Array(bam) = ba.as_mut()
+ && let PhpMixed::Array(bam) = ba
{
bam.shift_remove(source_branch);
}
@@ -1258,10 +1217,9 @@ impl ValidatingArrayLoader {
"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(PhpMixed::Array(extra)) = self.config.get_mut("extra")
&& let Some(ba) = extra.get_mut("branch-alias")
- && let PhpMixed::Array(bam) = ba.as_mut()
+ && let PhpMixed::Array(bam) = ba
{
bam.shift_remove(source_branch);
}
@@ -1274,17 +1232,14 @@ impl ValidatingArrayLoader {
return Err(anyhow::anyhow!(InvalidPackageException::new(
self.errors.clone(),
self.warnings.clone(),
- config
- .iter()
- .map(|(k, v)| (k.clone(), (**v).clone()))
- .collect(),
+ config.iter().map(|(k, v)| (k.clone(), v.clone())).collect(),
)));
}
let package = self.loader.load(
self.config
.iter()
- .map(|(k, v)| (k.clone(), (**v).clone()))
+ .map(|(k, v)| (k.clone(), v.clone()))
.collect(),
Some(class.to_string()),
)?;
@@ -1459,7 +1414,7 @@ impl ValidatingArrayLoader {
}
let mut pass = true;
- let entries: Vec<(String, Box<PhpMixed>)> = self.config[property]
+ let entries: Vec<(String, PhpMixed)> = self.config[property]
.as_array()
.map(|m| m.iter().map(|(k, v)| (k.clone(), v.clone())).collect())
.unwrap_or_default();
@@ -1471,9 +1426,7 @@ impl ValidatingArrayLoader {
key,
get_debug_type(&value)
));
- if let Some(PhpMixed::Array(arr)) =
- self.config.get_mut(property).map(|v| v.as_mut())
- {
+ if let Some(PhpMixed::Array(arr)) = self.config.get_mut(property) {
arr.shift_remove(&key);
}
pass = false;
@@ -1488,9 +1441,7 @@ impl ValidatingArrayLoader {
"{}.{} : invalid value ({}), must match {}",
property, key, value_str, regex_str
));
- if let Some(PhpMixed::Array(arr)) =
- self.config.get_mut(property).map(|v| v.as_mut())
- {
+ if let Some(PhpMixed::Array(arr)) = self.config.get_mut(property) {
arr.shift_remove(&key);
}
pass = false;
@@ -1549,9 +1500,9 @@ impl ValidatingArrayLoader {
true
}
- fn is_empty_array(val: Option<&Box<PhpMixed>>) -> bool {
+ fn is_empty_array(val: Option<&PhpMixed>) -> bool {
match val {
- Some(v) => match v.as_ref() {
+ Some(v) => match v {
PhpMixed::Array(m) => m.is_empty(),
PhpMixed::Null => true,
PhpMixed::Bool(false) => true,
diff --git a/crates/shirabe/src/package/locker.rs b/crates/shirabe/src/package/locker.rs
index 369433e..8910645 100644
--- a/crates/shirabe/src/package/locker.rs
+++ b/crates/shirabe/src/package/locker.rs
@@ -90,7 +90,7 @@ impl Locker {
pub fn get_content_hash(composer_file_contents: &str) -> Result<String> {
let content = JsonFile::parse_json(Some(composer_file_contents), Some("composer.json"))?;
let content_map: IndexMap<String, PhpMixed> = match &content {
- 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(),
_ => IndexMap::new(),
};
@@ -124,7 +124,7 @@ impl Locker {
_ => None,
});
if let Some(platform) = platform_value {
- let mut config_map: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
+ let mut config_map: IndexMap<String, PhpMixed> = IndexMap::new();
config_map.insert("platform".to_string(), platform);
relevant_content.insert("config".to_string(), PhpMixed::Array(config_map));
}
@@ -134,12 +134,7 @@ impl Locker {
Ok(hash(
"md5",
&JsonFile::encode_with_options(
- &PhpMixed::Array(
- relevant_content
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
+ &PhpMixed::Array(relevant_content.into_iter().collect()),
JsonEncodeOptions::none(),
),
))
@@ -162,7 +157,7 @@ impl Locker {
pub fn is_fresh(&mut self) -> Result<bool> {
let lock = self.lock_file.read()?;
let lock_map: IndexMap<String, PhpMixed> = match lock {
- PhpMixed::Array(m) => m.into_iter().map(|(k, v)| (k, *v)).collect(),
+ PhpMixed::Array(m) => m.into_iter().collect(),
_ => IndexMap::new(),
};
@@ -213,7 +208,7 @@ impl Locker {
let has_name = if let PhpMixed::List(list) = &locked_packages {
list.first()
- .map(|v| match v.as_ref() {
+ .map(|v| match v {
PhpMixed::Array(m) => m.contains_key("name"),
_ => false,
})
@@ -225,9 +220,9 @@ impl Locker {
let mut package_by_name: IndexMap<String, BasePackageHandle> = IndexMap::new();
if let PhpMixed::List(list) = locked_packages {
for info in list {
- if let PhpMixed::Array(m) = info.as_ref() {
+ if let PhpMixed::Array(m) = info {
let info_map: IndexMap<String, PhpMixed> =
- m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect();
+ m.iter().map(|(k, v)| (k.clone(), v.clone())).collect();
let package = self.loader.load(info_map, None)?;
packages.add_package(package.clone())?;
package_by_name.insert(package.get_name(), package.clone());
@@ -244,7 +239,7 @@ impl Locker {
&& let PhpMixed::List(alias_list) = aliases
{
for alias in alias_list {
- if let PhpMixed::Array(m) = alias.as_ref() {
+ if let PhpMixed::Array(m) = alias {
let alias_pkg_name = m
.get("package")
.and_then(|v| v.as_string())
@@ -290,7 +285,7 @@ impl Locker {
let lock_data = self.get_lock_data()?;
if let Some(PhpMixed::List(list)) = lock_data.get("packages-dev") {
for package in list {
- if let PhpMixed::Array(m) = package.as_ref() {
+ if let PhpMixed::Array(m) = package {
names.push(strtolower(
m.get("name").and_then(|v| v.as_string()).unwrap_or(""),
));
@@ -313,9 +308,7 @@ impl Locker {
"1.0.0",
Link::TYPE_REQUIRE,
match platform_value.unwrap() {
- 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(),
_ => IndexMap::new(),
},
)?;
@@ -331,9 +324,7 @@ impl Locker {
"1.0.0",
Link::TYPE_REQUIRE,
match platform_dev_value.unwrap() {
- 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(),
_ => IndexMap::new(),
},
)?;
@@ -414,7 +405,7 @@ impl Locker {
.and_then(|v| match v {
PhpMixed::List(list) => Some(
list.iter()
- .filter_map(|v| match v.as_ref() {
+ .filter_map(|v| match v {
PhpMixed::Array(m) => Some(
m.iter()
.map(|(k, v)| {
@@ -457,7 +448,7 @@ impl Locker {
let data_php = self.lock_file.read()?;
let data: IndexMap<String, PhpMixed> = match data_php {
- PhpMixed::Array(m) => m.into_iter().map(|(k, v)| (k, *v)).collect(),
+ PhpMixed::Array(m) => m.into_iter().collect(),
_ => IndexMap::new(),
};
*self.lock_data_cache.borrow_mut() = Some(data.clone());
@@ -493,9 +484,9 @@ impl Locker {
if in_array(
PhpMixed::String(version),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("dev-master".to_string())),
- Box::new(PhpMixed::String("dev-trunk".to_string())),
- Box::new(PhpMixed::String("dev-default".to_string())),
+ PhpMixed::String("dev-master".to_string()),
+ PhpMixed::String("dev-trunk".to_string()),
+ PhpMixed::String("dev-default".to_string()),
]),
true,
) {
@@ -513,15 +504,15 @@ impl Locker {
lock.insert(
"_readme".to_string(),
PhpMixed::List(vec![
- Box::new(PhpMixed::String(
+ PhpMixed::String(
"This file locks the dependencies of your project to a known state".to_string(),
- )),
- Box::new(PhpMixed::String(
+ ),
+ PhpMixed::String(
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies".to_string(),
- )),
- Box::new(PhpMixed::String(
+ ),
+ PhpMixed::String(
format!("This file is @{}ated automatically", "gener"),
- )),
+ ),
]),
);
lock.insert(
@@ -536,11 +527,7 @@ impl Locker {
aliases
.iter()
.map(|m| {
- Box::new(PhpMixed::Array(
- m.iter()
- .map(|(k, v)| (k.clone(), Box::new(v.clone())))
- .collect(),
- ))
+ PhpMixed::Array(m.iter().map(|(k, v)| (k.clone(), v.clone())).collect())
})
.collect(),
),
@@ -554,7 +541,7 @@ impl Locker {
PhpMixed::Array(
stability_flags
.iter()
- .map(|(k, v)| (k.clone(), Box::new(PhpMixed::Int(*v))))
+ .map(|(k, v)| (k.clone(), PhpMixed::Int(*v)))
.collect(),
),
);
@@ -573,7 +560,7 @@ impl Locker {
PhpMixed::Array(
platform_reqs
.iter()
- .map(|(k, v)| (k.clone(), Box::new(PhpMixed::String(v.clone()))))
+ .map(|(k, v)| (k.clone(), PhpMixed::String(v.clone())))
.collect(),
),
);
@@ -582,19 +569,14 @@ impl Locker {
PhpMixed::Array(
platform_dev_reqs
.iter()
- .map(|(k, v)| (k.clone(), Box::new(PhpMixed::String(v.clone()))))
+ .map(|(k, v)| (k.clone(), PhpMixed::String(v.clone())))
.collect(),
),
);
if !platform_overrides.is_empty() {
lock.insert(
"platform-overrides".to_string(),
- PhpMixed::Array(
- platform_overrides
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
+ PhpMixed::Array(platform_overrides.into_iter().collect()),
);
}
lock.insert(
@@ -625,21 +607,20 @@ impl Locker {
.unwrap_or(true);
if !is_locked || differs {
if write {
- self.lock_file.write(PhpMixed::Array(
- lock.into_iter().map(|(k, v)| (k, Box::new(v))).collect(),
- ))?;
+ self.lock_file
+ .write(PhpMixed::Array(lock.into_iter().collect()))?;
*self.lock_data_cache.borrow_mut() = None;
self.virtual_file_written = false;
} else {
self.virtual_file_written = true;
let parsed = JsonFile::parse_json(
Some(&JsonFile::encode(&PhpMixed::Array(
- lock.into_iter().map(|(k, v)| (k, Box::new(v))).collect(),
+ lock.into_iter().collect(),
))),
None,
)?;
let parsed_map: 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(),
};
*self.lock_data_cache.borrow_mut() = Some(parsed_map);
@@ -682,7 +663,7 @@ impl Locker {
let lock_mtime = filemtime(self.lock_file.get_path());
let lock_data_php = self.lock_file.read()?;
let mut lock_data: IndexMap<String, PhpMixed> = match lock_data_php {
- PhpMixed::Array(m) => m.into_iter().map(|(k, v)| (k, *v)).collect(),
+ PhpMixed::Array(m) => m.into_iter().collect(),
_ => IndexMap::new(),
};
lock_data.insert(
@@ -694,10 +675,7 @@ impl Locker {
}
self.lock_file.write(PhpMixed::Array(
- self.fixup_json_data_type(lock_data)
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
+ self.fixup_json_data_type(lock_data).into_iter().collect(),
))?;
*self.lock_data_cache.borrow_mut() = None;
self.virtual_file_written = false;
@@ -729,9 +707,9 @@ impl Locker {
if let Some(PhpMixed::Array(m)) = lock_data.get_mut("stability-flags") {
let mut as_map: IndexMap<String, PhpMixed> =
- m.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect();
+ m.iter().map(|(k, v)| (k.clone(), v.clone())).collect();
ksort(&mut as_map);
- *m = as_map.into_iter().map(|(k, v)| (k, Box::new(v))).collect();
+ *m = as_map.into_iter().collect();
}
lock_data
@@ -804,11 +782,7 @@ impl Locker {
Ok(PhpMixed::List(
locked
.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(),
))
}
@@ -834,8 +808,8 @@ impl Locker {
&& in_array(
PhpMixed::String(source_type.clone().unwrap_or_default()),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("git".to_string())),
- Box::new(PhpMixed::String("hg".to_string())),
+ PhpMixed::String("git".to_string()),
+ PhpMixed::String("hg".to_string()),
]),
false,
)
@@ -859,12 +833,7 @@ impl Locker {
let command = GitUtil::build_rev_list_command(&self.process, args);
let mut output = PhpMixed::Null;
if 0 == self.process.borrow_mut().execute(
- PhpMixed::List(
- command
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
- ),
+ PhpMixed::List(command.into_iter().map(PhpMixed::String).collect()),
Some(&mut output),
path.as_deref(),
)? {
@@ -885,12 +854,12 @@ impl Locker {
let mut output = PhpMixed::Null;
if 0 == self.process.borrow_mut().execute(
PhpMixed::List(vec![
- Box::new(PhpMixed::String("hg".to_string())),
- Box::new(PhpMixed::String("log".to_string())),
- Box::new(PhpMixed::String("--template".to_string())),
- Box::new(PhpMixed::String("{date|hgdate}".to_string())),
- Box::new(PhpMixed::String("-r".to_string())),
- Box::new(PhpMixed::String(source_ref.clone())),
+ PhpMixed::String("hg".to_string()),
+ PhpMixed::String("log".to_string()),
+ PhpMixed::String("--template".to_string()),
+ PhpMixed::String("{date|hgdate}".to_string()),
+ PhpMixed::String("-r".to_string()),
+ PhpMixed::String(source_ref.clone()),
]),
Some(&mut output),
path.as_deref(),
diff --git a/crates/shirabe/src/package/version/version_guesser.rs b/crates/shirabe/src/package/version/version_guesser.rs
index 5d41434..42646cb 100644
--- a/crates/shirabe/src/package/version/version_guesser.rs
+++ b/crates/shirabe/src/package/version/version_guesser.rs
@@ -283,14 +283,14 @@ impl VersionGuesser {
&self.process,
array_merge(
PhpMixed::List(vec![
- Box::new(PhpMixed::String("--format=%H".to_string())),
- Box::new(PhpMixed::String("-n1".to_string())),
- Box::new(PhpMixed::String("HEAD".to_string())),
+ PhpMixed::String("--format=%H".to_string()),
+ PhpMixed::String("-n1".to_string()),
+ PhpMixed::String("HEAD".to_string()),
]),
PhpMixed::List(
GitUtil::get_no_show_signature_flags(&self.process)
.into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
+ .map(PhpMixed::String)
.collect(),
),
)
@@ -474,7 +474,7 @@ impl VersionGuesser {
&json_encode(&PhpMixed::Array(
package_config
.iter()
- .map(|(k, v)| (k.clone(), Box::new(v.clone())))
+ .map(|(k, v)| (k.clone(), v.clone()))
.collect(),
))
.unwrap_or_default(),
diff --git a/crates/shirabe/src/platform/hhvm_detector.rs b/crates/shirabe/src/platform/hhvm_detector.rs
index 3566f1f..99da3b7 100644
--- a/crates/shirabe/src/platform/hhvm_detector.rs
+++ b/crates/shirabe/src/platform/hhvm_detector.rs
@@ -64,7 +64,7 @@ impl HhvmDetector {
"echo HHVM_VERSION;",
]
.into_iter()
- .map(|s| Box::new(shirabe_php_shim::PhpMixed::String(s.to_string())))
+ .map(|s| shirabe_php_shim::PhpMixed::String(s.to_string()))
.collect(),
);
let exit_code = executor
diff --git a/crates/shirabe/src/plugin/plugin_manager.rs b/crates/shirabe/src/plugin/plugin_manager.rs
index da64cee..3d9c461 100644
--- a/crates/shirabe/src/plugin/plugin_manager.rs
+++ b/crates/shirabe/src/plugin/plugin_manager.rs
@@ -900,8 +900,7 @@ impl PluginManager {
config.borrow_mut().get("allow-plugins").clone();
if let Some(arr) = allow_plugins_value.as_array() {
let mut allow_plugins = arr.clone();
- allow_plugins
- .insert(package.to_string(), Box::new(PhpMixed::Bool(allow)));
+ allow_plugins.insert(package.to_string(), PhpMixed::Bool(allow));
if config
.borrow_mut()
.get("sort-packages")
@@ -917,20 +916,16 @@ impl PluginManager {
"allow-plugins",
PhpMixed::Array(allow_plugins.clone()),
)?;
- let mut inner: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
+ let mut inner = IndexMap::new();
inner.insert(
"allow-plugins".to_string(),
- Box::new(PhpMixed::Array(allow_plugins)),
+ PhpMixed::Array(allow_plugins),
);
- let mut config_section: IndexMap<String, Box<PhpMixed>> =
- IndexMap::new();
- config_section
- .insert("config".to_string(), Box::new(PhpMixed::Array(inner)));
- let wrap: IndexMap<String, PhpMixed> =
- config_section.into_iter().map(|(k, v)| (k, *v)).collect();
+ let mut config_section = IndexMap::new();
+ config_section.insert("config".to_string(), PhpMixed::Array(inner));
config
.borrow_mut()
- .merge(&wrap, crate::config::Config::SOURCE_UNKNOWN);
+ .merge(&config_section, crate::config::Config::SOURCE_UNKNOWN);
}
}
diff --git a/crates/shirabe/src/plugin/pre_file_download_event.rs b/crates/shirabe/src/plugin/pre_file_download_event.rs
index 3bf6296..0cd14d7 100644
--- a/crates/shirabe/src/plugin/pre_file_download_event.rs
+++ b/crates/shirabe/src/plugin/pre_file_download_event.rs
@@ -15,7 +15,7 @@ pub struct PreFileDownloadEvent {
custom_cache_key: Option<String>,
r#type: String,
context: PhpMixed,
- transport_options: IndexMap<String, Box<PhpMixed>>,
+ transport_options: IndexMap<String, PhpMixed>,
}
impl PreFileDownloadEvent {
@@ -69,11 +69,11 @@ impl PreFileDownloadEvent {
&self.context
}
- pub fn get_transport_options(&self) -> &IndexMap<String, Box<PhpMixed>> {
+ pub fn get_transport_options(&self) -> &IndexMap<String, PhpMixed> {
&self.transport_options
}
- pub fn set_transport_options(&mut self, options: IndexMap<String, Box<PhpMixed>>) {
+ pub fn set_transport_options(&mut self, options: IndexMap<String, PhpMixed>) {
self.transport_options = options;
}
}
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
diff --git a/crates/shirabe/src/self_update/versions.rs b/crates/shirabe/src/self_update/versions.rs
index 7c360e6..9d7dfa2 100644
--- a/crates/shirabe/src/self_update/versions.rs
+++ b/crates/shirabe/src/self_update/versions.rs
@@ -131,15 +131,15 @@ impl Versions {
if let PhpMixed::Array(ref map) = versions
&& let Some(channel_versions) = map.get(&effective_channel)
- && let PhpMixed::List(ref list) = **channel_versions
+ && let PhpMixed::List(ref list) = *channel_versions
{
for version in list {
- if let PhpMixed::Array(ref v) = **version {
+ if let PhpMixed::Array(ref v) = *version {
let min_php = v.get("min-php").and_then(|p| p.as_int()).unwrap_or(0);
if min_php <= PHP_VERSION_ID {
return Ok(Ok(v
.iter()
- .map(|(k, val)| (k.clone(), *val.clone()))
+ .map(|(k, val)| (k.clone(), val.clone()))
.collect()));
}
}
diff --git a/crates/shirabe/src/util/auth_helper.rs b/crates/shirabe/src/util/auth_helper.rs
index 5952429..d8b77ac 100644
--- a/crates/shirabe/src/util/auth_helper.rs
+++ b/crates/shirabe/src/util/auth_helper.rs
@@ -77,8 +77,8 @@ impl AuthHelper {
if in_array(
PhpMixed::String(input.clone()),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("y".to_string())),
- Box::new(PhpMixed::String("n".to_string())),
+ PhpMixed::String("y".to_string()),
+ PhpMixed::String("n".to_string()),
]),
false,
) {
@@ -106,7 +106,7 @@ impl AuthHelper {
.borrow()
.get_authentication(origin)
.into_iter()
- .map(|(k, v)| (k, Box::new(v.map_or(PhpMixed::Null, PhpMixed::String))))
+ .map(|(k, v)| (k, v.map_or(PhpMixed::Null, PhpMixed::String)))
.collect(),
),
)?;
@@ -256,9 +256,9 @@ impl AuthHelper {
if in_array(
PhpMixed::String(password),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("gitlab-ci-token".to_string())),
- Box::new(PhpMixed::String("private-token".to_string())),
- Box::new(PhpMixed::String("oauth2".to_string())),
+ PhpMixed::String("gitlab-ci-token".to_string()),
+ PhpMixed::String("private-token".to_string()),
+ PhpMixed::String("oauth2".to_string()),
]),
true,
) {
@@ -463,7 +463,7 @@ impl AuthHelper {
false
};
if !http_has_header && let Some(PhpMixed::Array(http)) = options.get_mut("http") {
- http.insert("header".to_string(), Box::new(PhpMixed::List(vec![])));
+ http.insert("header".to_string(), PhpMixed::List(vec![]));
}
}
@@ -475,7 +475,7 @@ impl AuthHelper {
.and_then(|h| h.get("header"))
.and_then(|v| v.as_list())
{
- Some(list) => list.iter().map(|b| (**b).clone()).collect(),
+ Some(list) => list.iter().cloned().collect(),
None => vec![],
};
@@ -504,11 +504,11 @@ impl AuthHelper {
if is_array(&custom_headers) {
if let Some(arr) = custom_headers.as_array() {
for header in arr.values() {
- headers.push((**header).clone());
+ headers.push(header.clone());
}
} else if let Some(list) = custom_headers.as_list() {
for header in list {
- headers.push((**header).clone());
+ headers.push(header.clone());
}
}
authentication_display_message =
@@ -527,9 +527,9 @@ impl AuthHelper {
} else if in_array(
PhpMixed::String(password.clone()),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("oauth2".to_string())),
- Box::new(PhpMixed::String("private-token".to_string())),
- Box::new(PhpMixed::String("gitlab-ci-token".to_string())),
+ PhpMixed::String("oauth2".to_string()),
+ PhpMixed::String("private-token".to_string()),
+ PhpMixed::String("gitlab-ci-token".to_string()),
]),
true,
) && in_array(
@@ -539,7 +539,7 @@ impl AuthHelper {
.borrow_mut()
.get("gitlab-domains")
.as_array()
- .map(|a| a.values().cloned().collect())
+ .map(|a| a.values().map(|v| v.clone()).collect())
.unwrap_or_default(),
),
true,
@@ -605,8 +605,8 @@ impl AuthHelper {
} else if in_array(
PhpMixed::String(origin.to_string()),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("api.bitbucket.org".to_string())),
- Box::new(PhpMixed::String("api.github.com".to_string())),
+ PhpMixed::String("api.bitbucket.org".to_string()),
+ PhpMixed::String("api.github.com".to_string()),
]),
true,
) {
@@ -615,10 +615,7 @@ impl AuthHelper {
// write headers back into options['http']['header']
if let Some(PhpMixed::Array(http)) = options.get_mut("http") {
- http.insert(
- "header".to_string(),
- Box::new(PhpMixed::List(headers.into_iter().map(Box::new).collect())),
- );
+ http.insert("header".to_string(), PhpMixed::List(headers));
}
Ok(options)
diff --git a/crates/shirabe/src/util/bitbucket.rs b/crates/shirabe/src/util/bitbucket.rs
index 0584308..26a9e65 100644
--- a/crates/shirabe/src/util/bitbucket.rs
+++ b/crates/shirabe/src/util/bitbucket.rs
@@ -102,24 +102,14 @@ impl Bitbucket {
fn request_access_token(&mut self) -> anyhow::Result<bool> {
let mut http = IndexMap::new();
- http.insert(
- "method".to_string(),
- Box::new(PhpMixed::String("POST".to_string())),
- );
+ http.insert("method".to_string(), PhpMixed::String("POST".to_string()));
http.insert(
"content".to_string(),
- Box::new(PhpMixed::String(
- "grant_type=client_credentials".to_string(),
- )),
- );
- let mut options = IndexMap::new();
- options.insert(
- "retry-auth-failure".to_string(),
- Box::new(PhpMixed::Bool(false)),
+ PhpMixed::String("grant_type=client_credentials".to_string()),
);
- options.insert("http".to_string(), Box::new(PhpMixed::Array(http)));
- let options: IndexMap<String, PhpMixed> =
- options.into_iter().map(|(k, v)| (k, *v)).collect();
+ let mut options: IndexMap<String, PhpMixed> = IndexMap::new();
+ options.insert("retry-auth-failure".to_string(), PhpMixed::Bool(false));
+ options.insert("http".to_string(), PhpMixed::Array(http));
let response = match self
.http_downloader
@@ -198,7 +188,7 @@ impl Bitbucket {
}
.into());
}
- self.token = Some(token_map.into_iter().map(|(k, v)| (k, *v)).collect());
+ self.token = Some(token_map.into_iter().collect());
Ok(true)
}
@@ -389,12 +379,8 @@ impl Bitbucket {
.get("expires_in")
.and_then(|v| v.as_int())
.ok_or_else(|| {
- let token_mixed = PhpMixed::Array(
- token
- .iter()
- .map(|(k, v)| (k.clone(), Box::new(v.clone())))
- .collect(),
- );
+ let token_mixed =
+ PhpMixed::Array(token.iter().map(|(k, v)| (k.clone(), v.clone())).collect());
LogicException {
message: format!(
"Expected a token configured with expires_in present, got {}",
@@ -405,22 +391,22 @@ impl Bitbucket {
})?;
let t = self.time.unwrap_or_else(time);
- let mut consumer: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
+ let mut consumer = IndexMap::new();
consumer.insert(
"consumer-key".to_string(),
- Box::new(PhpMixed::String(consumer_key.to_string())),
+ PhpMixed::String(consumer_key.to_string()),
);
consumer.insert(
"consumer-secret".to_string(),
- Box::new(PhpMixed::String(consumer_secret.to_string())),
+ PhpMixed::String(consumer_secret.to_string()),
);
consumer.insert(
"access-token".to_string(),
- Box::new(token.get("access_token").cloned().unwrap_or(PhpMixed::Null)),
+ token.get("access_token").cloned().unwrap_or(PhpMixed::Null),
);
consumer.insert(
"access-token-expiration".to_string(),
- Box::new(PhpMixed::Int(t + expires_in)),
+ PhpMixed::Int(t + expires_in),
);
self.config
@@ -465,7 +451,7 @@ impl Bitbucket {
return false;
}
- let access_token = match origin_config.get("access-token").map(|v| *v.clone()) {
+ let access_token = match origin_config.get("access-token").map(|v| v.clone()) {
Some(t) => t,
None => return false,
};
diff --git a/crates/shirabe/src/util/config_validator.rs b/crates/shirabe/src/util/config_validator.rs
index a3f6ef7..033e6b3 100644
--- a/crates/shirabe/src/util/config_validator.rs
+++ b/crates/shirabe/src/util/config_validator.rs
@@ -43,7 +43,7 @@ impl ConfigValidator {
.expect("config file path is always local");
let schema_result: anyhow::Result<()> = (|| -> anyhow::Result<()> {
manifest = Some(match json.read()? {
- PhpMixed::Array(m) => m.into_iter().map(|(k, v)| (k, *v)).collect(),
+ PhpMixed::Array(m) => m,
_ => IndexMap::new(),
});
json.validate_schema(JsonFile::LAX_SCHEMA, None)?;
@@ -108,7 +108,7 @@ impl ConfigValidator {
PhpMixed::List(list) => list
.iter()
.filter_map(|v| {
- if let PhpMixed::String(s) = v.as_ref() {
+ if let PhpMixed::String(s) = v {
Some(s.clone())
} else {
None
@@ -235,10 +235,10 @@ impl ConfigValidator {
Some(PhpMixed::Array(m)) => m.clone(),
_ => IndexMap::new(),
};
- let mut packages: IndexMap<String, Box<PhpMixed>> = require;
+ let mut packages: IndexMap<String, PhpMixed> = require;
packages.extend(require_dev);
for (package, version) in &packages {
- if let PhpMixed::String(version_str) = version.as_ref()
+ if let PhpMixed::String(version_str) = version
&& Preg::is_match(r"{#}", version_str)
{
warnings.push(format!(
@@ -282,12 +282,12 @@ impl ConfigValidator {
// check for empty psr-0/psr-4 namespace prefixes
if let Some(PhpMixed::Array(autoload)) = manifest.get("autoload") {
- if let Some(PhpMixed::Array(psr0)) = autoload.get("psr-0").map(|v| v.as_ref())
+ if let Some(PhpMixed::Array(psr0)) = autoload.get("psr-0")
&& psr0.contains_key("")
{
warnings.push("Defining autoload.psr-0 with an empty namespace prefix is a bad idea for performance".to_string());
}
- if let Some(PhpMixed::Array(psr4)) = autoload.get("psr-4").map(|v| v.as_ref())
+ if let Some(PhpMixed::Array(psr4)) = autoload.get("psr-4")
&& psr4.contains_key("")
{
warnings.push("Defining autoload.psr-4 with an empty namespace prefix is a bad idea for performance".to_string());
@@ -310,11 +310,7 @@ impl ConfigValidator {
PhpMixed::String("dummy/dummy".to_string()),
);
}
- let manifest_boxed: IndexMap<String, Box<PhpMixed>> = manifest_for_load
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect();
- match loader.load(manifest_boxed, "Composer\\Package\\CompletePackage") {
+ match loader.load(manifest_for_load, "Composer\\Package\\CompletePackage") {
Ok(_) => {}
Err(e) => {
if let Some(invalid_e) = e.downcast_ref::<InvalidPackageException>() {
diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs
index 50112ea..6ca6be0 100644
--- a/crates/shirabe/src/util/filesystem.rs
+++ b/crates/shirabe/src/util/filesystem.rs
@@ -107,11 +107,7 @@ impl Filesystem {
let result = self
.get_process()
.execute(
- PhpMixed::List(
- cmd.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
- .collect(),
- ),
+ PhpMixed::List(cmd.iter().map(|s| PhpMixed::String(s.clone())).collect()),
Some(&mut output),
(),
)
@@ -152,11 +148,7 @@ impl Filesystem {
let process = self
.get_process()
.execute_async(
- PhpMixed::List(
- cmd.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
- .collect(),
- ),
+ PhpMixed::List(cmd.iter().map(|s| PhpMixed::String(s.clone())).collect()),
(),
)
.await?;
diff --git a/crates/shirabe/src/util/forgejo.rs b/crates/shirabe/src/util/forgejo.rs
index 974fb4a..4ca4710 100644
--- a/crates/shirabe/src/util/forgejo.rs
+++ b/crates/shirabe/src/util/forgejo.rs
@@ -149,11 +149,10 @@ impl Forgejo {
cfg.get_config_source_mut()
.remove_config_setting(&setting_key)?;
}
- let value: shirabe_php_shim::PhpMixed =
- shirabe_php_shim::PhpMixed::Array(indexmap::indexmap! {
- "username".to_string() => Box::new(username.clone().into()),
- "token".to_string() => Box::new(token.clone().into()),
- });
+ let value = shirabe_php_shim::PhpMixed::Array(indexmap::indexmap! {
+ "username".to_string() => username.clone().into(),
+ "token".to_string() => token.clone().into(),
+ });
if store_in_local_auth_config && has_local_auth {
let mut cfg = self.config.borrow_mut();
if let Some(local) = cfg.get_local_auth_config_source_mut() {
diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs
index 5923917..d66751c 100644
--- a/crates/shirabe/src/util/git.rs
+++ b/crates/shirabe/src/util/git.rs
@@ -176,11 +176,8 @@ impl Git {
let mut status: i64 = 0;
for (counter, callable) in command_callables.iter().enumerate() {
let cmd = callable(url_arg);
- *last_cmd = PhpMixed::List(
- cmd.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
- .collect(),
- );
+ *last_cmd =
+ PhpMixed::List(cmd.iter().map(|s| PhpMixed::String(s.clone())).collect());
let mut local_output = String::new();
let exec_cwd = if initial_clone && counter == 0 {
None
@@ -324,7 +321,7 @@ impl Git {
&PhpMixed::List(
protocols_list
.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
+ .map(|s| PhpMixed::String(s.clone()))
.collect(),
),
true,
@@ -1321,11 +1318,11 @@ impl Git {
if in_array(
PhpMixed::String(credential.clone()),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("private-token".to_string())),
- Box::new(PhpMixed::String("x-token-auth".to_string())),
- Box::new(PhpMixed::String("oauth2".to_string())),
- Box::new(PhpMixed::String("gitlab-ci-token".to_string())),
- Box::new(PhpMixed::String("x-oauth-basic".to_string())),
+ PhpMixed::String("private-token".to_string()),
+ PhpMixed::String("x-token-auth".to_string()),
+ PhpMixed::String("oauth2".to_string()),
+ PhpMixed::String("gitlab-ci-token".to_string()),
+ PhpMixed::String("x-oauth-basic".to_string()),
]),
false,
) {
diff --git a/crates/shirabe/src/util/gitlab.rs b/crates/shirabe/src/util/gitlab.rs
index 86b7620..71ff7e3 100644
--- a/crates/shirabe/src/util/gitlab.rs
+++ b/crates/shirabe/src/util/gitlab.rs
@@ -123,10 +123,10 @@ impl GitLab {
if let Some(map) = auth_tokens.as_array() {
if let Some(t) = map.get(origin_url) {
- token = Some(*t.clone());
+ token = Some(t.clone());
}
if let Some(t) = map.get(bc_origin_url.as_str()) {
- token = Some(*t.clone());
+ token = Some(t.clone());
}
}
@@ -439,34 +439,23 @@ impl GitLab {
"",
"&",
);
- let mut http_inner: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- http_inner.insert(
- "method".to_string(),
- Box::new(PhpMixed::String("POST".to_string())),
- );
+ let mut http_inner: IndexMap<String, PhpMixed> = IndexMap::new();
+ http_inner.insert("method".to_string(), PhpMixed::String("POST".to_string()));
http_inner.insert(
"header".to_string(),
- Box::new(PhpMixed::List(
- headers
- .into_iter()
- .map(|h| Box::new(PhpMixed::String(h)))
- .collect(),
- )),
+ PhpMixed::List(headers.into_iter().map(PhpMixed::String).collect()),
);
- http_inner.insert("content".to_string(), Box::new(PhpMixed::String(data)));
- let mut options: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- options.insert(
- "retry-auth-failure".to_string(),
- Box::new(PhpMixed::Bool(false)),
- );
- options.insert("http".to_string(), Box::new(PhpMixed::Array(http_inner)));
+ http_inner.insert("content".to_string(), PhpMixed::String(data));
+ let mut options: IndexMap<String, PhpMixed> = IndexMap::new();
+ options.insert("retry-auth-failure".to_string(), PhpMixed::Bool(false));
+ options.insert("http".to_string(), PhpMixed::Array(http_inner));
let token = self
.http_downloader
.borrow_mut()
.get(
&format!("{}://{}/oauth/token", scheme, api_url),
- options.into_iter().map(|(k, v)| (k, *v)).collect(),
+ options.into_iter().collect(),
)?
.decode_json()?;
@@ -522,34 +511,23 @@ impl GitLab {
"",
"&",
);
- let mut http_inner: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- http_inner.insert(
- "method".to_string(),
- Box::new(PhpMixed::String("POST".to_string())),
- );
+ let mut http_inner = IndexMap::new();
+ http_inner.insert("method".to_string(), PhpMixed::String("POST".to_string()));
http_inner.insert(
"header".to_string(),
- Box::new(PhpMixed::List(
- headers
- .into_iter()
- .map(|h| Box::new(PhpMixed::String(h)))
- .collect(),
- )),
- );
- http_inner.insert("content".to_string(), Box::new(PhpMixed::String(data)));
- let mut options: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- options.insert(
- "retry-auth-failure".to_string(),
- Box::new(PhpMixed::Bool(false)),
+ PhpMixed::List(headers.into_iter().map(PhpMixed::String).collect()),
);
- options.insert("http".to_string(), Box::new(PhpMixed::Array(http_inner)));
+ http_inner.insert("content".to_string(), PhpMixed::String(data));
+ let mut options: IndexMap<String, PhpMixed> = IndexMap::new();
+ options.insert("retry-auth-failure".to_string(), PhpMixed::Bool(false));
+ options.insert("http".to_string(), PhpMixed::Array(http_inner));
let token = self
.http_downloader
.borrow_mut()
.get(
&format!("{}://{}/oauth/token", scheme, origin_url),
- options.into_iter().map(|(k, v)| (k, *v)).collect(),
+ options.into_iter().collect(),
)?
.decode_json()?;
@@ -587,18 +565,15 @@ impl GitLab {
.and_then(|v| v.as_string())
.unwrap_or("")
.to_string();
- let mut setting: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
+ let mut setting = IndexMap::new();
setting.insert(
"expires-at".to_string(),
- Box::new(PhpMixed::Int(created_at + expires_in)),
- );
- setting.insert(
- "refresh-token".to_string(),
- Box::new(PhpMixed::String(refresh_token)),
+ PhpMixed::Int(created_at + expires_in),
);
+ setting.insert("refresh-token".to_string(), PhpMixed::String(refresh_token));
setting.insert(
"token".to_string(),
- Box::new(PhpMixed::String(access_token.to_string())),
+ PhpMixed::String(access_token.to_string()),
);
PhpMixed::Array(setting)
}
diff --git a/crates/shirabe/src/util/http/curl_downloader.rs b/crates/shirabe/src/util/http/curl_downloader.rs
index c03da7a..42153eb 100644
--- a/crates/shirabe/src/util/http/curl_downloader.rs
+++ b/crates/shirabe/src/util/http/curl_downloader.rs
@@ -143,12 +143,12 @@ impl CurlDownloader {
version
.as_ref()
.and_then(|v| v.get("version"))
- .map(|b| (**b).clone())
+ .cloned()
.unwrap_or(PhpMixed::Null),
&PhpMixed::List(
BAD_MULTIPLEXING_CURL_VERSIONS
.iter()
- .map(|s| Box::new(PhpMixed::String((*s).to_string())))
+ .map(|s| PhpMixed::String((*s).to_string()))
.collect(),
),
true,
@@ -291,21 +291,11 @@ impl CurlDownloader {
m
};
let merged = array_merge(
- PhpMixed::Array(
- defaults
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
- PhpMixed::Array(
- attributes
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
+ PhpMixed::Array(defaults.into_iter().collect()),
+ PhpMixed::Array(attributes.into_iter().collect()),
);
let mut attributes: IndexMap<String, PhpMixed> = match merged {
- PhpMixed::Array(a) => a.into_iter().map(|(k, v)| (k, *v)).collect(),
+ PhpMixed::Array(a) => a,
_ => IndexMap::new(),
};
@@ -401,13 +391,13 @@ impl CurlDownloader {
PhpMixed::Int(CURLPROTO_HTTP | CURLPROTO_HTTPS),
);
- if attributes.get("ipResolve").and_then(|v| v.as_int()) == Some(4) {
+ if attributes.get("ipResolve").and_then(PhpMixed::as_int) == Some(4) {
curl_setopt(
&curl_handle,
CURLOPT_IPRESOLVE,
PhpMixed::Int(CURL_IPRESOLVE_V4),
);
- } else if attributes.get("ipResolve").and_then(|v| v.as_int()) == Some(6) {
+ } else if attributes.get("ipResolve").and_then(PhpMixed::as_int) == Some(6) {
curl_setopt(
&curl_handle,
CURLOPT_IPRESOLVE,
@@ -433,31 +423,25 @@ impl CurlDownloader {
.entry("http".to_string())
.or_insert(PhpMixed::Array(IndexMap::new()));
if let PhpMixed::Array(a) = http {
- a.insert("header".to_string(), Box::new(PhpMixed::List(Vec::new())));
+ a.insert("header".to_string(), PhpMixed::List(Vec::new()));
}
}
// $options['http']['header'] = array_diff($options['http']['header'], ['Connection: close']);
// $options['http']['header'][] = 'Connection: keep-alive';
if let Some(PhpMixed::Array(http)) = options.get_mut("http")
- && let Some(boxed) = http.get_mut("header")
- && let PhpMixed::List(list) = boxed.as_mut()
+ && let Some(PhpMixed::List(list)) = http.get_mut("header")
{
let headers: Vec<String> = list
.iter()
- .filter_map(|b| match b.as_ref() {
+ .filter_map(|b| match b {
PhpMixed::String(s) => Some(s.clone()),
_ => None,
})
.collect();
let diffed = array_diff(&headers, &["Connection: close".to_string()]);
- let mut new_list: Vec<Box<PhpMixed>> = diffed
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect();
- new_list.push(Box::new(PhpMixed::String(
- "Connection: keep-alive".to_string(),
- )));
+ let mut new_list: Vec<PhpMixed> = diffed.into_iter().map(PhpMixed::String).collect();
+ new_list.push(PhpMixed::String("Connection: keep-alive".to_string()));
*list = new_list;
}
@@ -515,11 +499,11 @@ impl CurlDownloader {
version
.as_ref()
.and_then(|v| v.get("version"))
- .map(|b| (**b).clone())
+ .cloned()
.unwrap_or(PhpMixed::Null),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("8.7.0".to_string())),
- Box::new(PhpMixed::String("8.7.1".to_string())),
+ PhpMixed::String("8.7.0".to_string()),
+ PhpMixed::String("8.7.1".to_string()),
]),
true,
)
@@ -552,7 +536,7 @@ impl CurlDownloader {
.get(&r#type)
.and_then(|v| v.as_array())
.and_then(|a| a.get(name))
- .map(|b| (**b).clone())
+ .cloned()
.unwrap_or(PhpMixed::Null);
let to_set = if matches!(val, PhpMixed::Bool(true)) {
PhpMixed::Int(2)
@@ -565,7 +549,7 @@ impl CurlDownloader {
.get(&r#type)
.and_then(|v| v.as_array())
.and_then(|a| a.get(name))
- .map(|b| (**b).clone())
+ .cloned()
.unwrap_or(PhpMixed::Null);
curl_setopt(&curl_handle, *curl_option, val);
}
@@ -576,7 +560,7 @@ impl CurlDownloader {
let ssl_options: IndexMap<String, PhpMixed> = options
.get("ssl")
.and_then(|v| v.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_else(IndexMap::new);
let proxy_curl_options = proxy
.get_curl_options(&ssl_options)
@@ -585,7 +569,7 @@ impl CurlDownloader {
let progress = array_diff_key(
match curl_getinfo(&curl_handle) {
- PhpMixed::Array(a) => a.into_iter().map(|(k, v)| (k, *v)).collect(),
+ PhpMixed::Array(a) => a,
_ => IndexMap::new(),
},
&time_info_static()
@@ -599,33 +583,10 @@ impl CurlDownloader {
job.insert("origin".to_string(), PhpMixed::String(origin.to_string()));
job.insert(
"attributes".to_string(),
- PhpMixed::Array(
- attributes
- .clone()
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
- );
- job.insert(
- "options".to_string(),
- PhpMixed::Array(
- original_options
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
- );
- job.insert(
- "progress".to_string(),
- PhpMixed::Array(
- progress
- .clone()
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
+ PhpMixed::Array(attributes.clone()),
);
+ job.insert("options".to_string(), PhpMixed::Array(original_options));
+ job.insert("progress".to_string(), PhpMixed::Array(progress.clone()));
// curlHandle, headerHandle, bodyHandle, resolve, reject are PHP resources/callables;
// stored as opaque PhpMixed::Null placeholders (real values live in Rust-side fields).
// TODO(phase-c): storing the real \CurlHandle and the resolve/reject callables needs the
@@ -659,10 +620,10 @@ impl CurlDownloader {
.get("http")
.and_then(|v| v.as_array())
.and_then(|a| a.get("header"))
- .and_then(|b| match b.as_ref() {
+ .and_then(|b| match b {
PhpMixed::List(l) => Some(
l.iter()
- .filter_map(|x| match x.as_ref() {
+ .filter_map(|x| match x {
PhpMixed::String(s) => Some(s.clone()),
_ => None,
})
@@ -743,15 +704,13 @@ impl CurlDownloader {
loop {
let progress_read = curl_multi_info_read(&self.multi_handle);
- let mut progress: IndexMap<String, Box<PhpMixed>> = match &progress_read {
+ let mut progress: IndexMap<String, PhpMixed> = match &progress_read {
PhpMixed::Array(a) => a.clone(),
_ => break,
};
// $curlHandle = $progress['handle']; $result = $progress['result']; $i = (int) $curlHandle;
- let _curl_handle_placeholder: PhpMixed = progress
- .get("handle")
- .map(|b| (**b).clone())
- .unwrap_or(PhpMixed::Null);
+ let _curl_handle_placeholder: PhpMixed =
+ progress.get("handle").cloned().unwrap_or(PhpMixed::Null);
let result_code: i64 = progress.get("result").and_then(|b| b.as_int()).unwrap_or(0);
// TODO(phase-c): the job id is `(int) $progress['handle']` — the integer id of the
// \CurlHandle reported by curl_multi_info_read. Recovering it needs real curl handle
@@ -809,7 +768,7 @@ impl CurlDownloader {
if error.is_empty() && function_exists("curl_strerror") {
error = curl_strerror(errno).unwrap_or_default();
}
- progress.insert("error_code".to_string(), Box::new(PhpMixed::Int(errno)));
+ progress.insert("error_code".to_string(), PhpMixed::Int(errno));
if errno == 28 /* CURLE_OPERATION_TIMEDOUT */
&& PHP_VERSION_ID >= 70300
@@ -846,18 +805,18 @@ impl CurlDownloader {
&& (in_array(
PhpMixed::Int(errno),
&PhpMixed::List(vec![
- Box::new(PhpMixed::Int(7 /* CURLE_COULDNT_CONNECT */)),
- Box::new(PhpMixed::Int(16 /* CURLE_HTTP2 */)),
- Box::new(PhpMixed::Int(92 /* CURLE_HTTP2_STREAM */)),
- Box::new(PhpMixed::Int(6 /* CURLE_COULDNT_RESOLVE_HOST */)),
- Box::new(PhpMixed::Int(28 /* CURLE_OPERATION_TIMEDOUT */)),
+ PhpMixed::Int(7 /* CURLE_COULDNT_CONNECT */),
+ PhpMixed::Int(16 /* CURLE_HTTP2 */),
+ PhpMixed::Int(92 /* CURLE_HTTP2_STREAM */),
+ PhpMixed::Int(6 /* CURLE_COULDNT_RESOLVE_HOST */),
+ PhpMixed::Int(28 /* CURLE_OPERATION_TIMEDOUT */),
]),
true,
) || (in_array(
PhpMixed::Int(errno),
&PhpMixed::List(vec![
- Box::new(PhpMixed::Int(56 /* CURLE_RECV_ERROR */)),
- Box::new(PhpMixed::Int(35 /* CURLE_SSL_CONNECT_ERROR */)),
+ PhpMixed::Int(56 /* CURLE_RECV_ERROR */),
+ PhpMixed::Int(35 /* CURLE_SSL_CONNECT_ERROR */),
]),
true,
) && str_contains(&error, "Connection reset by peer")))
@@ -1011,7 +970,7 @@ impl CurlDownloader {
.as_ref()
.unwrap()
.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
+ .map(|s| PhpMixed::String(s.clone()))
.collect()
),
true
@@ -1046,10 +1005,7 @@ impl CurlDownloader {
status_code,
headers.clone().unwrap_or_default(),
contents.as_string().map(|s| s.to_string()),
- progress
- .iter()
- .map(|(k, v)| (k.clone(), (**v).clone()))
- .collect(),
+ progress.clone(),
));
self.io.write_error3(
&format!(
@@ -1113,10 +1069,7 @@ impl CurlDownloader {
status_code,
headers.clone().unwrap_or_default(),
contents.as_string().map(|s| s.to_string()),
- progress
- .iter()
- .map(|(k, v)| (k.clone(), (**v).clone()))
- .collect(),
+ progress.clone(),
));
self.io.write_error3(
&format!(
@@ -1144,7 +1097,7 @@ impl CurlDownloader {
self.io.clone(),
job.get("origin").and_then(|v| v.as_string()).unwrap_or(""),
&match json_decode(response_ref.inner.get_body().unwrap_or(""), true)? {
- PhpMixed::Array(a) => a.into_iter().map(|(k, v)| (k, *v)).collect(),
+ PhpMixed::Array(a) => a,
_ => IndexMap::new(),
},
)?;
@@ -1241,14 +1194,14 @@ impl CurlDownloader {
&& in_array(
PhpMixed::Int(sc),
&PhpMixed::List(vec![
- Box::new(PhpMixed::Int(423)),
- Box::new(PhpMixed::Int(425)),
- Box::new(PhpMixed::Int(500)),
- Box::new(PhpMixed::Int(502)),
- Box::new(PhpMixed::Int(503)),
- Box::new(PhpMixed::Int(504)),
- Box::new(PhpMixed::Int(507)),
- Box::new(PhpMixed::Int(510)),
+ PhpMixed::Int(423),
+ PhpMixed::Int(425),
+ PhpMixed::Int(500),
+ PhpMixed::Int(502),
+ PhpMixed::Int(503),
+ PhpMixed::Int(504),
+ PhpMixed::Int(507),
+ PhpMixed::Int(510),
]),
true,
)
@@ -1312,14 +1265,14 @@ impl CurlDownloader {
job.get("attributes")
.and_then(|v| v.as_array())
.and_then(|a| a.get("storeAuth"))
- .map(|b| (**b).clone()),
+ .cloned(),
Some(PhpMixed::Bool(false))
) {
let store_auth_val = job
.get("attributes")
.and_then(|v| v.as_array())
.and_then(|a| a.get("storeAuth"))
- .map(|b| (**b).clone())
+ .cloned()
.unwrap_or(PhpMixed::Bool(false));
let store_auth = match store_auth_val {
PhpMixed::Bool(b) => StoreAuth::Bool(b),
@@ -1356,12 +1309,7 @@ impl CurlDownloader {
if let Some(r) = &response {
e.set_response(r.inner.get_body().map(|s| s.to_string()));
}
- e.set_response_info(
- progress
- .iter()
- .map(|(_, v)| (**v).clone())
- .collect::<Vec<_>>(),
- );
+ e.set_response_info(progress.values().cloned().collect::<Vec<_>>());
self.reject_job(&job, anyhow::anyhow!(e.message));
}
Err(e) => {
@@ -1377,7 +1325,7 @@ impl CurlDownloader {
// $progress = array_diff_key(curl_getinfo($curlHandle), self::$timeInfo);
let progress_now = array_diff_key(
match curl_getinfo(/* TODO real handle */ &curl_init()) {
- PhpMixed::Array(a) => a.into_iter().map(|(k, v)| (k, *v)).collect(),
+ PhpMixed::Array(a) => a,
_ => IndexMap::new(),
},
&time_info_static()
@@ -1392,21 +1340,16 @@ impl CurlDownloader {
.and_then(|j| j.get("progress"))
.cloned()
.unwrap_or(PhpMixed::Null);
- let prev_progress_map = match &prev_progress {
- PhpMixed::Array(a) => a.clone(),
+ let prev_progress_map: IndexMap<String, PhpMixed> = match prev_progress {
+ PhpMixed::Array(a) => a,
_ => IndexMap::new(),
};
- let progress_now_boxed: IndexMap<String, Box<PhpMixed>> = progress_now
- .clone()
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect();
- if !maps_equal(&prev_progress_map, &progress_now_boxed) {
+ if !maps_equal(&prev_progress_map, &progress_now) {
if let Some(job) = self.jobs.get_mut(&i) {
job.insert(
"progress".to_string(),
- PhpMixed::Array(progress_now_boxed.clone()),
+ PhpMixed::Array(progress_now.clone()),
);
}
@@ -1614,10 +1557,7 @@ impl CurlDownloader {
) -> anyhow::Result<Result<PromptAuthResult, TransportException>> {
if in_array(
PhpMixed::Int(response.inner.get_status_code()),
- &PhpMixed::List(vec![
- Box::new(PhpMixed::Int(401)),
- Box::new(PhpMixed::Int(403)),
- ]),
+ &PhpMixed::List(vec![PhpMixed::Int(401), PhpMixed::Int(403)]),
false,
) && job
.get("attributes")
@@ -1675,7 +1615,7 @@ impl CurlDownloader {
// check for gitlab 404 when downloading archives
let gitlab_domains = self.config.borrow_mut().get("gitlab-domains");
- let gitlab_domains_list: Vec<Box<PhpMixed>> = match gitlab_domains {
+ let gitlab_domains_list: Vec<PhpMixed> = match gitlab_domains {
PhpMixed::List(l) => l,
_ => Vec::new(),
};
@@ -1754,15 +1694,10 @@ impl CurlDownloader {
};
let merged = array_merge(
PhpMixed::Array(job_attrs),
- PhpMixed::Array(
- attributes
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
+ PhpMixed::Array(attributes.into_iter().collect()),
);
let attributes: IndexMap<String, PhpMixed> = match merged {
- PhpMixed::Array(a) => a.into_iter().map(|(k, v)| (k, *v)).collect(),
+ PhpMixed::Array(a) => a,
_ => IndexMap::new(),
};
let origin = Url::get_origin(&self.config.borrow(), url);
@@ -1772,7 +1707,7 @@ impl CurlDownloader {
.and_then(|v| v.as_string())
.map(|s| s.to_string());
let options = match job.get("options") {
- Some(PhpMixed::Array(a)) => a.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect(),
+ Some(PhpMixed::Array(a)) => a.clone(),
_ => IndexMap::new(),
};
// PHP forwards the original job's resolve/reject callables into the restarted download.
@@ -1836,10 +1771,8 @@ impl CurlDownloader {
.to_lowercase(),
),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("application/json".to_string())),
- Box::new(PhpMixed::String(
- "application/json; charset=utf-8".to_string(),
- )),
+ PhpMixed::String("application/json".to_string()),
+ PhpMixed::String("application/json; charset=utf-8".to_string()),
]),
true,
) {
@@ -1907,7 +1840,7 @@ impl CurlDownloader {
}
}
-fn maps_equal(a: &IndexMap<String, Box<PhpMixed>>, b: &IndexMap<String, Box<PhpMixed>>) -> bool {
+fn maps_equal(a: &IndexMap<String, PhpMixed>, b: &IndexMap<String, PhpMixed>) -> bool {
if a.len() != b.len() {
return false;
}
diff --git a/crates/shirabe/src/util/http_downloader.rs b/crates/shirabe/src/util/http_downloader.rs
index 929dd67..d5d619d 100644
--- a/crates/shirabe/src/util/http_downloader.rs
+++ b/crates/shirabe/src/util/http_downloader.rs
@@ -454,7 +454,7 @@ impl HttpDownloader {
_ => None,
})
.cloned();
- if let Some(PhpMixed::List(list)) = http_header.as_deref() {
+ if let Some(PhpMixed::List(list)) = http_header.as_ref() {
let joined = implode(
"",
&list
@@ -463,7 +463,7 @@ impl HttpDownloader {
.collect::<Vec<_>>(),
);
stripos(&joined, "if-modified-since").is_some()
- } else if let Some(PhpMixed::Array(m)) = http_header.as_deref() {
+ } else if let Some(PhpMixed::Array(m)) = http_header.as_ref() {
let joined = implode(
"",
&m.values()
@@ -718,7 +718,7 @@ impl HttpDownloader {
if let Some(PhpMixed::List(list)) = entry {
for spec in list {
let r#type = substr(key, 0, Some(-1));
- if let PhpMixed::Array(spec_map) = spec.as_ref() {
+ if let PhpMixed::Array(spec_map) = spec {
let constraint = version_parser.parse_constraints(
spec_map
.get("versions")
@@ -769,15 +769,12 @@ impl HttpDownloader {
{
Silencer::suppress(None);
let mut ctx_options: IndexMap<String, PhpMixed> = IndexMap::new();
- let mut ssl_map: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- ssl_map.insert("verify_peer".to_string(), Box::new(PhpMixed::Bool(false)));
+ let mut ssl_map: IndexMap<String, PhpMixed> = IndexMap::new();
+ ssl_map.insert("verify_peer".to_string(), PhpMixed::Bool(false));
ctx_options.insert("ssl".to_string(), PhpMixed::Array(ssl_map));
- let mut http_map: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- http_map.insert(
- "follow_location".to_string(),
- Box::new(PhpMixed::Bool(false)),
- );
- http_map.insert("ignore_errors".to_string(), Box::new(PhpMixed::Bool(true)));
+ let mut http_map: IndexMap<String, PhpMixed> = IndexMap::new();
+ http_map.insert("follow_location".to_string(), PhpMixed::Bool(false));
+ http_map.insert("ignore_errors".to_string(), PhpMixed::Bool(true));
ctx_options.insert("http".to_string(), PhpMixed::Array(http_map));
// TODO(phase-c): file_get_contents only takes a path; the stream context arg is dropped
// until the PHP stream-context layer is modeled.
diff --git a/crates/shirabe/src/util/no_proxy_pattern.rs b/crates/shirabe/src/util/no_proxy_pattern.rs
index 34491ba..ed93414 100644
--- a/crates/shirabe/src/util/no_proxy_pattern.rs
+++ b/crates/shirabe/src/util/no_proxy_pattern.rs
@@ -489,7 +489,7 @@ impl NoProxyPattern {
inner.insert("max_range".to_string(), PhpMixed::Int(max));
options.insert(
"options".to_string(),
- PhpMixed::Array(inner.into_iter().map(|(k, v)| (k, Box::new(v))).collect()),
+ PhpMixed::Array(inner.into_iter().collect()),
);
!matches!(
diff --git a/crates/shirabe/src/util/perforce.rs b/crates/shirabe/src/util/perforce.rs
index 3f73f7d..0d56afb 100644
--- a/crates/shirabe/src/util/perforce.rs
+++ b/crates/shirabe/src/util/perforce.rs
@@ -146,10 +146,7 @@ impl Perforce {
let use_p4_client = false;
let command = self.generate_p4_command(task, use_p4_client);
self.execute_command(PhpMixed::List(
- command
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
+ command.into_iter().map(PhpMixed::String).collect(),
));
let client_spec = self.get_p4_client_spec();
let file_system = self.get_filesystem();
@@ -358,10 +355,7 @@ impl Perforce {
pub fn is_logged_in(&mut self) -> Result<bool> {
let command = self.generate_p4_command(vec!["login".to_string(), "-s".to_string()], false);
let exit_code = self.execute_command(PhpMixed::List(
- command
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
+ command.into_iter().map(PhpMixed::String).collect(),
));
if exit_code != 0 {
let error_output = self.process.borrow().get_error_output().to_string();
@@ -411,10 +405,7 @@ impl Perforce {
p4_sync_command.push(format!("@{}", source_reference));
}
self.execute_command(PhpMixed::List(
- p4_sync_command
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
+ p4_sync_command.into_iter().map(PhpMixed::String).collect(),
));
chdir(&prev_dir);
@@ -592,7 +583,7 @@ impl Perforce {
let decoded = json_decode(&composer_file_content, true)?;
Ok(match decoded {
- PhpMixed::Array(m) => Some(m.into_iter().map(|(k, v)| (k, *v)).collect()),
+ PhpMixed::Array(m) => Some(m.into_iter().collect()),
_ => None,
})
}
@@ -602,10 +593,7 @@ impl Perforce {
let command = self.generate_p4_command(vec!["print".to_string(), path], true);
self.execute_command(PhpMixed::List(
- command
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
+ command.into_iter().map(PhpMixed::String).collect(),
));
let result = self.command_result.clone();
@@ -631,10 +619,7 @@ impl Perforce {
);
let command = self.generate_p4_command(vec!["files".to_string(), path], false);
self.execute_command(PhpMixed::List(
- command
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
+ command.into_iter().map(PhpMixed::String).collect(),
));
let result = self.command_result.clone();
let index2 = strpos(&result, "no such file(s).");
@@ -673,10 +658,7 @@ impl Perforce {
true,
);
self.execute_command(PhpMixed::List(
- command
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
+ command.into_iter().map(PhpMixed::String).collect(),
));
let result = self.command_result.clone();
let res_array = explode(PHP_EOL, &result);
@@ -698,10 +680,7 @@ impl Perforce {
false,
);
self.execute_command(PhpMixed::List(
- command
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
+ command.into_iter().map(PhpMixed::String).collect(),
));
let result = self.command_result.clone();
let res_array = explode(PHP_EOL, &result);
@@ -728,10 +707,7 @@ impl Perforce {
pub fn get_tags(&mut self) -> IndexMap<String, String> {
let command = self.generate_p4_command(vec!["labels".to_string()], true);
self.execute_command(PhpMixed::List(
- command
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
+ command.into_iter().map(PhpMixed::String).collect(),
));
let result = self.command_result.clone();
let res_array = explode(PHP_EOL, &result);
@@ -751,10 +727,7 @@ impl Perforce {
pub fn check_stream(&mut self) -> bool {
let command = self.generate_p4_command(vec!["depots".to_string()], false);
self.execute_command(PhpMixed::List(
- command
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
+ command.into_iter().map(PhpMixed::String).collect(),
));
let result = self.command_result.clone();
let res_array = explode(PHP_EOL, &result);
@@ -783,10 +756,7 @@ impl Perforce {
let command =
self.generate_p4_command(vec!["changes".to_string(), "-m1".to_string(), label], true);
self.execute_command(PhpMixed::List(
- command
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
+ command.into_iter().map(PhpMixed::String).collect(),
));
let changes = self.command_result.clone();
if strpos(&changes, "Change") != Some(0) {
@@ -811,10 +781,7 @@ impl Perforce {
true,
);
self.execute_command(PhpMixed::List(
- command
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
+ command.into_iter().map(PhpMixed::String).collect(),
));
Some(self.command_result.clone())
diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs
index 7560072..449874e 100644
--- a/crates/shirabe/src/util/platform.rs
+++ b/crates/shirabe/src/util/platform.rs
@@ -304,8 +304,8 @@ impl Platform {
if in_array(
PhpMixed::String(strtoupper(&Self::get_env("MSYSTEM").unwrap_or_default())),
&PhpMixed::List(vec![
- Box::new(PhpMixed::String("MINGW32".to_string())),
- Box::new(PhpMixed::String("MINGW64".to_string())),
+ PhpMixed::String("MINGW32".to_string()),
+ PhpMixed::String("MINGW64".to_string()),
]),
true,
) {
diff --git a/crates/shirabe/src/util/process_executor.rs b/crates/shirabe/src/util/process_executor.rs
index ca31290..2bdf065 100644
--- a/crates/shirabe/src/util/process_executor.rs
+++ b/crates/shirabe/src/util/process_executor.rs
@@ -149,7 +149,7 @@ impl ProcessExecutor {
let cmd = PhpMixed::List(
command
.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
+ .map(|s| PhpMixed::String(s.clone()))
.collect(),
);
let mut buf = PhpMixed::String(String::new());
@@ -352,9 +352,9 @@ impl ProcessExecutor {
git_env.insert("GIT_DIR".to_string(), cwd.unwrap().to_string());
self.run_process(
PhpMixed::List(vec![
- Box::new(PhpMixed::String("git".to_string())),
- Box::new(PhpMixed::String("config".to_string())),
- Box::new(PhpMixed::String("safe.bareRepository".to_string())),
+ PhpMixed::String("git".to_string()),
+ PhpMixed::String("config".to_string()),
+ PhpMixed::String("safe.bareRepository".to_string()),
]),
cwd,
Some(git_env.clone()),
@@ -677,7 +677,7 @@ impl ProcessExecutor {
} else if let PhpMixed::List(list) = command {
let parts: Vec<String> = array_map(
|v| Self::escape(v.as_string().unwrap_or("")),
- &list.iter().map(|b| (**b).clone()).collect::<Vec<_>>(),
+ &list.iter().cloned().collect::<Vec<_>>(),
);
implode(" ", &parts)
} else {
@@ -810,7 +810,7 @@ impl ProcessExecutor {
&PhpMixed::List(
Self::BUILTIN_CMD_COMMANDS
.iter()
- .map(|s| Box::new(PhpMixed::String(s.to_string())))
+ .map(|s| PhpMixed::String(s.to_string()))
.collect(),
),
true,
@@ -870,21 +870,13 @@ impl IntoExecCommand for &String {
impl IntoExecCommand for Vec<String> {
fn into_exec_command(self) -> PhpMixed {
- PhpMixed::List(
- self.into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
- )
+ PhpMixed::List(self.into_iter().map(PhpMixed::String).collect())
}
}
impl IntoExecCommand for &Vec<String> {
fn into_exec_command(self) -> PhpMixed {
- PhpMixed::List(
- self.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
- .collect(),
- )
+ PhpMixed::List(self.iter().map(|s| PhpMixed::String(s.clone())).collect())
}
}
@@ -892,7 +884,7 @@ impl<const N: usize> IntoExecCommand for &[&str; N] {
fn into_exec_command(self) -> PhpMixed {
PhpMixed::List(
self.iter()
- .map(|s| Box::new(PhpMixed::String(s.to_string())))
+ .map(|s| PhpMixed::String(s.to_string()))
.collect(),
)
}
@@ -902,7 +894,7 @@ impl IntoExecCommand for &[&str] {
fn into_exec_command(self) -> PhpMixed {
PhpMixed::List(
self.iter()
- .map(|s| Box::new(PhpMixed::String(s.to_string())))
+ .map(|s| PhpMixed::String(s.to_string()))
.collect(),
)
}
@@ -910,11 +902,7 @@ impl IntoExecCommand for &[&str] {
impl IntoExecCommand for &[String] {
fn into_exec_command(self) -> PhpMixed {
- PhpMixed::List(
- self.iter()
- .map(|s| Box::new(PhpMixed::String(s.clone())))
- .collect(),
- )
+ PhpMixed::List(self.iter().map(|s| PhpMixed::String(s.clone())).collect())
}
}
diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs
index 1890a95..c4b3923 100644
--- a/crates/shirabe/src/util/remote_filesystem.rs
+++ b/crates/shirabe/src/util/remote_filesystem.rs
@@ -234,7 +234,7 @@ impl RemoteFilesystem {
if let Some(http_opts) = options.get_mut("http")
&& let PhpMixed::Array(m) = http_opts
{
- m.insert("ignore_errors".to_string(), Box::new(PhpMixed::Bool(true)));
+ m.insert("ignore_errors".to_string(), PhpMixed::Bool(true));
}
let mut degraded_packagist = false;
@@ -331,7 +331,7 @@ impl RemoteFilesystem {
.map(|s| json_decode(s, true).unwrap_or(PhpMixed::Null))
.unwrap_or(PhpMixed::Null);
let parsed_map: 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 _ = HttpDownloader::output_warnings(
@@ -854,10 +854,7 @@ impl RemoteFilesystem {
.entry("http".to_string())
.or_insert_with(|| PhpMixed::Array(IndexMap::new()));
if let PhpMixed::Array(m) = http_entry {
- m.insert(
- "protocol_version".to_string(),
- Box::new(PhpMixed::Float(1.1)),
- );
+ m.insert("protocol_version".to_string(), PhpMixed::Float(1.1));
}
headers.push("Connection: close".to_string());
}
@@ -866,7 +863,7 @@ impl RemoteFilesystem {
.get("http")
.and_then(|v| v.as_array())
.and_then(|m| m.get("header"))
- .map(|v| matches!(v.as_ref(), PhpMixed::String(_)))
+ .map(|v| matches!(v, PhpMixed::String(_)))
.unwrap_or(false);
if header_is_string {
let header_str = options["http"].as_array().unwrap()["header"]
@@ -877,12 +874,7 @@ impl RemoteFilesystem {
if let Some(PhpMixed::Array(m)) = options.get_mut("http") {
m.insert(
"header".to_string(),
- Box::new(PhpMixed::List(
- split
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
- )),
+ PhpMixed::List(split.into_iter().map(PhpMixed::String).collect()),
);
}
}
@@ -896,16 +888,16 @@ impl RemoteFilesystem {
.entry("http".to_string())
.or_insert_with(|| PhpMixed::Array(IndexMap::new()));
if let PhpMixed::Array(m) = http_entry {
- m.insert("follow_location".to_string(), Box::new(PhpMixed::Int(0)));
+ m.insert("follow_location".to_string(), PhpMixed::Int(0));
}
for header in headers {
if let Some(PhpMixed::Array(m)) = options.get_mut("http") {
let header_list = m
.entry("header".to_string())
- .or_insert_with(|| Box::new(PhpMixed::List(Vec::new())));
- if let PhpMixed::List(l) = header_list.as_mut() {
- l.push(Box::new(PhpMixed::String(header)));
+ .or_insert_with(|| PhpMixed::List(Vec::new()));
+ if let PhpMixed::List(l) = header_list {
+ l.push(PhpMixed::String(header));
}
}
}
diff --git a/crates/shirabe/src/util/stream_context_factory.rs b/crates/shirabe/src/util/stream_context_factory.rs
index d73f3b4..db48122 100644
--- a/crates/shirabe/src/util/stream_context_factory.rs
+++ b/crates/shirabe/src/util/stream_context_factory.rs
@@ -33,7 +33,7 @@ impl StreamContextFactory {
let mut o = IndexMap::new();
o.insert(
"http".to_string(),
- PhpMixed::Array(http.into_iter().map(|(k, v)| (k, Box::new(v))).collect()),
+ PhpMixed::Array(http.into_iter().collect()),
);
o
};
@@ -57,12 +57,7 @@ impl StreamContextFactory {
let fixed = Self::fix_http_header_field(&header);
http.insert(
"header".to_string(),
- Box::new(PhpMixed::List(
- fixed
- .into_iter()
- .map(|s| Box::new(PhpMixed::String(s)))
- .collect(),
- )),
+ PhpMixed::List(fixed.into_iter().map(PhpMixed::String).collect()),
);
}
@@ -81,24 +76,24 @@ impl StreamContextFactory {
.map(|a| a.contains_key("header"))
.unwrap_or(false);
if !has_header && let Some(PhpMixed::Array(http)) = options.get_mut("http") {
- http.insert("header".to_string(), Box::new(PhpMixed::List(vec![])));
+ http.insert("header".to_string(), PhpMixed::List(vec![]));
}
// Convert string header to array
let header_is_string = options
.get("http")
.and_then(|v| v.as_array())
.and_then(|a| a.get("header"))
- .map(|v| matches!(**v, PhpMixed::String(_)))
+ .map(|v| matches!(*v, PhpMixed::String(_)))
.unwrap_or(false);
if header_is_string
&& let Some(PhpMixed::Array(http)) = options.get_mut("http")
- && let Some(PhpMixed::String(header_str)) = http.get("header").map(|v| *v.clone())
+ && let Some(PhpMixed::String(header_str)) = http.get("header").cloned()
{
- let parts: Vec<Box<PhpMixed>> = header_str
+ let parts: Vec<PhpMixed> = header_str
.split("\r\n")
- .map(|s| Box::new(PhpMixed::String(s.to_string())))
+ .map(|s| PhpMixed::String(s.to_string()))
.collect();
- http.insert("header".to_string(), Box::new(PhpMixed::List(parts)));
+ http.insert("header".to_string(), PhpMixed::List(parts));
}
// Add stream proxy options if there is a proxy
@@ -135,18 +130,18 @@ impl StreamContextFactory {
let proxy_http = proxy_options.get("http");
if let Some(proxy_header) = proxy_http.and_then(|h| h.get("header"))
&& let Some(PhpMixed::Array(http)) = options.get_mut("http")
- && let Some(PhpMixed::List(headers)) = http.get_mut("header").map(|v| &mut **v)
+ && let Some(PhpMixed::List(headers)) = http.get_mut("header")
{
- headers.push(Box::new(proxy_header.clone()));
+ headers.push(proxy_header.clone());
}
let proxy_options_flat: IndexMap<String, PhpMixed> = proxy_options
.iter()
.map(|(k, v)| {
- let inner: IndexMap<String, Box<PhpMixed>> = v
+ let inner: IndexMap<String, PhpMixed> = v
.iter()
.filter(|(ik, _)| ik.as_str() != "header")
- .map(|(ik, iv)| (ik.clone(), Box::new(iv.clone())))
+ .map(|(ik, iv)| (ik.clone(), iv.clone()))
.collect();
(k.clone(), PhpMixed::Array(inner))
})
@@ -180,8 +175,8 @@ impl StreamContextFactory {
.get("http")
.and_then(|v| v.as_array())
.and_then(|a| a.get("header"))
- .and_then(|v| match **v {
- PhpMixed::List(ref list) => {
+ .and_then(|v| match v {
+ PhpMixed::List(list) => {
let joined: String = list
.iter()
.filter_map(|item| item.as_string())
@@ -221,9 +216,9 @@ impl StreamContextFactory {
},
);
if let Some(PhpMixed::Array(http)) = options.get_mut("http")
- && let Some(PhpMixed::List(headers)) = http.get_mut("header").map(|v| &mut **v)
+ && let Some(PhpMixed::List(headers)) = http.get_mut("header")
{
- headers.push(Box::new(PhpMixed::String(user_agent)));
+ headers.push(PhpMixed::String(user_agent));
}
}
@@ -299,12 +294,7 @@ impl StreamContextFactory {
let mut d = IndexMap::new();
d.insert(
"ssl".to_string(),
- PhpMixed::Array(
- ssl_defaults
- .into_iter()
- .map(|(k, v)| (k, Box::new(v)))
- .collect(),
- ),
+ PhpMixed::Array(ssl_defaults.into_iter().collect()),
);
d
};
@@ -314,18 +304,15 @@ impl StreamContextFactory {
{
let merged = array_replace_recursive(
match ssl_defaults_mixed {
- PhpMixed::Array(a) => a.into_iter().map(|(k, v)| (k, *v)).collect(),
+ PhpMixed::Array(a) => a,
_ => IndexMap::new(),
},
match ssl_options.clone() {
- PhpMixed::Array(a) => a.into_iter().map(|(k, v)| (k, *v)).collect(),
+ PhpMixed::Array(a) => a,
_ => IndexMap::new(),
},
);
- defaults.insert(
- "ssl".to_string(),
- PhpMixed::Array(merged.into_iter().map(|(k, v)| (k, Box::new(v))).collect()),
- );
+ defaults.insert("ssl".to_string(), PhpMixed::Array(merged));
}
// Attempt to find a local cafile or throw an exception if none pre-set.
@@ -337,11 +324,11 @@ impl StreamContextFactory {
let result = CaBundle::get_system_ca_root_bundle_path(logger);
if shirabe_php_shim::is_dir(&result) {
if let Some(PhpMixed::Array(ssl)) = defaults.get_mut("ssl") {
- ssl.insert("capath".to_string(), Box::new(PhpMixed::String(result)));
+ ssl.insert("capath".to_string(), PhpMixed::String(result));
}
} else {
if let Some(PhpMixed::Array(ssl)) = defaults.get_mut("ssl") {
- ssl.insert("cafile".to_string(), Box::new(PhpMixed::String(result)));
+ ssl.insert("cafile".to_string(), PhpMixed::String(result));
}
}
}
@@ -378,10 +365,7 @@ impl StreamContextFactory {
// Disable TLS compression to prevent CRIME attacks where supported.
if let Some(PhpMixed::Array(ssl)) = defaults.get_mut("ssl") {
- ssl.insert(
- "disable_compression".to_string(),
- Box::new(PhpMixed::Bool(true)),
- );
+ ssl.insert("disable_compression".to_string(), PhpMixed::Bool(true));
}
Ok(defaults)
diff --git a/crates/shirabe/src/util/svn.rs b/crates/shirabe/src/util/svn.rs
index 269cb5d..319edaf 100644
--- a/crates/shirabe/src/util/svn.rs
+++ b/crates/shirabe/src/util/svn.rs
@@ -371,7 +371,7 @@ impl Svn {
let auth_for_host = auth_config
.as_array()
.and_then(|m| m.get(host_str))
- .map(|v| (**v).clone());
+ .map(|v| v.clone());
if let Some(entry) = auth_for_host
&& let Some(entry_arr) = entry.as_array()
{
@@ -408,7 +408,7 @@ impl Svn {
};
let user_val = uri_arr
.get("user")
- .map(|v| (**v).clone())
+ .map(|v| v.clone())
.unwrap_or(PhpMixed::Null);
if empty(&user_val) {
self.has_auth = Some(false);
@@ -417,7 +417,7 @@ impl Svn {
let pass_val = uri_arr
.get("pass")
- .map(|v| (**v).clone())
+ .map(|v| v.clone())
.unwrap_or(PhpMixed::Null);
self.credentials = Some(SvnCredentials {
username: user_val.as_string().unwrap_or("").to_string(),