Skip to content

Commit 6b92695

Browse files
committed
Refactored throws tag
1 parent 447acda commit 6b92695

File tree

1 file changed

+58
-6
lines changed

1 file changed

+58
-6
lines changed

src/DocBlock/Tags/Throws.php

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,72 @@
11
<?php
22
/**
3-
* phpDocumentor
3+
* This file is part of phpDocumentor.
44
*
5-
* PHP Version 5.3
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
67
*
7-
* @author Mike van Riel <[email protected]>
8-
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
8+
* @copyright 2010-2015 Mike van Riel<[email protected]>
99
* @license http://www.opensource.org/licenses/mit-license.php MIT
1010
* @link http://phpdoc.org
1111
*/
1212

1313
namespace phpDocumentor\Reflection\DocBlock\Tags;
1414

15+
use phpDocumentor\Reflection\DocBlock\Description;
16+
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\TypeResolver;
19+
use phpDocumentor\Reflection\Types\Context;
20+
use Webmozart\Assert\Assert;
21+
1522
/**
16-
* Reflection class for a @throws tag in a Docblock.
23+
* Reflection class for a {@}throws tag in a Docblock.
1724
*/
18-
class Throws extends Return_
25+
final class Throws extends BaseTag
1926
{
27+
protected $name = 'throws';
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+
Context $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+
}
2072
}

0 commit comments

Comments
 (0)