Use the caret operator for all require operations
parent
43c1caad0d
commit
4ce0adb23c
|
@ -21,6 +21,7 @@ use Composer\Package\Dumper\ArrayDumper;
|
||||||
* Selects the best possible version for a package
|
* Selects the best possible version for a package
|
||||||
*
|
*
|
||||||
* @author Ryan Weaver <ryan@knpuniversity.com>
|
* @author Ryan Weaver <ryan@knpuniversity.com>
|
||||||
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||||
*/
|
*/
|
||||||
class VersionSelector
|
class VersionSelector
|
||||||
{
|
{
|
||||||
|
@ -66,11 +67,11 @@ class VersionSelector
|
||||||
* that should be used, for example, in composer.json.
|
* that should be used, for example, in composer.json.
|
||||||
*
|
*
|
||||||
* For example:
|
* For example:
|
||||||
* * 1.2.1 -> ~1.2
|
* * 1.2.1 -> ^1.2
|
||||||
* * 1.2 -> ~1.2
|
* * 1.2 -> ^1.2
|
||||||
* * v3.2.1 -> ~3.2
|
* * v3.2.1 -> ^3.2
|
||||||
* * 2.0-beta.1 -> ~2.0@beta
|
* * 2.0-beta.1 -> ^2.0@beta
|
||||||
* * dev-master -> ~2.1@dev (dev version with alias)
|
* * dev-master -> ^2.1@dev (dev version with alias)
|
||||||
* * dev-master -> dev-master (dev versions are untouched)
|
* * dev-master -> dev-master (dev versions are untouched)
|
||||||
*
|
*
|
||||||
* @param PackageInterface $package
|
* @param PackageInterface $package
|
||||||
|
@ -103,14 +104,12 @@ class VersionSelector
|
||||||
// attempt to transform 2.1.1 to 2.1
|
// attempt to transform 2.1.1 to 2.1
|
||||||
// this allows you to upgrade through minor versions
|
// this allows you to upgrade through minor versions
|
||||||
$semanticVersionParts = explode('.', $version);
|
$semanticVersionParts = explode('.', $version);
|
||||||
$op = '~';
|
|
||||||
|
|
||||||
// check to see if we have a semver-looking version
|
// check to see if we have a semver-looking version
|
||||||
if (count($semanticVersionParts) == 4 && preg_match('{^0\D?}', $semanticVersionParts[3])) {
|
if (count($semanticVersionParts) == 4 && preg_match('{^0\D?}', $semanticVersionParts[3])) {
|
||||||
// remove the last parts (i.e. the patch version number and any extra)
|
// remove the last parts (i.e. the patch version number and any extra)
|
||||||
if ($semanticVersionParts[0] === '0') {
|
if ($semanticVersionParts[0] === '0') {
|
||||||
unset($semanticVersionParts[3]);
|
unset($semanticVersionParts[3]);
|
||||||
$op = '^';
|
|
||||||
} else {
|
} else {
|
||||||
unset($semanticVersionParts[2], $semanticVersionParts[3]);
|
unset($semanticVersionParts[2], $semanticVersionParts[3]);
|
||||||
}
|
}
|
||||||
|
@ -124,8 +123,8 @@ class VersionSelector
|
||||||
$version .= '@'.$stability;
|
$version .= '@'.$stability;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2.1 -> ~2.1
|
// 2.1 -> ^2.1
|
||||||
return $op . $version;
|
return '^' . $version;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getParser()
|
private function getParser()
|
||||||
|
|
|
@ -93,14 +93,14 @@ class VersionSelectorTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
// real version, is dev package, stability, expected recommendation, [branch-alias]
|
// real version, is dev package, stability, expected recommendation, [branch-alias]
|
||||||
array('1.2.1', false, 'stable', '~1.2'),
|
array('1.2.1', false, 'stable', '^1.2'),
|
||||||
array('1.2', false, 'stable', '~1.2'),
|
array('1.2', false, 'stable', '^1.2'),
|
||||||
array('v1.2.1', false, 'stable', '~1.2'),
|
array('v1.2.1', false, 'stable', '^1.2'),
|
||||||
array('3.1.2-pl2', false, 'stable', '~3.1'),
|
array('3.1.2-pl2', false, 'stable', '^3.1'),
|
||||||
array('3.1.2-patch', false, 'stable', '~3.1'),
|
array('3.1.2-patch', false, 'stable', '^3.1'),
|
||||||
array('2.0-beta.1', false, 'beta', '~2.0@beta'),
|
array('2.0-beta.1', false, 'beta', '^2.0@beta'),
|
||||||
array('3.1.2-alpha5', false, 'alpha', '~3.1@alpha'),
|
array('3.1.2-alpha5', false, 'alpha', '^3.1@alpha'),
|
||||||
array('3.0-RC2', false, 'RC', '~3.0@RC'),
|
array('3.0-RC2', false, 'RC', '^3.0@RC'),
|
||||||
array('0.1.0', false, 'stable', '^0.1.0'),
|
array('0.1.0', false, 'stable', '^0.1.0'),
|
||||||
array('0.1.3', false, 'stable', '^0.1.3'),
|
array('0.1.3', false, 'stable', '^0.1.3'),
|
||||||
array('0.0.3', false, 'stable', '^0.0.3'),
|
array('0.0.3', false, 'stable', '^0.0.3'),
|
||||||
|
@ -112,15 +112,15 @@ class VersionSelectorTest extends \PHPUnit_Framework_TestCase
|
||||||
array('dev-master', true, 'dev', 'dev-master'),
|
array('dev-master', true, 'dev', 'dev-master'),
|
||||||
array('3.1.2-dev', true, 'dev', '3.1.2-dev'),
|
array('3.1.2-dev', true, 'dev', '3.1.2-dev'),
|
||||||
// dev packages with alias inherit the alias
|
// dev packages with alias inherit the alias
|
||||||
array('dev-master', true, 'dev', '~2.1@dev', '2.1.x-dev'),
|
array('dev-master', true, 'dev', '^2.1@dev', '2.1.x-dev'),
|
||||||
array('dev-master', true, 'dev', '~2.1@dev', '2.1-dev'),
|
array('dev-master', true, 'dev', '^2.1@dev', '2.1-dev'),
|
||||||
array('dev-master', true, 'dev', '~2.1@dev', '2.1.3.x-dev'),
|
array('dev-master', true, 'dev', '^2.1@dev', '2.1.3.x-dev'),
|
||||||
array('dev-master', true, 'dev', '~2.0@dev', '2.x-dev'),
|
array('dev-master', true, 'dev', '^2.0@dev', '2.x-dev'),
|
||||||
array('dev-master', true, 'dev', '^0.3.0@dev', '0.3.x-dev'),
|
array('dev-master', true, 'dev', '^0.3.0@dev', '0.3.x-dev'),
|
||||||
array('dev-master', true, 'dev', '^0.0.3@dev', '0.0.3.x-dev'),
|
array('dev-master', true, 'dev', '^0.0.3@dev', '0.0.3.x-dev'),
|
||||||
// numeric alias
|
// numeric alias
|
||||||
array('3.x-dev', true, 'dev', '~3.0@dev', '3.0.x-dev'),
|
array('3.x-dev', true, 'dev', '^3.0@dev', '3.0.x-dev'),
|
||||||
array('3.x-dev', true, 'dev', '~3.0@dev', '3.0-dev'),
|
array('3.x-dev', true, 'dev', '^3.0@dev', '3.0-dev'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue