diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-08 03:04:27 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-08 03:04:27 +0900 |
| commit | da0d38a8e16ebefd59ef5291b5788e6238cc78ba (patch) | |
| tree | c6a4cb9f2444beeb84b2d30133053867acb46741 /crates/shirabe/src/command/show_command.rs | |
| parent | c0879ab4a02b257cb0bd416dbdfa07784c8e3809 (diff) | |
| download | php-shirabe-da0d38a8e16ebefd59ef5291b5788e6238cc78ba.tar.gz php-shirabe-da0d38a8e16ebefd59ef5291b5788e6238cc78ba.tar.zst php-shirabe-da0d38a8e16ebefd59ef5291b5788e6238cc78ba.zip | |
refactor(semver): replace Constraint's OP_*/STR_OP_* with CmpOp
PHP's version_compare takes its operator as a string, so the shim's port
did too, and Constraint carried two families of operator constants plus
translation tables to convert between the string form and its own int
codes. Five copies of those tables had accumulated across Constraint,
CompilingMatcher and the plugin value bridge.
version_compare now takes a CmpOp, which makes an invalid operator
unrepresentable and removes the tables' reason to exist. Constraint
stores a CmpOp and keeps only the string parsing its constructor needs;
getOperator, compile and CompilingMatcher::match speak CmpOp as well.
PHP's OP_* numbering stays observable: a plugin reads the raw integer off
the Constraint object over RPC, so get_operator_constant and its new
inverse hold that 0..5 mapping.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/command/show_command.rs')
| -rw-r--r-- | crates/shirabe/src/command/show_command.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs index ff20f325..aa63d8e7 100644 --- a/crates/shirabe/src/command/show_command.rs +++ b/crates/shirabe/src/command/show_command.rs @@ -43,7 +43,7 @@ use shirabe_external_packages::symfony::console::formatter::OutputFormatterStyle use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::output::OutputInterface; use shirabe_php_shim::{ - DATE_ATOM, InvalidArgumentException, LogicException, PhpMixed, UnexpectedValueException, + CmpOp, DATE_ATOM, InvalidArgumentException, LogicException, PhpMixed, UnexpectedValueException, array_search, date, date_format_to_strftime, extension_loaded, impl_php_class, in_array_loose, in_array_strict, php_regex, realpath, strtolower, version_compare, }; @@ -841,9 +841,9 @@ impl ShowCommand { .collect(); // uasort($versions, 'version_compare'); versions_pairs.sort_by(|a, b| { - if version_compare(&a.1, &b.1, "<") { + if version_compare(&a.1, &b.1, CmpOp::Lt) { std::cmp::Ordering::Less - } else if version_compare(&a.1, &b.1, ">") { + } else if version_compare(&a.1, &b.1, CmpOp::Gt) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -1432,7 +1432,7 @@ impl ShowCommand { return false; } - version_compare(&candidate.get_version(), &package_version, "<=") + version_compare(&candidate.get_version(), &package_version, CmpOp::Le) }, )) }; @@ -2343,9 +2343,11 @@ impl Command for ShowCommand { let need_replace = match existing { None => true, Some(PackageOrName::Name(_)) => true, - Some(PackageOrName::Pkg(existing)) => { - version_compare(&existing.get_version(), &package.get_version(), "<") - } + Some(PackageOrName::Pkg(existing)) => version_compare( + &existing.get_version(), + &package.get_version(), + CmpOp::Lt, + ), }; if need_replace { let mut p: crate::package::PackageInterfaceHandle = package.clone(); |
