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
parent
8775c94895
commit
99dab8aebd
|
@ -206,6 +206,23 @@ abstract class BasePackage implements PackageInterface
|
||||||
return $this->getPrettyName().' '.$this->getPrettyVersion();
|
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()
|
public function __clone()
|
||||||
{
|
{
|
||||||
$this->repository = null;
|
$this->repository = null;
|
||||||
|
|
|
@ -192,6 +192,16 @@ interface PackageInterface
|
||||||
*/
|
*/
|
||||||
public function getPrettyVersion();
|
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
|
* Returns the release date of the package
|
||||||
*
|
*
|
||||||
|
|
|
@ -71,16 +71,7 @@ class VersionParser
|
||||||
|
|
||||||
public static function formatVersion(PackageInterface $package, $truncate = true)
|
public static function formatVersion(PackageInterface $package, $truncate = true)
|
||||||
{
|
{
|
||||||
if (!$package->isDev() || !in_array($package->getSourceType(), array('hg', 'git'))) {
|
return $package->getFullPrettyVersion($truncate);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -56,7 +56,7 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
$self = $this;
|
$self = $this;
|
||||||
$createPackage = function ($arr) use ($self) {
|
$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('isDev')->will($self->returnValue(true));
|
||||||
$package->expects($self->once())->method('getSourceType')->will($self->returnValue('git'));
|
$package->expects($self->once())->method('getSourceType')->will($self->returnValue('git'));
|
||||||
$package->expects($self->once())->method('getPrettyVersion')->will($self->returnValue('PrettyVersion'));
|
$package->expects($self->once())->method('getPrettyVersion')->will($self->returnValue('PrettyVersion'));
|
||||||
|
|
Loading…
Reference in New Issue