aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/filter
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-23 23:14:52 +0900
committernsfisis <nsfisis@gmail.com>2026-05-23 23:15:14 +0900
commitdbdecaf5a1c54a876b7ee0153d58dd39b1080f97 (patch)
treef13f2ced03c803dcbc42a5672458b3cb19ff0f30 /crates/shirabe/src/filter
parentf5b987a00712211b7ce56300851182bda904e97b (diff)
downloadphp-shirabe-dbdecaf5a1c54a876b7ee0153d58dd39b1080f97.tar.gz
php-shirabe-dbdecaf5a1c54a876b7ee0153d58dd39b1080f97.tar.zst
php-shirabe-dbdecaf5a1c54a876b7ee0153d58dd39b1080f97.zip
refactor(semver): change ConstraintInterface to a closed enum
Replace the dyn ConstraintInterface trait objects with an AnyConstraint enum closing over its four implementors (Simple, Multi, MatchAll, MatchNone), mirroring the earlier Rule enum conversion. Rename constraint.rs to simple_constraint.rs to match the renamed Constraint type. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/filter')
-rw-r--r--crates/shirabe/src/filter/platform_requirement_filter/ignore_list_platform_requirement_filter.rs24
1 files changed, 15 insertions, 9 deletions
diff --git a/crates/shirabe/src/filter/platform_requirement_filter/ignore_list_platform_requirement_filter.rs b/crates/shirabe/src/filter/platform_requirement_filter/ignore_list_platform_requirement_filter.rs
index f6b8091..d69773c 100644
--- a/crates/shirabe/src/filter/platform_requirement_filter/ignore_list_platform_requirement_filter.rs
+++ b/crates/shirabe/src/filter/platform_requirement_filter/ignore_list_platform_requirement_filter.rs
@@ -1,10 +1,10 @@
//! ref: composer/src/Composer/Filter/PlatformRequirementFilter/IgnoreListPlatformRequirementFilter.php
use shirabe_external_packages::composer::pcre::Preg;
-use shirabe_semver::constraint::Constraint;
-use shirabe_semver::constraint::ConstraintInterface;
+use shirabe_semver::constraint::AnyConstraint;
use shirabe_semver::constraint::MatchAllConstraint;
use shirabe_semver::constraint::MultiConstraint;
+use shirabe_semver::constraint::SimpleConstraint;
use shirabe_semver::interval::Interval;
use shirabe_semver::intervals::Intervals;
@@ -41,9 +41,9 @@ impl IgnoreListPlatformRequirementFilter {
pub fn filter_constraint(
&self,
req: &str,
- constraint: Box<dyn ConstraintInterface>,
+ constraint: AnyConstraint,
allow_upper_bound_override: bool,
- ) -> anyhow::Result<Box<dyn ConstraintInterface>> {
+ ) -> anyhow::Result<AnyConstraint> {
if !PlatformRepository::is_platform_package(req) {
return Ok(constraint);
}
@@ -53,20 +53,26 @@ impl IgnoreListPlatformRequirementFilter {
}
if Preg::is_match(&self.ignore_regex, req)? {
- return Ok(Box::new(MatchAllConstraint::new()));
+ return Ok(MatchAllConstraint::new(None).into());
}
- let intervals = Intervals::get(&*constraint)?;
+ let intervals = Intervals::get(&constraint)?;
let last = intervals.numeric.last();
if let Some(last) = last {
if last.get_end().to_string() != Interval::until_positive_infinity().to_string() {
- let constraint = Box::new(MultiConstraint::new(
+ let constraint = MultiConstraint::new(
vec![
constraint,
- Box::new(Constraint::new(">=", last.get_end().get_version())),
+ AnyConstraint::Simple(SimpleConstraint::new(
+ ">=".to_string(),
+ last.get_end().get_version().to_string(),
+ None,
+ )),
],
false,
- ));
+ None,
+ )
+ .into();
return Ok(constraint);
}
}