diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-21 16:48:03 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-21 16:50:58 +0900 |
| commit | 12a7756588a20f1351e6976f0c009de5992514a9 (patch) | |
| tree | 53ee08e207fc06687d998e9ad749e425e56ee138 | |
| parent | 657440d01423b50153d07ebc288d9bd2fc982d52 (diff) | |
| download | php-shirabe-12a7756588a20f1351e6976f0c009de5992514a9.tar.gz php-shirabe-12a7756588a20f1351e6976f0c009de5992514a9.tar.zst php-shirabe-12a7756588a20f1351e6976f0c009de5992514a9.zip | |
feat(php-shim): implement round() shim
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
| -rw-r--r-- | crates/shirabe-php-shim/src/math.rs | 29 | ||||
| -rw-r--r-- | crates/shirabe/src/command/diagnose_command.rs | 6 | ||||
| -rw-r--r-- | crates/shirabe/src/console/application.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/src/event_dispatcher/event_dispatcher.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/src/installer.rs | 3 | ||||
| -rw-r--r-- | crates/shirabe/src/json/json_manipulator.rs | 8 |
6 files changed, 25 insertions, 29 deletions
diff --git a/crates/shirabe-php-shim/src/math.rs b/crates/shirabe-php-shim/src/math.rs index fffe2d6..ee9a76d 100644 --- a/crates/shirabe-php-shim/src/math.rs +++ b/crates/shirabe-php-shim/src/math.rs @@ -1,33 +1,30 @@ -pub fn max_i64(_a: i64, _b: i64) -> i64 { - _a.max(_b) +pub fn max(a: i64, b: i64) -> i64 { + a.max(b) } -pub fn max(_a: i64, _b: i64) -> i64 { - _a.max(_b) +pub fn min(a: i64, b: i64) -> i64 { + a.min(b) } -pub fn min(_a: i64, _b: i64) -> i64 { - _a.min(_b) +pub fn abs(v: i64) -> i64 { + v.abs() } -pub fn abs(_value: i64) -> i64 { - _value.abs() -} - -pub fn floor(_value: f64) -> f64 { - _value.floor() +pub fn floor(v: f64) -> f64 { + v.floor() } pub fn ceil(v: f64) -> f64 { v.ceil() } -pub fn round(_value: f64, _precision: i64) -> f64 { - todo!() +pub fn round(v: f64, precision: i64) -> f64 { + // PHP's default mode is PHP_ROUND_HALF_UP (round half away from zero), + // which matches Rust's f64::round. + let factor = 10f64.powi(precision as i32); + (v * factor).round() / factor } pub fn intdiv(a: i64, b: i64) -> i64 { - // PHP intdiv() throws DivisionByZeroError on a zero divisor and ArithmeticError - // for PHP_INT_MIN / -1; Rust's `/` likewise panics in both cases. a / b } diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs index 739adad..304f26f 100644 --- a/crates/shirabe/src/command/diagnose_command.rs +++ b/crates/shirabe/src/command/diagnose_command.rs @@ -16,7 +16,7 @@ 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_i64, ob_get_clean, ob_start, phpinfo, reset, rtrim, sprintf, + 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, }; use std::cell::RefCell; @@ -1141,9 +1141,9 @@ impl DiagnoseCommand { } // Apply exit code updates after io borrow ends if had_error { - self.exit_code = max_i64(prev_exit_code, 2); + self.exit_code = max(prev_exit_code, 2); } else if had_warning { - self.exit_code = max_i64(prev_exit_code, 1); + self.exit_code = max(prev_exit_code, 1); } } diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index 7fa6720..22b857d 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -56,8 +56,8 @@ 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_i64, memory_get_peak_usage, - memory_get_usage, method_exists, microtime, php_uname, posix_getuid, random_bytes, realpath, + is_file, is_string, is_subclass_of, json_decode, max, 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, }; diff --git a/crates/shirabe/src/event_dispatcher/event_dispatcher.rs b/crates/shirabe/src/event_dispatcher/event_dispatcher.rs index 3ad6ad9..bd14fea 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_i64, method_exists, preg_quote, realpath, + is_callable, is_object, is_string, krsort, max, 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_i64(return_max, r#return); + return_max = 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 31af702..6fe4f1f 100644 --- a/crates/shirabe/src/installer.rs +++ b/crates/shirabe/src/installer.rs @@ -37,8 +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_i64, sprintf, strcmp, strpos, strtolower, touch, - usort, + intval, is_dir, is_numeric, is_string, max, 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 75f933c..f5ad2cd 100644 --- a/crates/shirabe/src/json/json_manipulator.rs +++ b/crates/shirabe/src/json/json_manipulator.rs @@ -6,8 +6,8 @@ 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_i64, preg_quote, rtrim, str_contains, - str_repeat, str_replace, strlen, strnatcmp, strpos, substr, trim, uksort, + is_array, is_int, is_numeric, json_decode, max, preg_quote, rtrim, str_contains, str_repeat, + str_replace, strlen, strnatcmp, strpos, substr, trim, uksort, }; use crate::json::JsonFile; @@ -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_i64(0, i_val) + max(0, i_val) )); } @@ -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_i64(0, index) + max(0, index) ); let value_capture = value.clone(); |
