aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-21 17:02:52 +0900
committernsfisis <nsfisis@gmail.com>2026-06-21 17:12:37 +0900
commit84fe6ac6977f15cbec85cbc9f773567742a7fb87 (patch)
tree5701e7c980585dd404471ab9fa53e98a0ba601ab /crates/shirabe/src/util
parent12a7756588a20f1351e6976f0c009de5992514a9 (diff)
downloadphp-shirabe-84fe6ac6977f15cbec85cbc9f773567742a7fb87.tar.gz
php-shirabe-84fe6ac6977f15cbec85cbc9f773567742a7fb87.tar.zst
php-shirabe-84fe6ac6977f15cbec85cbc9f773567742a7fb87.zip
refactor(math): use method-style max/min/clamp over std::cmp
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util')
-rw-r--r--crates/shirabe/src/util/http/curl_downloader.rs12
-rw-r--r--crates/shirabe/src/util/http_downloader.rs17
-rw-r--r--crates/shirabe/src/util/no_proxy_pattern.rs6
-rw-r--r--crates/shirabe/src/util/process_executor.rs17
-rw-r--r--crates/shirabe/src/util/remote_filesystem.rs7
5 files changed, 28 insertions, 31 deletions
diff --git a/crates/shirabe/src/util/http/curl_downloader.rs b/crates/shirabe/src/util/http/curl_downloader.rs
index 42153eb..0519f26 100644
--- a/crates/shirabe/src/util/http/curl_downloader.rs
+++ b/crates/shirabe/src/util/http/curl_downloader.rs
@@ -19,8 +19,8 @@ use shirabe_php_shim::{
curl_multi_add_handle, curl_multi_exec, curl_multi_info_read, curl_multi_init,
curl_multi_select, curl_multi_setopt, curl_setopt, curl_setopt_array, curl_share_init,
curl_share_setopt, curl_strerror, curl_version, defined, explode, fclose, fopen,
- function_exists, implode, in_array, ini_get, is_resource, json_decode, max, parse_url,
- preg_quote, rename, rewind, rtrim, sprintf, str_contains, stream_get_contents,
+ function_exists, implode, in_array, ini_get, is_resource, json_decode, parse_url, preg_quote,
+ rename, rewind, rtrim, sprintf, str_contains, stream_get_contents,
stream_get_contents_with_max, stripos, strpos, substr, unlink_silent, usleep, var_export,
};
@@ -369,14 +369,14 @@ impl CurlDownloader {
curl_setopt(
&curl_handle,
CURLOPT_TIMEOUT,
- PhpMixed::Int(max(
+ PhpMixed::Int(
ini_get("default_socket_timeout")
.as_deref()
.unwrap_or("0")
.parse::<i64>()
- .unwrap_or(0),
- 300,
- )),
+ .unwrap_or(0)
+ .max(300),
+ ),
);
curl_setopt(&curl_handle, CURLOPT_WRITEHEADER, header_handle.clone());
curl_setopt(&curl_handle, CURLOPT_FILE, body_handle.clone());
diff --git a/crates/shirabe/src/util/http_downloader.rs b/crates/shirabe/src/util/http_downloader.rs
index d5d619d..0c7308d 100644
--- a/crates/shirabe/src/util/http_downloader.rs
+++ b/crates/shirabe/src/util/http_downloader.rs
@@ -7,8 +7,8 @@ use crate::util::Silencer;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
InvalidArgumentException, LogicException, PhpMixed, array_replace_recursive, chr,
- extension_loaded, file_get_contents, function_exists, implode, is_numeric, max, min,
- rawurldecode, stream_context_create, stripos, strpos, substr, ucfirst,
+ extension_loaded, file_get_contents, function_exists, implode, is_numeric, rawurldecode,
+ stream_context_create, stripos, strpos, substr, ucfirst,
};
use shirabe_semver::constraint::AnyConstraint;
use shirabe_semver::constraint::SimpleConstraint;
@@ -148,13 +148,12 @@ impl HttpDownloader {
None => PhpMixed::Bool(false),
};
if is_numeric(&max_jobs_env_mixed) {
- max_jobs = max(
- 1,
- min(
- 50,
- max_jobs_env.as_deref().unwrap_or("0").parse().unwrap_or(0),
- ),
- );
+ max_jobs = max_jobs_env
+ .as_deref()
+ .unwrap_or("0")
+ .parse()
+ .unwrap_or(0)
+ .clamp(1, 50);
}
Self {
diff --git a/crates/shirabe/src/util/no_proxy_pattern.rs b/crates/shirabe/src/util/no_proxy_pattern.rs
index ed93414..08cd92f 100644
--- a/crates/shirabe/src/util/no_proxy_pattern.rs
+++ b/crates/shirabe/src/util/no_proxy_pattern.rs
@@ -6,8 +6,8 @@ use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
FILTER_VALIDATE_INT, FILTER_VALIDATE_IP, PHP_URL_HOST, PHP_URL_PORT, PHP_URL_SCHEME, PhpMixed,
RuntimeException, array_key_exists, chr, empty, explode, filter_var, filter_var_with_options,
- floor, inet_pton, ltrim, parse_url, str_pad, str_repeat, stripos, strlen, strpbrk, strpos,
- substr, substr_count, unpack,
+ inet_pton, ltrim, parse_url, str_pad, str_repeat, stripos, strlen, strpbrk, strpos, substr,
+ substr_count, unpack,
};
/// Tests URLs against NO_PROXY patterns
@@ -314,7 +314,7 @@ impl NoProxyPattern {
fn ip_get_mask(&self, prefix: i64, size: i64) -> Vec<u8> {
let mut mask = String::new();
- let ones = floor(prefix as f64 / 8.0) as i64;
+ let ones = (prefix as f64 / 8.0).floor() as i64;
if ones != 0 {
mask = str_repeat(&chr(255), ones as usize);
}
diff --git a/crates/shirabe/src/util/process_executor.rs b/crates/shirabe/src/util/process_executor.rs
index 61fc0a1..1f15795 100644
--- a/crates/shirabe/src/util/process_executor.rs
+++ b/crates/shirabe/src/util/process_executor.rs
@@ -14,8 +14,8 @@ use shirabe_external_packages::symfony::process::exception::RuntimeException as
use shirabe_php_shim::{
LogicException, PhpMixed, RuntimeException, array_intersect, array_map, call_user_func,
defined, escapeshellarg, explode, implode, in_array, is_array, is_callable, is_dir, is_numeric,
- is_string, max, min, rtrim, sprintf, str_replace, strcspn, strlen, strpbrk, strtolower,
- strtr_array, substr_replace, trim, usleep,
+ is_string, rtrim, sprintf, str_replace, strcspn, strlen, strpbrk, strtolower, strtr_array,
+ substr_replace, trim, usleep,
};
use crate::io::IOInterface;
@@ -540,13 +540,12 @@ impl ProcessExecutor {
None => PhpMixed::Null,
};
if is_numeric(&max_jobs_env_mixed) {
- self.max_jobs = max(
- 1,
- min(
- 50,
- max_jobs_env.as_deref().unwrap_or("0").parse().unwrap_or(0),
- ),
- );
+ self.max_jobs = max_jobs_env
+ .as_deref()
+ .unwrap_or("0")
+ .parse()
+ .unwrap_or(0)
+ .clamp(1, 50);
} else {
self.max_jobs = 10;
}
diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs
index c4b3923..bada2af 100644
--- a/crates/shirabe/src/util/remote_filesystem.rs
+++ b/crates/shirabe/src/util/remote_filesystem.rs
@@ -778,10 +778,9 @@ impl RemoteFilesystem {
}
x if x == STREAM_NOTIFY_PROGRESS => {
if self.bytes_max > 0 && self.progress {
- let progression = std::cmp::min(
- 100_i64,
- ((bytes_transferred as f64 / self.bytes_max as f64) * 100.0).round() as i64,
- );
+ let progression = (((bytes_transferred as f64 / self.bytes_max as f64) * 100.0)
+ .round() as i64)
+ .min(100_i64);
if 0 == progression % 5
&& 100 != progression