aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-08 03:04:27 +0900
committernsfisis <nsfisis@gmail.com>2026-08-08 03:04:27 +0900
commitda0d38a8e16ebefd59ef5291b5788e6238cc78ba (patch)
treec6a4cb9f2444beeb84b2d30133053867acb46741 /crates/shirabe/src
parentc0879ab4a02b257cb0bd416dbdfa07784c8e3809 (diff)
downloadphp-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')
-rw-r--r--crates/shirabe/src/command/diagnose_command.rs16
-rw-r--r--crates/shirabe/src/command/show_command.rs16
-rw-r--r--crates/shirabe/src/dependency_resolver/default_policy.rs3
-rw-r--r--crates/shirabe/src/dependency_resolver/pool.rs8
-rw-r--r--crates/shirabe/src/dependency_resolver/pool_builder.rs5
-rw-r--r--crates/shirabe/src/dependency_resolver/pool_optimizer.rs20
-rw-r--r--crates/shirabe/src/dependency_resolver/problem.rs20
-rw-r--r--crates/shirabe/src/downloader/git_downloader.rs4
-rw-r--r--crates/shirabe/src/downloader/svn_downloader.rs8
-rw-r--r--crates/shirabe/src/downloader/zip_downloader.rs10
-rw-r--r--crates/shirabe/src/package/loader/validating_array_loader.rs10
-rw-r--r--crates/shirabe/src/package/version/version_selector.rs6
-rw-r--r--crates/shirabe/src/platform/version.rs4
-rw-r--r--crates/shirabe/src/plugin/php_plugin_value.rs25
-rw-r--r--crates/shirabe/src/plugin/plugin_manager.rs6
-rw-r--r--crates/shirabe/src/repository/composer_repository.rs4
-rw-r--r--crates/shirabe/src/util/git.rs14
-rw-r--r--crates/shirabe/src/util/package_sorter.rs4
18 files changed, 82 insertions, 101 deletions
diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs
index 65240e51..72b58dea 100644
--- a/crates/shirabe/src/command/diagnose_command.rs
+++ b/crates/shirabe/src/command/diagnose_command.rs
@@ -39,10 +39,10 @@ use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
use shirabe_external_packages::symfony::process::ExecutableFinder;
use shirabe_php_shim::{
- InvalidArgumentException, PHP_EOL, PhpMixed, disk_free_space, file_exists, filter_var_boolean,
- get_class_err, hash, impl_php_class, implode, is_array, is_string, php_regex, rtrim,
- str_contains, str_replace, str_starts_with, strpos, strstr, strstr3, strtolower, trim,
- version_compare,
+ CmpOp, InvalidArgumentException, PHP_EOL, PhpMixed, disk_free_space, file_exists,
+ filter_var_boolean, get_class_err, hash, impl_php_class, implode, is_array, is_string,
+ php_regex, rtrim, str_contains, str_replace, str_starts_with, strpos, strstr, strstr3,
+ strtolower, trim, version_compare,
};
#[derive(Debug)]
@@ -153,7 +153,7 @@ impl DiagnoseCommand {
None => return "<comment>No git process found</>".to_string(),
};
- if version_compare("2.24.0", &git_version, ">") {
+ if version_compare("2.24.0", &git_version, CmpOp::Gt) {
return format!(
"<warning>Your git version ({}) is too old and possibly will cause issues. Please upgrade to git 2.24 or above</>",
git_version
@@ -889,9 +889,9 @@ impl DiagnoseCommand {
}
if diagnostics.has_php_windows_version_build
- && (version_compare(&diagnostics.php_version, "7.2.23", "<")
- || (version_compare(&diagnostics.php_version, "7.3.0", ">=")
- && version_compare(&diagnostics.php_version, "7.3.10", "<")))
+ && (version_compare(&diagnostics.php_version, "7.2.23", CmpOp::Lt)
+ || (version_compare(&diagnostics.php_version, "7.3.0", CmpOp::Ge)
+ && version_compare(&diagnostics.php_version, "7.3.10", CmpOp::Lt)))
{
warnings.insert(
"onedrive".to_string(),
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();
diff --git a/crates/shirabe/src/dependency_resolver/default_policy.rs b/crates/shirabe/src/dependency_resolver/default_policy.rs
index d81c8621..8c1a7697 100644
--- a/crates/shirabe/src/dependency_resolver/default_policy.rs
+++ b/crates/shirabe/src/dependency_resolver/default_policy.rs
@@ -6,6 +6,7 @@ use crate::package::BasePackageHandle;
use crate::package::STABILITIES;
use crate::util::Platform;
use indexmap::IndexMap;
+use shirabe_php_shim::CmpOp;
use shirabe_php_shim::PhpMixed;
use shirabe_semver::CompilingMatcher;
use shirabe_semver::constraint::SimpleConstraint;
@@ -205,7 +206,7 @@ impl PolicyInterface for DefaultPolicy {
CompilingMatcher::r#match(
&SimpleConstraint::new(operator.to_string(), b.get_version(), None).into(),
- SimpleConstraint::OP_EQ,
+ CmpOp::Eq,
a.get_version(),
)
}
diff --git a/crates/shirabe/src/dependency_resolver/pool.rs b/crates/shirabe/src/dependency_resolver/pool.rs
index 80534b0a..a0dfd362 100644
--- a/crates/shirabe/src/dependency_resolver/pool.rs
+++ b/crates/shirabe/src/dependency_resolver/pool.rs
@@ -4,7 +4,7 @@ use crate::advisory::AnySecurityAdvisory;
use crate::package::BasePackageHandle;
use crate::package::version::VersionParser;
use indexmap::IndexMap;
-use shirabe_php_shim::{STR_PAD_LEFT, str_pad};
+use shirabe_php_shim::{CmpOp, STR_PAD_LEFT, str_pad};
use shirabe_semver::CompilingMatcher;
use shirabe_semver::constraint::AnyConstraint;
use shirabe_semver::constraint::SimpleConstraint;
@@ -305,11 +305,7 @@ impl Pool {
if candidate_name == name {
return constraint.is_none()
- || CompilingMatcher::r#match(
- constraint.unwrap(),
- SimpleConstraint::OP_EQ,
- candidate_version,
- );
+ || CompilingMatcher::r#match(constraint.unwrap(), CmpOp::Eq, candidate_version);
}
let provides = candidate.get_provides();
diff --git a/crates/shirabe/src/dependency_resolver/pool_builder.rs b/crates/shirabe/src/dependency_resolver/pool_builder.rs
index 137a36ba..35699a90 100644
--- a/crates/shirabe/src/dependency_resolver/pool_builder.rs
+++ b/crates/shirabe/src/dependency_resolver/pool_builder.rs
@@ -21,7 +21,7 @@ use crate::repository::RootPackageRepository;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
- LogicException, PhpMixed, array_flip_strings, array_map, in_array_strict, microtime,
+ CmpOp, LogicException, PhpMixed, array_flip_strings, array_map, in_array_strict, microtime,
number_format, round, strpos,
};
use shirabe_semver::CompilingMatcher;
@@ -29,7 +29,6 @@ use shirabe_semver::Intervals;
use shirabe_semver::constraint::AnyConstraint;
use shirabe_semver::constraint::MatchAllConstraint;
use shirabe_semver::constraint::MultiConstraint;
-use shirabe_semver::constraint::SimpleConstraint;
#[derive(Debug)]
pub struct PoolBuilder {
@@ -289,7 +288,7 @@ impl PoolBuilder {
for (_idx, package_or_alias) in &package_and_aliases {
if CompilingMatcher::r#match(
&constraint,
- SimpleConstraint::OP_EQ,
+ CmpOp::Eq,
package_or_alias.get_version(),
) {
found = true;
diff --git a/crates/shirabe/src/dependency_resolver/pool_optimizer.rs b/crates/shirabe/src/dependency_resolver/pool_optimizer.rs
index 972d2f21..5aca700e 100644
--- a/crates/shirabe/src/dependency_resolver/pool_optimizer.rs
+++ b/crates/shirabe/src/dependency_resolver/pool_optimizer.rs
@@ -6,7 +6,7 @@ use crate::dependency_resolver::Request;
use crate::package::BasePackageHandle;
use crate::package::version::VersionParser;
use indexmap::IndexMap;
-use shirabe_php_shim::{implode, ksort};
+use shirabe_php_shim::{CmpOp, implode, ksort};
use shirabe_semver::CompilingMatcher;
use shirabe_semver::Intervals;
use shirabe_semver::constraint::AnyConstraint;
@@ -156,11 +156,7 @@ impl PoolOptimizer {
let constraint = irremovable_package_constraints
.get(&package.get_name())
.unwrap();
- if CompilingMatcher::r#match(
- constraint,
- SimpleConstraint::OP_EQ,
- package.get_version().to_string(),
- ) {
+ if CompilingMatcher::r#match(constraint, CmpOp::Eq, package.get_version().to_string()) {
self.mark_package_irremovable(package.clone());
}
}
@@ -252,7 +248,7 @@ impl PoolOptimizer {
if CompilingMatcher::r#match(
require_constraint,
- SimpleConstraint::OP_EQ,
+ CmpOp::Eq,
package.get_version().to_string(),
) {
group_hash_parts.push(format!(
@@ -265,7 +261,7 @@ impl PoolOptimizer {
for (_, link) in package.get_replaces() {
if CompilingMatcher::r#match(
link.get_constraint(),
- SimpleConstraint::OP_EQ,
+ CmpOp::Eq,
package.get_version().to_string(),
) {
// Use the same hash part as the regular require hash because that's what the replacement does
@@ -283,7 +279,7 @@ impl PoolOptimizer {
for (_, conflict_constraint) in conflict_constraints {
if CompilingMatcher::r#match(
conflict_constraint,
- SimpleConstraint::OP_EQ,
+ CmpOp::Eq,
package.get_version().to_string(),
) {
group_hash_parts.push(format!(
@@ -605,11 +601,7 @@ impl PoolOptimizer {
.and_then(|m| m.get(&id))
.map(|p| p.get_version());
if let Some(version_str) = version_str
- && !CompilingMatcher::r#match(
- link_constraint,
- SimpleConstraint::OP_EQ,
- version_str,
- )
+ && !CompilingMatcher::r#match(link_constraint, CmpOp::Eq, version_str)
{
self.mark_package_for_removal(id);
if let Some(map) = package_index.get_mut(require) {
diff --git a/crates/shirabe/src/dependency_resolver/problem.rs b/crates/shirabe/src/dependency_resolver/problem.rs
index 8ee4b816..f9e525bf 100644
--- a/crates/shirabe/src/dependency_resolver/problem.rs
+++ b/crates/shirabe/src/dependency_resolver/problem.rs
@@ -13,8 +13,8 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::symfony::console::formatter::OutputFormatter;
use shirabe_php_shim::{
- LogicException, PhpMixed, defined, extension_loaded, implode, loosely_compare, php_regex,
- phpversion, spl_object_hash, sprintf, str_replace, str_starts_with, stripos, strpos,
+ CmpOp, LogicException, PhpMixed, defined, extension_loaded, implode, loosely_compare,
+ php_regex, phpversion, spl_object_hash, sprintf, str_replace, str_starts_with, stripos, strpos,
strtolower, substr, substr_count, version_compare,
};
use shirabe_semver::constraint::AnyConstraint;
@@ -284,9 +284,9 @@ impl Problem {
// uksort($versions, 'version_compare')
let mut keys: Vec<String> = versions.keys().cloned().collect();
keys.sort_by(|a, b| {
- if version_compare(a, b, "<") {
+ if version_compare(a, b, CmpOp::Lt) {
std::cmp::Ordering::Less
- } else if version_compare(a, b, ">") {
+ } else if version_compare(a, b, CmpOp::Gt) {
std::cmp::Ordering::Greater
} else {
std::cmp::Ordering::Equal
@@ -564,7 +564,7 @@ impl Problem {
if let Some(c) = constraint
&& c.is_constraint()
- && c.get_operator() == SimpleConstraint::STR_OP_EQ
+ && c.get_operator() == Some(CmpOp::Eq)
&& Preg::is_match3(php_regex!(r"{^dev-.*#.*}"), &c.get_pretty_string(), None)
{
let new_constraint = Preg::replace(
@@ -578,12 +578,12 @@ impl Problem {
MultiConstraint::new(
vec![
AnyConstraint::Simple(SimpleConstraint::new(
- SimpleConstraint::STR_OP_EQ.to_string(),
+ "==".to_string(),
new_constraint.clone(),
None,
)),
AnyConstraint::Simple(SimpleConstraint::new(
- SimpleConstraint::STR_OP_EQ.to_string(),
+ "==".to_string(),
str_replace("#", "+", &new_constraint),
None,
)),
@@ -1102,9 +1102,9 @@ impl Problem {
// uksort($package['versions'], 'version_compare')
let mut keys: Vec<String> = package.versions.keys().cloned().collect();
keys.sort_by(|a, b| {
- if version_compare(a, b, "<") {
+ if version_compare(a, b, CmpOp::Lt) {
std::cmp::Ordering::Less
- } else if version_compare(a, b, ">") {
+ } else if version_compare(a, b, CmpOp::Gt) {
std::cmp::Ordering::Greater
} else {
std::cmp::Ordering::Equal
@@ -1386,7 +1386,7 @@ impl Problem {
pub(crate) fn constraint_to_text(constraint: Option<&AnyConstraint>) -> String {
if let Some(c) = constraint
&& c.is_constraint()
- && c.get_operator() == SimpleConstraint::STR_OP_EQ
+ && c.get_operator() == Some(CmpOp::Eq)
&& !str_starts_with(c.get_version(), "dev-")
{
if !Preg::is_match3(
diff --git a/crates/shirabe/src/downloader/git_downloader.rs b/crates/shirabe/src/downloader/git_downloader.rs
index 5e57de52..275050fd 100644
--- a/crates/shirabe/src/downloader/git_downloader.rs
+++ b/crates/shirabe/src/downloader/git_downloader.rs
@@ -19,7 +19,7 @@ use crate::util::Url;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
- PhpMixed, RuntimeException, array_map, basename, dirname, impl_php_class, implode,
+ CmpOp, PhpMixed, RuntimeException, array_map, basename, dirname, impl_php_class, implode,
in_array_strict, is_dir, php_regex, preg_quote, realpath, rtrim, strlen, strpos, substr, trim,
version_compare,
};
@@ -814,7 +814,7 @@ impl VcsDownloader for GitDownloader {
// --dissociate option is only available since git 2.3.0-rc0
if git_version.is_some()
- && version_compare(git_version.as_deref().unwrap_or(""), "2.3.0-rc0", ">=")
+ && version_compare(git_version.as_deref().unwrap_or(""), "2.3.0-rc0", CmpOp::Ge)
&& Cache::is_usable(&cache_path)
{
self.inner.io.write_error3(
diff --git a/crates/shirabe/src/downloader/svn_downloader.rs b/crates/shirabe/src/downloader/svn_downloader.rs
index 99a5bfe6..6a8bdf0e 100644
--- a/crates/shirabe/src/downloader/svn_downloader.rs
+++ b/crates/shirabe/src/downloader/svn_downloader.rs
@@ -17,7 +17,7 @@ use crate::util::Svn as SvnUtil;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
- PhpMixed, RuntimeException, impl_php_class, is_dir, php_regex, version_compare,
+ CmpOp, PhpMixed, RuntimeException, impl_php_class, is_dir, php_regex, version_compare,
};
#[derive(Debug)]
@@ -223,7 +223,11 @@ impl VcsDownloader for SvnDownloader {
Some(self.inner.process.clone()),
);
let mut flags: Vec<String> = vec![];
- if version_compare(&util.binary_version().unwrap_or_default(), "1.7.0", ">=") {
+ if version_compare(
+ &util.binary_version().unwrap_or_default(),
+ "1.7.0",
+ CmpOp::Ge,
+ ) {
flags.push("--ignore-ancestry".to_string());
}
diff --git a/crates/shirabe/src/downloader/zip_downloader.rs b/crates/shirabe/src/downloader/zip_downloader.rs
index 350ea738..8870194c 100644
--- a/crates/shirabe/src/downloader/zip_downloader.rs
+++ b/crates/shirabe/src/downloader/zip_downloader.rs
@@ -11,10 +11,10 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::symfony::process::ExecutableFinder;
use shirabe_php_shim::{
- DIRECTORY_SEPARATOR, ErrorException, PhpMixed, RuntimeException, UnexpectedValueException,
- ZipArchive, bin2hex, class_exists, file_exists, file_get_contents, filesize, function_exists,
- hash_file, impl_php_class, is_file, json_encode, php_regex, random_int, str_contains,
- str_replace, strlen, substr, version_compare,
+ CmpOp, DIRECTORY_SEPARATOR, ErrorException, PhpMixed, RuntimeException,
+ UnexpectedValueException, ZipArchive, bin2hex, class_exists, file_exists, file_get_contents,
+ filesize, function_exists, hash_file, impl_php_class, is_file, json_encode, php_regex,
+ random_int, str_contains, str_replace, strlen, substr, version_compare,
};
use std::sync::Mutex;
@@ -120,7 +120,7 @@ impl ZipDownloader {
Some(&mut m),
) {
let m1 = m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default();
- if version_compare(&m1, "21.01", "<") {
+ if version_compare(&m1, "21.01", CmpOp::Lt) {
self.inner.io.borrow().write_error(&format!(
" <warning>Unzipping using {} {} may result in incorrect file permissions. Install {} 21.01+ or unzip to ensure you get correct permissions.</warning>",
executable, m1, executable,
diff --git a/crates/shirabe/src/package/loader/validating_array_loader.rs b/crates/shirabe/src/package/loader/validating_array_loader.rs
index a28df595..a050f2d7 100644
--- a/crates/shirabe/src/package/loader/validating_array_loader.rs
+++ b/crates/shirabe/src/package/loader/validating_array_loader.rs
@@ -9,10 +9,10 @@ use crate::repository::PlatformRepository;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
- E_USER_DEPRECATED, PHP_EOL, PhpMixed, array_intersect_key, array_values, filter_var_email,
- get_debug_type, is_array, is_bool, is_int, is_numeric, is_scalar, is_string, json_encode,
- parse_url_all, php_regex, php_to_string, str_replace, strcasecmp, strtolower, strtotime,
- substr, trigger_error, trim, var_export,
+ CmpOp, E_USER_DEPRECATED, PHP_EOL, PhpMixed, array_intersect_key, array_values,
+ filter_var_email, get_debug_type, is_array, is_bool, is_int, is_numeric, is_scalar, is_string,
+ json_encode, parse_url_all, php_regex, php_to_string, str_replace, strcasecmp, strtolower,
+ strtotime, substr, trigger_error, trim, var_export,
};
use shirabe_semver::Intervals;
use shirabe_semver::constraint::AnyConstraint;
@@ -1242,7 +1242,7 @@ impl LoaderInterface for ValidatingArrayLoader {
&& link_type == "require"
&& link_constraint
.as_constraint()
- .is_some_and(|c| ["==", "="].contains(&c.get_operator()))
+ .is_some_and(|c| c.get_operator() == CmpOp::Eq)
&& AnyConstraint::from(SimpleConstraint::new(
">=".to_string(),
"1.0.0.0-dev".to_string(),
diff --git a/crates/shirabe/src/package/version/version_selector.rs b/crates/shirabe/src/package/version/version_selector.rs
index bf5514a5..84f2beef 100644
--- a/crates/shirabe/src/package/version/version_selector.rs
+++ b/crates/shirabe/src/package/version/version_selector.rs
@@ -18,7 +18,7 @@ use crate::repository::RepositorySetInterface;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
- PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION, php_regex, strtolower,
+ CmpOp, PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION, php_regex, strtolower,
version_compare,
};
use shirabe_semver::constraint::AnyConstraint;
@@ -123,9 +123,9 @@ impl VersionSelector {
return std::cmp::Ordering::Less;
}
- if version_compare(&b.get_version(), &a.get_version(), ">") {
+ if version_compare(&b.get_version(), &a.get_version(), CmpOp::Gt) {
std::cmp::Ordering::Greater
- } else if version_compare(&b.get_version(), &a.get_version(), "<") {
+ } else if version_compare(&b.get_version(), &a.get_version(), CmpOp::Lt) {
std::cmp::Ordering::Less
} else {
std::cmp::Ordering::Equal
diff --git a/crates/shirabe/src/platform/version.rs b/crates/shirabe/src/platform/version.rs
index feed1b85..87357062 100644
--- a/crates/shirabe/src/platform/version.rs
+++ b/crates/shirabe/src/platform/version.rs
@@ -2,7 +2,7 @@
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
-use shirabe_php_shim::{php_regex, version_compare};
+use shirabe_php_shim::{CmpOp, php_regex, version_compare};
pub struct Version;
@@ -34,7 +34,7 @@ impl Version {
.cloned()
.unwrap_or_default();
- let patch = if version_compare(&version, "3.0.0", "<") {
+ let patch = if version_compare(&version, "3.0.0", CmpOp::Lt) {
format!(
".{}",
Self::convert_alpha_version_to_int_version(&patch_str)
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
}
diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs
index 59e1d520..b2476e1e 100644
--- a/crates/shirabe/src/repository/composer_repository.rs
+++ b/crates/shirabe/src/repository/composer_repository.rs
@@ -39,7 +39,7 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_metadata_minifier::MetadataMinifier;
use shirabe_php_shim::{
- InvalidArgumentException, LogicException, PHP_EOL, PhpMixed, RuntimeException,
+ CmpOp, InvalidArgumentException, LogicException, PHP_EOL, PhpMixed, RuntimeException,
UnexpectedValueException, extension_loaded, hash, http_build_query, json_decode, parse_url_all,
php_regex, realpath, strtolower, strtr, urlencode, var_export,
};
@@ -2110,7 +2110,7 @@ impl ComposerRepository {
}
if let Some(c) = constraint
- && !CompilingMatcher::r#match(c, SimpleConstraint::OP_EQ, version.clone())
+ && !CompilingMatcher::r#match(c, CmpOp::Eq, version.clone())
{
continue;
}
diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs
index 0ee69926..a6f8d79e 100644
--- a/crates/shirabe/src/util/git.rs
+++ b/crates/shirabe/src/util/git.rs
@@ -16,10 +16,10 @@ use crate::util::{AuthHelper, StoreAuth};
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
- InvalidArgumentException, PHP_EOL, PhpMixed, RuntimeException, array_map, clearstatcache,
- explode, implode, in_array_loose, in_array_strict, is_dir, php_regex, preg_quote, rawurldecode,
- rawurlencode, str_contains, str_ends_with, str_replace_array, strlen, strpos, substr, trim,
- version_compare,
+ CmpOp, InvalidArgumentException, PHP_EOL, PhpMixed, RuntimeException, array_map,
+ clearstatcache, explode, implode, in_array_loose, in_array_strict, is_dir, php_regex,
+ preg_quote, rawurldecode, rawurlencode, str_contains, str_ends_with, str_replace_array, strlen,
+ strpos, substr, trim, version_compare,
};
use std::sync::Mutex;
@@ -982,7 +982,7 @@ impl Git {
) -> String {
let git_version = Self::get_version(process);
if let Some(v) = git_version
- && version_compare(&v, "2.10.0-rc0", ">=")
+ && version_compare(&v, "2.10.0-rc0", CmpOp::Ge)
{
return " --no-show-signature".to_string();
}
@@ -1010,7 +1010,7 @@ impl Git {
let git_version = Self::get_version(process);
git_version
- .map(|v| version_compare(&v, "2.33.0-rc0", ">="))
+ .map(|v| version_compare(&v, "2.33.0-rc0", CmpOp::Ge))
.unwrap_or(false)
}
@@ -1212,7 +1212,7 @@ impl Git {
// PHP: $process ?? new ProcessExecutor()
let git_version = Self::get_version(process);
if let Some(v) = git_version {
- if version_compare(&v, "2.3.0", ">=") {
+ if version_compare(&v, "2.3.0", CmpOp::Ge) {
// added in git 2.3.0, prevents prompting the user for username/password
if Platform::get_env("GIT_TERMINAL_PROMPT").as_deref() != Some("0") {
Platform::put_env("GIT_TERMINAL_PROMPT", "0");
diff --git a/crates/shirabe/src/util/package_sorter.rs b/crates/shirabe/src/util/package_sorter.rs
index 4b76c2fe..5687a339 100644
--- a/crates/shirabe/src/util/package_sorter.rs
+++ b/crates/shirabe/src/util/package_sorter.rs
@@ -3,7 +3,7 @@
use crate::package::Link;
use crate::package::PackageInterfaceHandle;
use indexmap::IndexMap;
-use shirabe_php_shim::{strnatcasecmp, version_compare};
+use shirabe_php_shim::{CmpOp, strnatcasecmp, version_compare};
pub struct PackageSorter;
@@ -21,7 +21,7 @@ impl PackageSorter {
if candidate.is_default_branch() {
return Some(candidate);
}
- if version_compare(&highest.get_version(), &candidate.get_version(), "<") {
+ if version_compare(&highest.get_version(), &candidate.get_version(), CmpOp::Lt) {
highest = candidate;
}
}