1
0
Fork 0

Added phpdocs + change to yoda comparison

pull/4083/head
nevvermind 2015-05-30 01:38:14 +01:00
parent e64470c987
commit 8e79a3766d
2 changed files with 47 additions and 8 deletions

View File

@ -21,10 +21,29 @@ use Composer\Package\LinkConstraint\LinkConstraintInterface;
*/ */
class Link class Link
{ {
/**
* @var string
*/
protected $source; protected $source;
/**
* @var string
*/
protected $target; protected $target;
/**
* @var LinkConstraintInterface|null
*/
protected $constraint; protected $constraint;
/**
* @var string
*/
protected $description; protected $description;
/**
* @var string|null
*/
protected $prettyConstraint; protected $prettyConstraint;
/** /**
@ -32,9 +51,9 @@ class Link
* *
* @param string $source * @param string $source
* @param string $target * @param string $target
* @param LinkConstraintInterface $constraint Constraint applying to the target of this link * @param LinkConstraintInterface|null $constraint Constraint applying to the target of this link
* @param string $description Used to create a descriptive string representation * @param string $description Used to create a descriptive string representation
* @param string $prettyConstraint * @param string|null $prettyConstraint
*/ */
public function __construct($source, $target, LinkConstraintInterface $constraint = null, $description = 'relates to', $prettyConstraint = null) public function __construct($source, $target, LinkConstraintInterface $constraint = null, $description = 'relates to', $prettyConstraint = null)
{ {
@ -45,21 +64,34 @@ class Link
$this->prettyConstraint = $prettyConstraint; $this->prettyConstraint = $prettyConstraint;
} }
/**
* @return string
*/
public function getSource() public function getSource()
{ {
return $this->source; return $this->source;
} }
/**
* @return string
*/
public function getTarget() public function getTarget()
{ {
return $this->target; return $this->target;
} }
/**
* @return LinkConstraintInterface|null
*/
public function getConstraint() public function getConstraint()
{ {
return $this->constraint; return $this->constraint;
} }
/**
* @throws \UnexpectedValueException If no pretty constraint was provided
* @return string
*/
public function getPrettyConstraint() public function getPrettyConstraint()
{ {
if (null === $this->prettyConstraint) { if (null === $this->prettyConstraint) {
@ -69,11 +101,18 @@ class Link
return $this->prettyConstraint; return $this->prettyConstraint;
} }
/**
* @return string
*/
public function __toString() public function __toString()
{ {
return $this->source.' '.$this->description.' '.$this->target.' ('.$this->constraint.')'; return $this->source.' '.$this->description.' '.$this->target.' ('.$this->constraint.')';
} }
/**
* @param PackageInterface $sourcePackage
* @return string
*/
public function getPrettyString(PackageInterface $sourcePackage) public function getPrettyString(PackageInterface $sourcePackage)
{ {
return $sourcePackage->getPrettyString().' '.$this->description.' '.$this->target.' '.$this->constraint->getPrettyString().''; return $sourcePackage->getPrettyString().' '.$this->description.' '.$this->target.' '.$this->constraint->getPrettyString().'';

View File

@ -113,14 +113,14 @@ class PluginManager
*/ */
public function loadRepository(RepositoryInterface $repo) public function loadRepository(RepositoryInterface $repo)
{ {
foreach ($repo->getPackages() as $package) { foreach ($repo->getPackages() as $package) { /** @var PackageInterface $package */
if ($package instanceof AliasPackage) { if ($package instanceof AliasPackage) {
continue; continue;
} }
if ('composer-plugin' === $package->getType()) { if ('composer-plugin' === $package->getType()) {
$requiresComposer = null; $requiresComposer = null;
foreach ($package->getRequires() as $link) { foreach ($package->getRequires() as $link) { /** @var Link $link */
if ($link->getTarget() == 'composer-plugin-api') { if ('composer-plugin-api' === $link->getTarget()) {
$requiresComposer = $link->getConstraint(); $requiresComposer = $link->getConstraint();
} }
} }