1<?php
2/**
3 * This file is part of phpDocumentor.
4 *
5 * For the full copyright and license information, please view the LICENSE
6 * file that was distributed with this source code.
7 *
8 * @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
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\Type;
18use phpDocumentor\Reflection\TypeResolver;
19use phpDocumentor\Reflection\Types\Context as TypeContext;
20use Webmozart\Assert\Assert;
21
22/**
23 * Reflection class for a {@}return tag in a Docblock.
24 */
25final class Return_ extends BaseTag implements Factory\StaticMethod
26{
27    protected $name = 'return';
28
29    /** @var Type */
30    private $type;
31
32    public function __construct(Type $type, Description $description = null)
33    {
34        $this->type = $type;
35        $this->description = $description;
36    }
37
38    /**
39     * {@inheritdoc}
40     */
41    public static function create(
42        $body,
43        TypeResolver $typeResolver = null,
44        DescriptionFactory $descriptionFactory = null,
45        TypeContext $context = null
46    ) {
47        Assert::string($body);
48        Assert::allNotNull([$typeResolver, $descriptionFactory]);
49
50        $parts = preg_split('/\s+/Su', $body, 2);
51
52        $type = $typeResolver->resolve(isset($parts[0]) ? $parts[0] : '', $context);
53        $description = $descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context);
54
55        return new static($type, $description);
56    }
57
58    /**
59     * Returns the type section of the variable.
60     *
61     * @return Type
62     */
63    public function getType()
64    {
65        return $this->type;
66    }
67
68    public function __toString()
69    {
70        return $this->type . ' ' . $this->description;
71    }
72}
73