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