CS fixes and one more test for safety, fixes #1855
parent
533512879e
commit
f59f443fce
|
@ -276,7 +276,6 @@ class VersionParser
|
||||||
// however, if a stability suffix is added to the constraint, then a >= match on the current version is
|
// however, if a stability suffix is added to the constraint, then a >= match on the current version is
|
||||||
// used instead
|
// used instead
|
||||||
if (preg_match('{^~(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?'.self::$modifierRegex.'?$}i', $constraint, $matches)) {
|
if (preg_match('{^~(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?'.self::$modifierRegex.'?$}i', $constraint, $matches)) {
|
||||||
|
|
||||||
// Work out which position in the version we are operating at
|
// Work out which position in the version we are operating at
|
||||||
if (isset($matches[4]) && '' !== $matches[4]) {
|
if (isset($matches[4]) && '' !== $matches[4]) {
|
||||||
$position = 4;
|
$position = 4;
|
||||||
|
@ -298,7 +297,9 @@ class VersionParser
|
||||||
$stabilitySuffix .= '-dev';
|
$stabilitySuffix .= '-dev';
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$stabilitySuffix) $stabilitySuffix = "-dev";
|
if (!$stabilitySuffix) {
|
||||||
|
$stabilitySuffix = "-dev";
|
||||||
|
}
|
||||||
$lowVersion = $this->manipulateVersionString($matches, $position, 0) . $stabilitySuffix;
|
$lowVersion = $this->manipulateVersionString($matches, $position, 0) . $stabilitySuffix;
|
||||||
$lowerBound = new VersionConstraint('>=', $lowVersion);
|
$lowerBound = new VersionConstraint('>=', $lowVersion);
|
||||||
|
|
||||||
|
@ -327,14 +328,14 @@ class VersionParser
|
||||||
$lowVersion = $this->manipulateVersionString($matches, $position) . "-dev";
|
$lowVersion = $this->manipulateVersionString($matches, $position) . "-dev";
|
||||||
$highVersion = $this->manipulateVersionString($matches, $position, 1) . "-dev";
|
$highVersion = $this->manipulateVersionString($matches, $position, 1) . "-dev";
|
||||||
|
|
||||||
if($lowVersion === "0.0.0.0-dev") {
|
if ($lowVersion === "0.0.0.0-dev") {
|
||||||
return array(new VersionConstraint('<', $highVersion));
|
return array(new VersionConstraint('<', $highVersion));
|
||||||
} else {
|
|
||||||
return array(
|
|
||||||
new VersionConstraint('>=', $lowVersion),
|
|
||||||
new VersionConstraint('<', $highVersion),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return array(
|
||||||
|
new VersionConstraint('>=', $lowVersion),
|
||||||
|
new VersionConstraint('<', $highVersion),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// match operators constraints
|
// match operators constraints
|
||||||
|
@ -372,20 +373,22 @@ class VersionParser
|
||||||
* @param string $pad The string to pad version parts after $position
|
* @param string $pad The string to pad version parts after $position
|
||||||
* @return string The new version
|
* @return string The new version
|
||||||
*/
|
*/
|
||||||
private function manipulateVersionString($matches, $position, $increment = 0, $pad = '0') {
|
private function manipulateVersionString($matches, $position, $increment = 0, $pad = '0')
|
||||||
for($i = 4; $i>0; $i--) {
|
{
|
||||||
if($i > $position) {
|
for ($i = 4; $i > 0; $i--) {
|
||||||
|
if ($i > $position) {
|
||||||
$matches[$i] = $pad;
|
$matches[$i] = $pad;
|
||||||
|
} else if ($i == $position && $increment) {
|
||||||
} else if(($i == $position) && $increment) {
|
|
||||||
$matches[$i] += $increment;
|
$matches[$i] += $increment;
|
||||||
// If $matches[$i] was 0, carry the decrement
|
// If $matches[$i] was 0, carry the decrement
|
||||||
if($matches[$i] < 0) {
|
if ($matches[$i] < 0) {
|
||||||
$matches[$i] = $pad;
|
$matches[$i] = $pad;
|
||||||
$position--;
|
$position--;
|
||||||
|
|
||||||
// Return null on a carry overflow
|
// Return null on a carry overflow
|
||||||
if($i == 1) return null;
|
if ($i == 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -275,6 +275,7 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
|
||||||
array('~1.2-b2', new VersionConstraint('>=', '1.2.0.0-beta2'), new VersionConstraint('<', '2.0.0.0-dev')),
|
array('~1.2-b2', new VersionConstraint('>=', '1.2.0.0-beta2'), new VersionConstraint('<', '2.0.0.0-dev')),
|
||||||
array('~1.2-BETA2', new VersionConstraint('>=', '1.2.0.0-beta2'), new VersionConstraint('<', '2.0.0.0-dev')),
|
array('~1.2-BETA2', new VersionConstraint('>=', '1.2.0.0-beta2'), new VersionConstraint('<', '2.0.0.0-dev')),
|
||||||
array('~1.2.2-dev', new VersionConstraint('>=', '1.2.2.0-dev'), new VersionConstraint('<', '1.3.0.0-dev')),
|
array('~1.2.2-dev', new VersionConstraint('>=', '1.2.2.0-dev'), new VersionConstraint('<', '1.3.0.0-dev')),
|
||||||
|
array('~1.2.2-stable', new VersionConstraint('>=', '1.2.2.0-stable'), new VersionConstraint('<', '1.3.0.0-dev')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue