Skip to content

Commit

Permalink
Fix feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed May 19, 2020
1 parent aaf43b3 commit 3d72ad3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
15 changes: 9 additions & 6 deletions src/Intervals.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ class Intervals
private static $opSortOrder = array(
'>=' => -3,
'<' => -2,
'==' => -1,
'!=' => 1,
'>' => 2,
'<=' => 3,
);
Expand Down Expand Up @@ -166,6 +164,11 @@ private static function generateIntervals(ConstraintInterface $constraint, $stop
}

foreach ($dev as $i => $c) {
if ($c === self::anyDev()) {
$dev = array($c);
break;
}

if ($c->getOperator() === '!=') {
foreach ($dev as $j => $c2) {
if ($i === $j) {
Expand All @@ -191,7 +194,7 @@ private static function generateIntervals(ConstraintInterface $constraint, $stop
}
}
} else {
$blacklist = array();
$disallowlist = array();
foreach ($devGroups as $i => $group) {
foreach ($group as $j => $c) {
// all != constraints are kept
Expand All @@ -213,8 +216,8 @@ private static function generateIntervals(ConstraintInterface $constraint, $stop

// != x && == x cancel each other, make sure none of these appears in the output
if ($c->getOperator() === '==' && $c2->getOperator() === '!=' && $c->getVersion() === $c2->getVersion()) {
$blacklist[] = (string) $c;
$blacklist[] = (string) $c2;
$disallowlist[(string) $c] = true;
$disallowlist[(string) $c2] = true;
}
}
}
Expand All @@ -225,7 +228,7 @@ private static function generateIntervals(ConstraintInterface $constraint, $stop
}
}
}
foreach ($blacklist as $c) {
foreach ($disallowlist as $c => $dummy) {
unset($dev[$c]);
}
}
Expand Down
18 changes: 8 additions & 10 deletions tests/IntervalsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,7 @@ public function intervalsProvider()
'!= 1.4.5, ^1.0, != 1.2.3, != 2.3, != dev-foo, != dev-master'
),
'conjunctive constraints with dev exact versions suppresses the number scope matches' => array(
array('intervals' => array(
), 'devConstraints' => array()),
self::INTERVAL_NONE,
'!= 1.4.5, ^1.0, != 1.2.3, != 2.3, == dev-foo, == dev-foo'
),
'conjunctive constraints with dev exact versions suppresses the number scope matches, but keeps dev- match if number constraints allowed dev*' => array(
Expand All @@ -380,15 +379,10 @@ public function intervalsProvider()
'end' => '< '.PHP_INT_MAX.'.0.0.0',
),
), 'devConstraints' => array('!= dev-foo', '< dev-foo')),
'!= 1.4.5 || ^1.0 || != dev-foo || < dev-foo'
'^1.0 || != dev-foo || < dev-foo'
),
'disjunctive constraints with exclusions, if matches * in number scope and dev scope, then no dev constraints returned' => array(
array('intervals' => array(
array(
'start' => '>= 0.0.0.0-dev',
'end' => '< '.PHP_INT_MAX.'.0.0.0',
),
), 'devConstraints' => array()),
'disjunctive constraints with exclusions, if matches * in number scope and dev scope, then * is returned' => array(
self::INTERVAL_ANY,
'!= 1.4.5 || ^1.0 || != dev-foo || != dev-master || == dev-master'
),
'disjunctive constraints with exclusions, if dev constraints match *, then * is returned for everything' => array(
Expand Down Expand Up @@ -469,6 +463,10 @@ public function intervalsProvider()
self::INTERVAL_ANY_NODEV,
new MultiConstraint(array(new Constraint('>=', '0.0.0.0-dev'), new Constraint('<', PHP_INT_MAX.'.0.0.0'))),
),
'disjunctive constraints with * and dev exclusion should not return the dev exclusion' => array(
self::INTERVAL_ANY,
'!= dev-foo || *'
),
);
}
}

0 comments on commit 3d72ad3

Please sign in to comment.