/**
  * @param Version $version
  *
  * @return bool
  */
 public function complies(Version $version)
 {
     if ($version->getMajor()->getValue() != $this->major) {
         return false;
     }
     return $version->getMinor()->getValue() == $this->minor;
 }
Esempio n. 2
0
 /**
  * @dataProvider versionProvider
  *
  * @param string $versionString
  * @param string $expectedMajor
  * @param string $expectedMinor
  * @param string $expectedPatch
  * @param string $expectedLabel
  * @param string $expectedMetadata
  */
 public function testParsesVersionNumbers($versionString, $expectedMajor, $expectedMinor, $expectedPatch, $expectedLabel = '', $expectedMetadata = '')
 {
     $version = new Version($versionString);
     $this->assertSame($expectedMajor, $version->getMajor()->getValue());
     $this->assertSame($expectedMinor, $version->getMinor()->getValue());
     $this->assertSame($expectedPatch, $version->getPatch()->getValue());
     $this->assertSame($expectedLabel, $version->getLabel());
     $this->assertSame($expectedMetadata, $version->getBuildMetadata());
     $this->assertSame($versionString, $version->getVersionString());
 }
 /**
  * @param string $value
  *
  * @return ExactVersionConstraint
  */
 public function parse($value)
 {
     switch ($value[0]) {
         case '~':
             $version = new Version(substr($value, 1));
             return new VersionConstraintGroup($value, [new GreaterThanOrEqualToVersionConstraint($value, $version), new SpecificMajorVersionConstraint($value, $version->getMajor()->getValue())]);
     }
     $version = new Version($value);
     if ($version->getMajor()->isAny()) {
         return new AnyVersionConstraint();
     }
     if ($version->getMinor()->isAny()) {
         return new SpecificMajorVersionConstraint($value, $version->getMajor()->getValue());
     }
     if ($version->getPatch()->isAny()) {
         return new SpecificMajorAndMinorVersionConstraint($value, $version->getMajor()->getValue(), $version->getMinor()->getValue());
     }
     return new ExactVersionConstraint($value);
 }
 /**
  * Compares one version with another.
  *
  * @param Version $left  The left version to compare.
  * @param Version $right The right version to compare.
  *
  * @return integer Returns Comparator::EQUAL_TO if the two versions are
  *                 equal. If the left version is less than the right
  *                 version, Comparator::LESS_THAN is returned. If the left
  *                 version is greater than the right version,
  *                 Comparator::GREATER_THAN is returned.
  */
 public static function compareTo(Version $left, Version $right)
 {
     switch (true) {
         case $left->getMajor() < $right->getMajor():
             return self::LESS_THAN;
         case $left->getMajor() > $right->getMajor():
             return self::GREATER_THAN;
         case $left->getMinor() > $right->getMinor():
             return self::GREATER_THAN;
         case $left->getMinor() < $right->getMinor():
             return self::LESS_THAN;
         case $left->getPatch() > $right->getPatch():
             return self::GREATER_THAN;
         case $left->getPatch() < $right->getPatch():
             return self::LESS_THAN;
             // @codeCoverageIgnoreStart
     }
     // @codeCoverageIgnoreEnd
     return self::compareIdentifiers($left->getPreRelease(), $right->getPreRelease());
 }
Esempio n. 5
0
 /**
  * @param Version $version
  *
  * @return bool
  */
 public function isGreaterThan(Version $version)
 {
     if ($version->getMajor()->getValue() > $this->getMajor()->getValue()) {
         return false;
     }
     if ($version->getMajor()->getValue() < $this->getMajor()->getValue()) {
         return true;
     }
     if ($version->getMinor()->getValue() > $this->getMinor()->getValue()) {
         return false;
     }
     if ($version->getMinor()->getValue() < $this->getMinor()->getValue()) {
         return true;
     }
     if ($version->getPatch()->getValue() >= $this->getPatch()->getValue()) {
         return false;
     }
     if ($version->getPatch()->getValue() < $this->getPatch()->getValue()) {
         return true;
     }
     return false;
 }
Esempio n. 6
0
 /**
  * Returns the string representation of a Version instance.
  *
  * @param Version $version A version.
  *
  * @return string The string representation.
  */
 public static function toString(Version $version)
 {
     return sprintf('%d.%d.%d%s%s', $version->getMajor(), $version->getMinor(), $version->getPatch(), $version->getPreRelease() ? '-' . join('.', $version->getPreRelease()) : '', $version->getBuild() ? '+' . join('.', $version->getBuild()) : '');
 }