/**
  * Finds the most recent update and returns it.
  *
  * @param Version $version The current version.
  * @param boolean $major   Lock to major version?
  * @param boolean $pre     Allow pre-releases?
  *
  * @return Update The update.
  */
 public function findRecent(Version $version, $major = false, $pre = false)
 {
     /** @var $current Update */
     $current = null;
     $major = $major ? $version->getMajor() : null;
     foreach ($this->updates as $update) {
         if ($major && $major !== $update->getVersion()->getMajor()) {
             continue;
         }
         if (false === $pre && !$update->getVersion()->isStable()) {
             continue;
         }
         $test = $current ? $current->getVersion() : $version;
         if (false === $update->isNewer($test)) {
             continue;
         }
         $current = $update;
     }
     return $current;
 }
 /**
  * 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()) : '');
 }
Example #3
0
 /**
  * Imports an existing Version instance.
  *
  * @param Version $version A Version instance.
  *
  * @return Builder The Version builder.
  */
 public function importVersion($version)
 {
     return $this->setMajor($version->getMajor())->setMinor($version->getMinor())->setPatch($version->getPatch())->setPreRelease($version->getPreRelease())->setBuild($version->getBuild());
 }
 public function testIsStable()
 {
     $this->assertFalse($this->version->isStable());
     $version = new Version();
     $this->assertFalse($version->isStable());
     $version = new Version(1);
     $this->assertTrue($version->isStable());
 }