diff options
Diffstat (limited to 'crates/shirabe/src/plugin')
| -rw-r--r-- | crates/shirabe/src/plugin/php_plugin_value.rs | 25 | ||||
| -rw-r--r-- | crates/shirabe/src/plugin/plugin_manager.rs | 6 |
2 files changed, 9 insertions, 22 deletions
diff --git a/crates/shirabe/src/plugin/php_plugin_value.rs b/crates/shirabe/src/plugin/php_plugin_value.rs index cdef2a79..a61d4873 100644 --- a/crates/shirabe/src/plugin/php_plugin_value.rs +++ b/crates/shirabe/src/plugin/php_plugin_value.rs @@ -68,20 +68,6 @@ fn required_string(context: &str, value: Option<&PluginValue>) -> Result<String, } } -/// PHP's `Constraint` keeps the operator as one of its `OP_*` codes, not as the string its -/// constructor takes. -fn operator_from_code(code: i64) -> Option<&'static str> { - Some(match code { - SimpleConstraint::OP_EQ => SimpleConstraint::STR_OP_EQ, - SimpleConstraint::OP_LT => SimpleConstraint::STR_OP_LT, - SimpleConstraint::OP_LE => SimpleConstraint::STR_OP_LE, - SimpleConstraint::OP_GT => SimpleConstraint::STR_OP_GT, - SimpleConstraint::OP_GE => SimpleConstraint::STR_OP_GE, - SimpleConstraint::OP_NE => SimpleConstraint::STR_OP_NE, - _ => return None, - }) -} - fn constraint_to_wire(constraint: &AnyConstraint) -> PluginValue { // Whether the pretty string was ever set is observable (`getPrettyString()` falls back to the // string form), so an unset one crosses as null rather than as an absent property. @@ -144,11 +130,12 @@ fn constraint_from_wire(value: &PluginValue) -> Result<AnyConstraint, PhpThrow> Ok(match object.class.as_str() { CONSTRAINT_CLASS => { let operator = match object.protected("operator") { - Some(PluginValue::Int(code)) => operator_from_code(*code).ok_or_else(|| { - throw(format!( - "a semver constraint has an unknown operator: {code}" - )) - })?, + Some(PluginValue::Int(code)) => SimpleConstraint::from_operator_constant(*code) + .ok_or_else(|| { + throw(format!( + "a semver constraint has an unknown operator: {code}" + )) + })?, other => { return Err(throw(format!( "a semver constraint operator is not an int, got {other:?}" diff --git a/crates/shirabe/src/plugin/plugin_manager.rs b/crates/shirabe/src/plugin/plugin_manager.rs index 8f005079..18239ce9 100644 --- a/crates/shirabe/src/plugin/plugin_manager.rs +++ b/crates/shirabe/src/plugin/plugin_manager.rs @@ -27,7 +27,7 @@ use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::Preg; use shirabe_php_rpc::{PluginValue, call_function_with_dispatcher}; use shirabe_php_shim::{ - E_USER_DEPRECATED, PhpMixed, RuntimeException, UnexpectedValueException, dirname, empty, + CmpOp, E_USER_DEPRECATED, PhpMixed, RuntimeException, UnexpectedValueException, dirname, empty, file_get_contents, implode, ksort, php_regex, preg_quote, strrpos, strtr_array, substr, trigger_error, trim, var_export, var_export_str, version_compare, }; @@ -263,7 +263,7 @@ impl PluginManager { if package.get_name() == "symfony/flex" && Preg::is_match3(php_regex!("{^[0-9.]+$}"), &package.get_version(), None) - && version_compare(&package.get_version(), "1.9.8", "<") + && version_compare(&package.get_version(), "1.9.8", CmpOp::Lt) { self.io.write_error(&format!("<warning>The \"{}\" plugin {}was skipped because it is not compatible with Composer 2+. Make sure to update it to version 1.9.8 or greater.</warning>", package.get_name(), @@ -1171,7 +1171,7 @@ impl PluginManager { Some(l) => { if l.is_locked() { let api = l.get_plugin_api().unwrap_or_default(); - version_compare(&api, "2.2.0", "<") + version_compare(&api, "2.2.0", CmpOp::Lt) } else { false } |
