function Intervals::generateSingleConstraintIntervals
@phpstan-return array{'numeric': Interval[], 'branches': array{'names': string[], 'exclude': bool}}
1 call to Intervals::generateSingleConstraintIntervals()
- Intervals::generateIntervals in vendor/
composer/ semver/ src/ Intervals.php - @phpstan-return array{'numeric': Interval[], 'branches': array{'names': string[], 'exclude': bool}}
File
-
vendor/
composer/ semver/ src/ Intervals.php, line 436
Class
- Intervals
- Helper class generating intervals from constraints
Namespace
Composer\SemverCode
private static function generateSingleConstraintIntervals(Constraint $constraint) {
$op = $constraint->getOperator();
// handle branch constraints first
if (strpos($constraint->getVersion(), 'dev-') === 0) {
$intervals = array();
$branches = array(
'names' => array(),
'exclude' => false,
);
// != dev-foo means any numeric version may match, we treat >/< like != they are not really defined for branches
if ($op === '!=') {
$intervals[] = new Interval(Interval::fromZero(), Interval::untilPositiveInfinity());
$branches = array(
'names' => array(
$constraint->getVersion(),
),
'exclude' => true,
);
}
elseif ($op === '==') {
$branches['names'][] = $constraint->getVersion();
}
return array(
'numeric' => $intervals,
'branches' => $branches,
);
}
if ($op[0] === '>') {
// > & >=
return array(
'numeric' => array(
new Interval($constraint, Interval::untilPositiveInfinity()),
),
'branches' => Interval::noDev(),
);
}
if ($op[0] === '<') {
// < & <=
return array(
'numeric' => array(
new Interval(Interval::fromZero(), $constraint),
),
'branches' => Interval::noDev(),
);
}
if ($op === '!=') {
// convert !=x to intervals of 0 - <x && >x - +inf + dev*
return array(
'numeric' => array(
new Interval(Interval::fromZero(), new Constraint('<', $constraint->getVersion())),
new Interval(new Constraint('>', $constraint->getVersion()), Interval::untilPositiveInfinity()),
),
'branches' => Interval::anyDev(),
);
}
// convert ==x to an interval of >=x - <=x
return array(
'numeric' => array(
new Interval(new Constraint('>=', $constraint->getVersion()), new Constraint('<=', $constraint->getVersion())),
),
'branches' => Interval::noDev(),
);
}