From e16caa9bd761ae6746a39306ef8792b08a9df4ed Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 27 Apr 2013 14:32:22 +0200 Subject: [PATCH] Add EmptyConstraint --- .../LinkConstraint/EmptyConstraint.php | 47 +++++++++++++++++++ .../Package/Version/VersionParser.php | 3 +- .../Package/Version/VersionParserTest.php | 9 ++-- 3 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 src/Composer/Package/LinkConstraint/EmptyConstraint.php diff --git a/src/Composer/Package/LinkConstraint/EmptyConstraint.php b/src/Composer/Package/LinkConstraint/EmptyConstraint.php new file mode 100644 index 000000000..ca1c75ff5 --- /dev/null +++ b/src/Composer/Package/LinkConstraint/EmptyConstraint.php @@ -0,0 +1,47 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Package\LinkConstraint; + +/** + * Defines an absence of constraints + * + * @author Jordi Boggiano + */ +class EmptyConstraint implements LinkConstraintInterface +{ + protected $prettyString; + + public function matches(LinkConstraintInterface $provider) + { + return true; + } + + public function setPrettyString($prettyString) + { + $this->prettyString = $prettyString; + } + + public function getPrettyString() + { + if ($this->prettyString) { + return $this->prettyString; + } + + return $this->__toString(); + } + + public function __toString() + { + return '[]'; + } +} diff --git a/src/Composer/Package/Version/VersionParser.php b/src/Composer/Package/Version/VersionParser.php index 2440b6b6a..b6685a6c0 100644 --- a/src/Composer/Package/Version/VersionParser.php +++ b/src/Composer/Package/Version/VersionParser.php @@ -15,6 +15,7 @@ namespace Composer\Package\Version; use Composer\Package\BasePackage; use Composer\Package\PackageInterface; use Composer\Package\Link; +use Composer\Package\LinkConstraint\EmptyConstraint; use Composer\Package\LinkConstraint\MultiConstraint; use Composer\Package\LinkConstraint\VersionConstraint; @@ -253,7 +254,7 @@ class VersionParser } if (preg_match('{^[x*](\.[x*])*$}i', $constraint)) { - return array(); + return array(new EmptyConstraint); } if (preg_match('{^~(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?'.self::$modifierRegex.'?$}i', $constraint, $matches)) { diff --git a/tests/Composer/Test/Package/Version/VersionParserTest.php b/tests/Composer/Test/Package/Version/VersionParserTest.php index ff1fa6871..c31aedca7 100644 --- a/tests/Composer/Test/Package/Version/VersionParserTest.php +++ b/tests/Composer/Test/Package/Version/VersionParserTest.php @@ -15,6 +15,7 @@ namespace Composer\Test\Package\Version; use Composer\Package\Version\VersionParser; use Composer\Package\LinkConstraint\MultiConstraint; use Composer\Package\LinkConstraint\VersionConstraint; +use Composer\Package\LinkConstraint\EmptyConstraint; use Composer\Package\PackageInterface; class VersionParserTest extends \PHPUnit_Framework_TestCase @@ -192,10 +193,10 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase public function simpleConstraints() { return array( - 'match any' => array('*', new MultiConstraint(array())), - 'match any/2' => array('*.*', new MultiConstraint(array())), - 'match any/3' => array('*.x.*', new MultiConstraint(array())), - 'match any/4' => array('x.x.x.*', new MultiConstraint(array())), + 'match any' => array('*', new EmptyConstraint()), + 'match any/2' => array('*.*', new EmptyConstraint()), + 'match any/3' => array('*.x.*', new EmptyConstraint()), + 'match any/4' => array('x.x.x.*', new EmptyConstraint()), 'not equal' => array('<>1.0.0', new VersionConstraint('<>', '1.0.0.0')), 'not equal/2' => array('!=1.0.0', new VersionConstraint('!=', '1.0.0.0')), 'greater than' => array('>1.0.0', new VersionConstraint('>', '1.0.0.0')),