aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/installer
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-20 01:16:50 +0900
committernsfisis <nsfisis@gmail.com>2026-06-20 02:22:41 +0900
commitefec43b3b8827820cf35fe1b73d8e33f5fe84eb4 (patch)
treea62bbba72324de48be5f8e689559f8d9e288fc61 /crates/shirabe/src/installer
parentcac18ef73a39b4ac41fa4d6ccb753804d4c42cb7 (diff)
downloadphp-shirabe-efec43b3b8827820cf35fe1b73d8e33f5fe84eb4.tar.gz
php-shirabe-efec43b3b8827820cf35fe1b73d8e33f5fe84eb4.tar.zst
php-shirabe-efec43b3b8827820cf35fe1b73d8e33f5fe84eb4.zip
refactor: auto-fix clippy warnings
Diffstat (limited to 'crates/shirabe/src/installer')
-rw-r--r--crates/shirabe/src/installer/binary_installer.rs27
-rw-r--r--crates/shirabe/src/installer/installation_manager.rs47
-rw-r--r--crates/shirabe/src/installer/library_installer.rs26
-rw-r--r--crates/shirabe/src/installer/suggested_packages_reporter.rs7
4 files changed, 50 insertions, 57 deletions
diff --git a/crates/shirabe/src/installer/binary_installer.rs b/crates/shirabe/src/installer/binary_installer.rs
index bc7d694..b9c56f6 100644
--- a/crates/shirabe/src/installer/binary_installer.rs
+++ b/crates/shirabe/src/installer/binary_installer.rs
@@ -310,7 +310,7 @@ impl BinaryInstaller {
.find_shortest_path_code(link, bin, false, true, false);
let mut stream_proxy_code = String::new();
let mut stream_hint = String::new();
- let mut globals_code = format!("$GLOBALS['_composer_bin_dir'] = __DIR__;\n",);
+ let mut globals_code = "$GLOBALS['_composer_bin_dir'] = __DIR__;\n".to_string();
let mut phpunit_hack1 = String::new();
let mut phpunit_hack2 = String::new();
// Don't expose autoload path when vendor dir was not set in custom installers
@@ -329,30 +329,29 @@ impl BinaryInstaller {
));
}
// Add workaround for PHPUnit process isolation
- if let Some(vendor_dir) = &self.vendor_dir {
- if self.filesystem.borrow().normalize_path(bin)
+ if let Some(vendor_dir) = &self.vendor_dir
+ && self.filesystem.borrow().normalize_path(bin)
== self
.filesystem
.borrow()
.normalize_path(&format!("{}/phpunit/phpunit/phpunit", vendor_dir))
- {
- // workaround issue on PHPUnit 6.5+ running on PHP 8+
- globals_code.push_str(&format!(
+ {
+ // workaround issue on PHPUnit 6.5+ running on PHP 8+
+ globals_code.push_str(&format!(
"$GLOBALS['__PHPUNIT_ISOLATION_EXCLUDE_LIST'] = $GLOBALS['__PHPUNIT_ISOLATION_BLACKLIST'] = array(realpath({}));\n",
bin_path_exported,
));
- // workaround issue on all PHPUnit versions running on PHP <8
- phpunit_hack1 = "'phpvfscomposer://'.".to_string();
- phpunit_hack2 = "
+ // workaround issue on all PHPUnit versions running on PHP <8
+ phpunit_hack1 = "'phpvfscomposer://'.".to_string();
+ phpunit_hack2 = "
$data = str_replace('__DIR__', var_export(dirname($this->realpath), true), $data);
$data = str_replace('__FILE__', var_export($this->realpath, true), $data);"
- .to_string();
- }
+ .to_string();
}
- if trim(m.get(0).map(|s| s.as_str()).unwrap_or(""), None) != "<?php" {
- stream_hint = format!(
+ if trim(m.first().map(|s| s.as_str()).unwrap_or(""), None) != "<?php" {
+ stream_hint =
" using a stream wrapper to prevent the shebang from being output on PHP<8\n *"
- );
+ .to_string();
stream_proxy_code = format!(
"if (PHP_VERSION_ID < 80000) {{\n if (!class_exists('Composer\\BinProxyWrapper')) {{\n /**\n * @internal\n */\n final class BinProxyWrapper\n {{\n private $handle;\n private $position;\n private $realpath;\n\n public function stream_open($path, $mode, $options, &$opened_path)\n {{\n // get rid of phpvfscomposer:// prefix for __FILE__ & __DIR__ resolution\n $opened_path = substr($path, 17);\n $this->realpath = realpath($opened_path) ?: $opened_path;\n $opened_path = {phpunit_hack1}$this->realpath;\n $this->handle = fopen($this->realpath, $mode);\n $this->position = 0;\n\n return (bool) $this->handle;\n }}\n\n public function stream_read($count)\n {{\n $data = fread($this->handle, $count);\n\n if ($this->position === 0) {{\n $data = preg_replace('{{^#!.*\\r?\\n}}', '', $data);\n }}{phpunit_hack2}\n\n $this->position += strlen($data);\n\n return $data;\n }}\n\n public function stream_cast($castAs)\n {{\n return $this->handle;\n }}\n\n public function stream_close()\n {{\n fclose($this->handle);\n }}\n\n public function stream_lock($operation)\n {{\n return $operation ? flock($this->handle, $operation) : true;\n }}\n\n public function stream_seek($offset, $whence)\n {{\n if (0 === fseek($this->handle, $offset, $whence)) {{\n $this->position = ftell($this->handle);\n return true;\n }}\n\n return false;\n }}\n\n public function stream_tell()\n {{\n return $this->position;\n }}\n\n public function stream_eof()\n {{\n return feof($this->handle);\n }}\n\n public function stream_stat()\n {{\n return array();\n }}\n\n public function stream_set_option($option, $arg1, $arg2)\n {{\n return true;\n }}\n\n public function url_stat($path, $flags)\n {{\n $path = substr($path, 17);\n if (file_exists($path)) {{\n return stat($path);\n }}\n\n return false;\n }}\n }}\n }}\n\n if (\n (function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))\n || (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\\BinProxyWrapper'))\n ) {{\n return include(\"phpvfscomposer://\" . {bin_path_exported});\n }}\n}}\n",
phpunit_hack1 = phpunit_hack1,
diff --git a/crates/shirabe/src/installer/installation_manager.rs b/crates/shirabe/src/installer/installation_manager.rs
index 90801ec..6f8b65c 100644
--- a/crates/shirabe/src/installer/installation_manager.rs
+++ b/crates/shirabe/src/installer/installation_manager.rs
@@ -222,23 +222,23 @@ impl InstallationManager {
.as_install_operation()
.map(|install| install.get_package())
};
- if let Some(package) = package {
- if package.get_type() == "composer-plugin" {
- let extra = package.get_extra();
- if extra
- .get("plugin-modifies-downloads")
- .and_then(|v| v.as_bool())
- == Some(true)
- {
- if (batch.len() as i64) > 0 {
- batches.push(std::mem::take(&mut batch));
- }
- let mut single = IndexMap::new();
- single.insert(index, operation);
- batches.push(single);
-
- continue;
+ if let Some(package) = package
+ && package.get_type() == "composer-plugin"
+ {
+ let extra = package.get_extra();
+ if extra
+ .get("plugin-modifies-downloads")
+ .and_then(|v| v.as_bool())
+ == Some(true)
+ {
+ if (batch.len() as i64) > 0 {
+ batches.push(std::mem::take(&mut batch));
}
+ let mut single = IndexMap::new();
+ single.insert(index, operation);
+ batches.push(single);
+
+ continue;
}
}
batch.insert(index, operation);
@@ -290,9 +290,7 @@ impl InstallationManager {
Ok(())
}
- /// @param OperationInterface[] $operations List of operations to execute in this batch
- /// @param OperationInterface[] $allOperations Complete list of operations to be executed in the install job, used for event listeners
- /// @phpstan-param array<callable(): ?PromiseInterface<void|null>> $cleanupPromises
+ #[allow(clippy::too_many_arguments, reason = "to keep PHP signature")]
async fn download_and_execute_batch(
&mut self,
repo: &mut dyn InstalledRepositoryInterface,
@@ -563,9 +561,8 @@ impl InstallationManager {
/// @phpstan-return PromiseInterface<void|null>|null
pub async fn download(&mut self, package: PackageInterfaceHandle) -> Option<PhpMixed> {
let installer = self.get_installer(&package.get_type()).ok()?;
- let promise = installer.cleanup("install", package, None).await.ok()?;
- promise
+ installer.cleanup("install", package, None).await.ok()?
}
/// Executes install operation.
@@ -599,7 +596,7 @@ impl InstallationManager {
let initial_type = initial.get_type();
let target_type = target.get_type();
- let promise = if initial_type == target_type {
+ if initial_type == target_type {
let installer = self.get_installer(&initial_type).ok()?;
let promise = installer.update(repo, initial, target.clone()).await.ok()?;
self.mark_for_notification(target.clone());
@@ -614,9 +611,7 @@ impl InstallationManager {
.ok()?;
let installer = self.get_installer(&target_type).ok()?;
installer.install(repo, target).await.ok()?
- };
-
- promise
+ }
}
/// Uninstalls package.
@@ -803,7 +798,7 @@ impl InstallationManager {
if let Some(notification_url) = package.get_notification_url() {
self.notifiable_packages
.entry(notification_url)
- .or_insert_with(Vec::new)
+ .or_default()
.push(package.clone());
}
}
diff --git a/crates/shirabe/src/installer/library_installer.rs b/crates/shirabe/src/installer/library_installer.rs
index 9fb3e43..d2f222e 100644
--- a/crates/shirabe/src/installer/library_installer.rs
+++ b/crates/shirabe/src/installer/library_installer.rs
@@ -109,18 +109,18 @@ impl LibraryInstaller {
let install_path = self.get_install_path(package.clone()).unwrap();
let target_dir = package.get_target_dir();
- if let Some(target_dir) = target_dir {
- if !target_dir.is_empty() {
- let replaced = Preg::replace(
- &format!(
- "{{/*{}/?$}}",
- preg_quote(&target_dir, None).replace('/', "/+")
- ),
- "",
- &install_path,
- );
- return replaced;
- }
+ if let Some(target_dir) = target_dir
+ && !target_dir.is_empty()
+ {
+ let replaced = Preg::replace(
+ &format!(
+ "{{/*{}/?$}}",
+ preg_quote(&target_dir, None).replace('/', "/+")
+ ),
+ "",
+ &install_path,
+ );
+ return replaced;
}
install_path
@@ -368,7 +368,7 @@ impl InstallerInterface for LibraryInstaller {
self.binary_installer.remove_binaries(package.clone());
repo.remove_package(package.clone());
- if strpos(&package.get_name(), "/").map_or(false, |pos| pos != 0) {
+ if strpos(&package.get_name(), "/").is_some_and(|pos| pos != 0) {
let package_vendor_dir = dirname(&download_path);
if is_dir(&package_vendor_dir)
&& self.filesystem.borrow().is_dir_empty(&package_vendor_dir)
diff --git a/crates/shirabe/src/installer/suggested_packages_reporter.rs b/crates/shirabe/src/installer/suggested_packages_reporter.rs
index 2a2ed9f..979b4bb 100644
--- a/crates/shirabe/src/installer/suggested_packages_reporter.rs
+++ b/crates/shirabe/src/installer/suggested_packages_reporter.rs
@@ -64,11 +64,11 @@ impl SuggestedPackagesReporter {
for suggestion in &suggested_packages {
suggesters
.entry(suggestion["source"].clone())
- .or_insert_with(IndexMap::new)
+ .or_default()
.insert(suggestion["target"].clone(), suggestion["reason"].clone());
suggested
.entry(suggestion["target"].clone())
- .or_insert_with(IndexMap::new)
+ .or_default()
.insert(suggestion["source"].clone(), suggestion["reason"].clone());
}
suggesters.sort_keys();
@@ -132,8 +132,7 @@ impl SuggestedPackagesReporter {
}
if let Some(only_dependents_of) = only_dependents_of {
- let all_suggested_packages =
- self.get_filtered_suggestions(installed_repo.as_deref_mut(), None)?;
+ let all_suggested_packages = self.get_filtered_suggestions(installed_repo, None)?;
let diff = all_suggested_packages.len() as i64 - suggested_packages.len() as i64;
if diff != 0 {
self.io.write(&format!("<info>{} additional suggestions</info> by transitive dependencies can be shown with <info>--all</info>", diff));