1<?php
2/**
3 * phpDocumentor
4 *
5 * PHP Version 5.3
6 *
7 * @author    Ben Selby <benmatselby@gmail.com>
8 * @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
9 * @license   http://www.opensource.org/licenses/mit-license.php MIT
10 * @link      http://phpdoc.org
11 */
12
13namespace phpDocumentor\Reflection\DocBlock\Tags;
14
15use phpDocumentor\Reflection\DocBlock\Description;
16use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
17use phpDocumentor\Reflection\Types\Context as TypeContext;
18use Webmozart\Assert\Assert;
19
20/**
21 * Reflection class for a @link tag in a Docblock.
22 */
23final class Link extends BaseTag implements Factory\StaticMethod
24{
25    protected $name = 'link';
26
27    /** @var string */
28    private $link = '';
29
30    /**
31     * Initializes a link to a URL.
32     *
33     * @param string      $link
34     * @param Description $description
35     */
36    public function __construct($link, Description $description = null)
37    {
38        Assert::string($link);
39
40        $this->link = $link;
41        $this->description = $description;
42    }
43
44    /**
45     * {@inheritdoc}
46     */
47    public static function create($body, DescriptionFactory $descriptionFactory = null, TypeContext $context = null)
48    {
49        Assert::string($body);
50        Assert::notNull($descriptionFactory);
51
52        $parts = preg_split('/\s+/Su', $body, 2);
53        $description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null;
54
55        return new static($parts[0], $description);
56    }
57
58    /**
59    * Gets the link
60    *
61    * @return string
62    */
63    public function getLink()
64    {
65        return $this->link;
66    }
67
68    /**
69     * Returns a string representation for this tag.
70     *
71     * @return string
72     */
73    public function __toString()
74    {
75        return $this->link . ($this->description ? ' ' . $this->description->render() : '');
76    }
77}
78