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-semver/src/constraint/any_constraint.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-semver/src/constraint/any_constraint.rs')
| -rw-r--r-- | crates/shirabe-semver/src/constraint/any_constraint.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/crates/shirabe-semver/src/constraint/any_constraint.rs b/crates/shirabe-semver/src/constraint/any_constraint.rs index 37541deb..33c2f7d0 100644 --- a/crates/shirabe-semver/src/constraint/any_constraint.rs +++ b/crates/shirabe-semver/src/constraint/any_constraint.rs @@ -5,6 +5,7 @@ use crate::constraint::MatchAllConstraint; use crate::constraint::MatchNoneConstraint; use crate::constraint::MultiConstraint; use crate::constraint::SimpleConstraint; +use shirabe_php_shim::CmpOp; /// Corresponds to PHP's `ConstraintInterface`. #[derive(Clone, Debug)] @@ -36,7 +37,7 @@ impl AnyConstraint { } } - pub fn compile(&self, other_operator: i64) -> String { + pub fn compile(&self, other_operator: CmpOp) -> String { match self { Self::Simple(c) => c.compile(other_operator), Self::Multi(c) => c.compile(other_operator), @@ -82,10 +83,10 @@ impl AnyConstraint { matches!(self, Self::Simple(_)) } - pub fn get_operator(&self) -> &'static str { + pub fn get_operator(&self) -> Option<CmpOp> { match self { - Self::Simple(c) => c.get_operator(), - _ => "", + Self::Simple(c) => Some(c.get_operator()), + _ => None, } } |
