/** * 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 && null !== $update->getVersion()->getPreRelease()) { continue; } $test = $current ? $current->getVersion() : $version; if (false === $update->isNewer($test)) { continue; } $current = $update; } return $current; }
/** * @depends testDefaults */ public function testSetMajor() { $version = new Version(); $version->setMajor(1); $this->assertSame(1, $version->getMajor()); }
/** * Compares one version to another. * * @param Version $version Another version. * * @return -1 If this one is greater, 0 if equal, or 1 if $version is greater. * * @api */ public function compareTo($version) { $major = $version->getMajor(); $minor = $version->getMinor(); $patch = $version->getPatch(); $pre = $version->getPreRelease(); $build = $version->getBuild(); switch (true) { case $this->major < $major: return 1; case $this->major > $major: return -1; case $this->minor > $minor: return -1; case $this->minor < $minor: return 1; case $this->patch > $patch: return -1; case $this->patch < $patch: return 1; // @codeCoverageIgnoreStart } // @codeCoverageIgnoreEnd if ($pre || $this->pre) { if (empty($this->pre) && $pre) { return -1; } if ($this->pre && empty($pre)) { return 1; } if (0 !== ($weight = $this->precedence($this->pre, $pre))) { return $weight; } } if ($build || $this->build) { if (null === $this->build && $build) { return 1; } if ($this->build && null === $build) { return -1; } return $this->precedence($this->build, $build); } return 0; }