diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-21 17:02:52 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-21 17:12:37 +0900 |
| commit | 84fe6ac6977f15cbec85cbc9f773567742a7fb87 (patch) | |
| tree | 5701e7c980585dd404471ab9fa53e98a0ba601ab /crates/shirabe | |
| parent | 12a7756588a20f1351e6976f0c009de5992514a9 (diff) | |
| download | php-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')
| -rw-r--r-- | crates/shirabe/src/cache.rs | 8 | ||||
| -rw-r--r-- | crates/shirabe/src/command/base_command.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/src/command/diagnose_command.rs | 8 | ||||
| -rw-r--r-- | crates/shirabe/src/config.rs | 20 | ||||
| -rw-r--r-- | crates/shirabe/src/console/application.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/src/dependency_resolver/pool.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/src/dependency_resolver/rule.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/src/event_dispatcher/event_dispatcher.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/src/installer.rs | 2 | ||||
| -rw-r--r-- | crates/shirabe/src/json/json_manipulator.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/svn_driver.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/src/util/http/curl_downloader.rs | 12 | ||||
| -rw-r--r-- | crates/shirabe/src/util/http_downloader.rs | 17 | ||||
| -rw-r--r-- | crates/shirabe/src/util/no_proxy_pattern.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/src/util/process_executor.rs | 17 | ||||
| -rw-r--r-- | crates/shirabe/src/util/remote_filesystem.rs | 7 |
16 files changed, 65 insertions, 66 deletions
diff --git a/crates/shirabe/src/cache.rs b/crates/shirabe/src/cache.rs index 315ba2c..8d9473a 100644 --- a/crates/shirabe/src/cache.rs +++ b/crates/shirabe/src/cache.rs @@ -7,9 +7,9 @@ use chrono::Utc; use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_external_packages::symfony::finder::Finder; use shirabe_php_shim::{ - ErrorException, abs, bin2hex, clearstatcache, date_format_to_strftime, dirname, - disk_free_space, file_exists, file_get_contents, file_put_contents, filemtime, function_exists, - hash_file, is_dir, is_writable, mkdir, random_bytes, random_int, rename, time, unlink, + ErrorException, bin2hex, clearstatcache, date_format_to_strftime, dirname, disk_free_space, + file_exists, file_get_contents, file_put_contents, filemtime, function_exists, hash_file, + is_dir, is_writable, mkdir, random_bytes, random_int, rename, time, unlink, }; use crate::io::IOInterface; @@ -308,7 +308,7 @@ impl Cache { if file_exists(&full_path) && let Some(mtime) = filemtime(&full_path) { - return Some(abs(time() - mtime)); + return Some((time() - mtime).abs()); } } diff --git a/crates/shirabe/src/command/base_command.rs b/crates/shirabe/src/command/base_command.rs index 40253d4..c4bfaef 100644 --- a/crates/shirabe/src/command/base_command.rs +++ b/crates/shirabe/src/command/base_command.rs @@ -13,7 +13,7 @@ use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::output::OutputInterface; use shirabe_php_shim::{ AsAny, InvalidArgumentException, LogicException, PhpMixed, RuntimeException, - UnexpectedValueException, count, explode, in_array, is_string, max, + UnexpectedValueException, count, explode, in_array, is_string, }; use std::cell::RefCell; use std::rc::Rc; @@ -590,7 +590,7 @@ impl BaseCommand for BaseCommandData { if Platform::is_windows() { width -= 1; } else { - width = max(80, width); + width = width.max(80); } width diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs index 304f26f..43e878d 100644 --- a/crates/shirabe/src/command/diagnose_command.rs +++ b/crates/shirabe/src/command/diagnose_command.rs @@ -16,8 +16,8 @@ use shirabe_php_shim::{ PHP_WINDOWS_VERSION_BUILD, PhpMixed, RuntimeException, count, curl_version, defined, disk_free_space, extension_loaded, file_exists, filter_var, function_exists, get_class, get_class_err, hash, implode, ini_get, ioncube_loader_iversion, ioncube_loader_version, - is_array, is_string, key, max, ob_get_clean, ob_start, phpinfo, reset, rtrim, sprintf, - str_contains, str_replace, str_starts_with, strpos, strstr, strtolower, trim, version_compare, + is_array, is_string, key, ob_get_clean, ob_start, phpinfo, reset, rtrim, sprintf, str_contains, + str_replace, str_starts_with, strpos, strstr, strtolower, trim, version_compare, }; use std::cell::RefCell; use std::rc::Rc; @@ -1141,9 +1141,9 @@ impl DiagnoseCommand { } // Apply exit code updates after io borrow ends if had_error { - self.exit_code = max(prev_exit_code, 2); + self.exit_code = prev_exit_code.max(2); } else if had_warning { - self.exit_code = max(prev_exit_code, 1); + self.exit_code = prev_exit_code.max(1); } } diff --git a/crates/shirabe/src/config.rs b/crates/shirabe/src/config.rs index 2c39db5..b65961e 100644 --- a/crates/shirabe/src/config.rs +++ b/crates/shirabe/src/config.rs @@ -14,8 +14,7 @@ use shirabe_php_shim::{ E_USER_DEPRECATED, FILTER_VALIDATE_URL, PHP_URL_HOST, PHP_URL_SCHEME, PhpMixed, RuntimeException, array_key_exists, array_merge, array_reverse, array_search_mixed, array_unique, current, empty, filter_var, implode, in_array, is_array, is_int, is_string, key, - max, parse_url, php_to_string, reset, rtrim, strtolower, strtoupper, strtr, substr, - trigger_error, + parse_url, php_to_string, reset, rtrim, strtolower, strtoupper, strtr, substr, trigger_error, }; use std::cell::RefCell; @@ -587,7 +586,7 @@ impl Config { } else { val.clone() }; - return Ok(PhpMixed::Int(max(0, raw.as_int().unwrap_or(0)))); + return Ok(PhpMixed::Int(raw.as_int().unwrap_or(0).max(0))); } let raw_val = if matches!(val, PhpMixed::Bool(false)) { @@ -647,10 +646,13 @@ impl Config { } // ints without env var support - "cache-ttl" => Ok(PhpMixed::Int(max( - 0, - self.config.get(key).and_then(|v| v.as_int()).unwrap_or(0), - ))), + "cache-ttl" => Ok(PhpMixed::Int( + self.config + .get(key) + .and_then(|v| v.as_int()) + .unwrap_or(0) + .max(0), + )), // numbers with kb/mb/gb support, without env var support "cache-files-maxsize" => { @@ -697,7 +699,7 @@ impl Config { } } - Ok(PhpMixed::Int(max(0, size as i64))) + Ok(PhpMixed::Int((size as i64).max(0))) } // special cases below @@ -706,7 +708,7 @@ impl Config { if let Some(v) = v && !v.is_null() { - return Ok(PhpMixed::Int(max(0, v.as_int().unwrap_or(0)))); + return Ok(PhpMixed::Int(v.as_int().unwrap_or(0).max(0))); } self.get_with_flags("cache-ttl", 0) diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index 22b857d..94f904f 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -56,7 +56,7 @@ use shirabe_php_shim::{ date_default_timezone_get, date_default_timezone_set, defined, dirname, disk_free_space, error_get_last, extension_loaded, file_exists, file_get_contents, file_put_contents, function_exists, get_class, getcwd, getmypid, glob, in_array, ini_set, is_array, is_dir, - is_file, is_string, is_subclass_of, json_decode, max, memory_get_peak_usage, memory_get_usage, + is_file, is_string, is_subclass_of, json_decode, memory_get_peak_usage, memory_get_usage, method_exists, microtime, php_uname, posix_getuid, random_bytes, realpath, register_shutdown_function, restore_error_handler, round, sprintf, str_contains, str_replace, strpos, strtoupper, sys_get_temp_dir, time, unlink, @@ -2428,7 +2428,7 @@ impl Application { // pre-format lines to get the right string length let line_length = Helper::width(&line) + 4; lines.push((line, line_length)); - len = shirabe_php_shim::max(line_length, len); + len = std::cmp::max(line_length, len); } } @@ -2455,7 +2455,7 @@ impl Application { title, shirabe_php_shim::str_repeat( " ", - std::cmp::max(0, len - Helper::width(&title)) as usize + (len - Helper::width(&title)).max(0) as usize ) )); } diff --git a/crates/shirabe/src/dependency_resolver/pool.rs b/crates/shirabe/src/dependency_resolver/pool.rs index 7b60002..b25f348 100644 --- a/crates/shirabe/src/dependency_resolver/pool.rs +++ b/crates/shirabe/src/dependency_resolver/pool.rs @@ -3,7 +3,7 @@ use std::fmt; use indexmap::IndexMap; -use shirabe_php_shim::{STR_PAD_LEFT, abs, str_pad}; +use shirabe_php_shim::{STR_PAD_LEFT, str_pad}; use shirabe_semver::compiling_matcher::CompilingMatcher; use shirabe_semver::constraint::AnyConstraint; use shirabe_semver::constraint::SimpleConstraint; @@ -280,7 +280,7 @@ impl Pool { } pub fn literal_to_package(&self, literal: i64) -> BasePackageHandle { - let package_id = abs(literal); + let package_id = literal.abs(); self.package_by_id(package_id) } diff --git a/crates/shirabe/src/dependency_resolver/rule.rs b/crates/shirabe/src/dependency_resolver/rule.rs index 30fa079..7686a3e 100644 --- a/crates/shirabe/src/dependency_resolver/rule.rs +++ b/crates/shirabe/src/dependency_resolver/rule.rs @@ -7,7 +7,7 @@ use std::rc::Rc; use anyhow::Result; use indexmap::IndexMap; use shirabe_php_shim::{ - LogicException, PhpMixed, RuntimeException, abs, array_filter, array_keys, array_shift, + LogicException, PhpMixed, RuntimeException, array_filter, array_keys, array_shift, array_values, implode, is_object, }; use shirabe_semver::constraint::AnyConstraint; @@ -554,7 +554,7 @@ impl Rule { let mut installed_packages: Vec<BasePackageHandle> = vec![]; let mut removable_packages: Vec<BasePackageHandle> = vec![]; for literal in &literals { - if installed_map.contains_key(&abs(*literal).to_string()) { + if installed_map.contains_key(&literal.abs().to_string()) { installed_packages.push(pool.literal_to_package(*literal)); } else { removable_packages.push(pool.literal_to_package(*literal)); diff --git a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs index bd14fea..d3b5fad 100644 --- a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs +++ b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs @@ -9,7 +9,7 @@ use shirabe_php_shim::{ Exception, InvalidArgumentException, LogicException, PATH_SEPARATOR, PHP_VERSION_ID, PhpMixed, RuntimeException, array_pop, array_push, array_search_in_vec, array_splice, class_exists, count_mixed, defined, file_exists, get_class, hash, implode, ini_get, is_a, is_array, - is_callable, is_object, is_string, krsort, max, method_exists, preg_quote, realpath, + is_callable, is_object, is_string, krsort, method_exists, preg_quote, realpath, spl_autoload_functions, spl_autoload_register, spl_autoload_unregister, spl_object_hash, sprintf, str_contains, str_ends_with, str_replace, str_starts_with, strlen, strpos, strtoupper, substr, trim, @@ -763,7 +763,7 @@ impl EventDispatcher { } } - return_max = max(return_max, r#return); + return_max = std::cmp::max(return_max, r#return); if event.is_propagation_stopped() { break; diff --git a/crates/shirabe/src/installer.rs b/crates/shirabe/src/installer.rs index 6fe4f1f..8149b05 100644 --- a/crates/shirabe/src/installer.rs +++ b/crates/shirabe/src/installer.rs @@ -37,7 +37,7 @@ use shirabe_external_packages::seld::json_lint::ParsingException; use shirabe_php_shim::{ PhpMixed, RuntimeException, array_flip, array_map, array_merge, array_unique, array_values, clone, count, defined, gc_collect_cycles, gc_disable, gc_enable, get_class, implode, in_array, - intval, is_dir, is_numeric, is_string, max, sprintf, strcmp, strpos, strtolower, touch, usort, + intval, is_dir, is_numeric, is_string, sprintf, strcmp, strpos, strtolower, touch, usort, }; use shirabe_semver; diff --git a/crates/shirabe/src/json/json_manipulator.rs b/crates/shirabe/src/json/json_manipulator.rs index f5ad2cd..904ea7a 100644 --- a/crates/shirabe/src/json/json_manipulator.rs +++ b/crates/shirabe/src/json/json_manipulator.rs @@ -6,7 +6,7 @@ use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_php_shim::{ ArrayObject, InvalidArgumentException, LogicException, PhpMixed, StdClass, addcslashes, array_key_exists, array_keys, array_reverse, count, empty, explode, implode, in_array, - is_array, is_int, is_numeric, json_decode, max, preg_quote, rtrim, str_contains, str_repeat, + is_array, is_int, is_numeric, json_decode, preg_quote, rtrim, str_contains, str_repeat, str_replace, strlen, strnatcmp, strpos, substr, trim, uksort, }; @@ -351,7 +351,7 @@ impl JsonManipulator { list_regex = Some(format!( "{{{}^(?P<start>\\s*\\{{\\s*(?:(?&string)\\s*:\\s*(?&json)\\s*,\\s*)*?\"repositories\"\\s*:\\s*\\[\\s*((?&json)\\s*+,\\s*+){{{}}})(?P<repository>(?&object))(?P<end>.*)}}sx", Self::DEFINES, - max(0, i_val) + i_val.max(0) )); } @@ -1251,7 +1251,7 @@ impl JsonManipulator { let list_skip_to_item_regex = format!( "{{{}^(?P<start>\\[\\s*((?&json)\\s*+,\\s*?){{{}}})(?P<space_before_item>(\\s*))(?P<end>.*)}}sx", Self::DEFINES, - max(0, index) + index.max(0) ); let value_capture = value.clone(); diff --git a/crates/shirabe/src/repository/vcs/svn_driver.rs b/crates/shirabe/src/repository/vcs/svn_driver.rs index 96a1b38..e68beb6 100644 --- a/crates/shirabe/src/repository/vcs/svn_driver.rs +++ b/crates/shirabe/src/repository/vcs/svn_driver.rs @@ -5,7 +5,7 @@ use chrono::{DateTime, FixedOffset, Utc}; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_php_shim::{ - PhpMixed, RuntimeException, array_key_exists, is_array, max, sprintf, stripos, strrpos, strtr, + PhpMixed, RuntimeException, array_key_exists, is_array, sprintf, stripos, strrpos, strtr, substr, trim, }; @@ -362,7 +362,7 @@ impl SvnDriver { } else { let identifier = self.build_identifier( &format!("/{}/{}", self.tags_path, path), - max(last_rev, rev), + std::cmp::max(last_rev, rev), ); tags.insert(path.trim_end_matches('/').to_string(), identifier); } @@ -451,7 +451,7 @@ impl SvnDriver { } else { let identifier = self.build_identifier( &format!("/{}/{}", self.branches_path, path), - max(last_rev, rev), + std::cmp::max(last_rev, rev), ); branches .insert(path.trim_end_matches('/').to_string(), identifier); 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 |
