1
0
Fork 0

Move VersionParser::formatVersion() to BasePackage::getFullPrettyVersion()

Working towards #3545.

formatVersion() does not belong in VersionParser since it depends upon a
Package object, and is creating a more complete pretty formatted
version, not parsing anything.

The new getFullPrettyVersion() method can be seen as an extension to
getPrettyVersion(), and is located in BasePackage as a result.

Callers to VersionParser::formatVersion() were not updated in this
commit to demonstrate that no functionality was changed in this
refactor. They will be updated in a follow up commit.
pull/4086/head
Kunal Mehta 2015-05-30 23:24:20 -07:00
parent 8775c94895
commit 99dab8aebd
4 changed files with 29 additions and 11 deletions

View File

@ -206,6 +206,23 @@ abstract class BasePackage implements PackageInterface
return $this->getPrettyName().' '.$this->getPrettyVersion();
}
/**
* {@inheritDoc}
*/
public function getFullPrettyVersion($truncate = true)
{
if (!$this->isDev() || !in_array($this->getSourceType(), array('hg', 'git'))) {
return $this->getPrettyVersion();
}
// if source reference is a sha1 hash -- truncate
if ($truncate && strlen($this->getSourceReference()) === 40) {
return $this->getPrettyVersion() . ' ' . substr($this->getSourceReference(), 0, 7);
}
return $this->getPrettyVersion() . ' ' . $this->getSourceReference();
}
public function __clone()
{
$this->repository = null;

View File

@ -192,6 +192,16 @@ interface PackageInterface
*/
public function getPrettyVersion();
/**
* Returns the pretty version string plus a git or hg commit hash of this package
*
* @see getPrettyVersion
*
* @param bool $truncate If the source reference is a sha1 hash, truncate it
* @return string version
*/
public function getFullPrettyVersion($truncate = true);
/**
* Returns the release date of the package
*

View File

@ -71,16 +71,7 @@ class VersionParser
public static function formatVersion(PackageInterface $package, $truncate = true)
{
if (!$package->isDev() || !in_array($package->getSourceType(), array('hg', 'git'))) {
return $package->getPrettyVersion();
}
// if source reference is a sha1 hash -- truncate
if ($truncate && strlen($package->getSourceReference()) === 40) {
return $package->getPrettyVersion() . ' ' . substr($package->getSourceReference(), 0, 7);
}
return $package->getPrettyVersion() . ' ' . $package->getSourceReference();
return $package->getFullPrettyVersion($truncate);
}
/**

View File

@ -56,7 +56,7 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
$self = $this;
$createPackage = function ($arr) use ($self) {
$package = $self->getMock('\Composer\Package\PackageInterface');
$package = $self->getMockForAbstractClass('\Composer\Package\BasePackage', array(), '', false);
$package->expects($self->once())->method('isDev')->will($self->returnValue(true));
$package->expects($self->once())->method('getSourceType')->will($self->returnValue('git'));
$package->expects($self->once())->method('getPrettyVersion')->will($self->returnValue('PrettyVersion'));