add support for @throws tag value parsing

This commit is contained in:
Jan Tvrdik 2017-12-16 15:34:23 +01:00
parent 72864aad33
commit f8a1d21be1
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,28 @@
<?php declare(strict_types = 1);
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
class ThrowsTagValueNode implements PhpDocTagValueNode
{
/** @var TypeNode */
public $type;
/** @var string (may be empty) */
public $description;
public function __construct(TypeNode $type, string $description)
{
$this->type = $type;
$this->description = $description;
}
public function __toString(): string
{
return trim("{$this->type} {$this->description}");
}
}

View File

@ -96,6 +96,10 @@ class PhpDocParser
$tagValue = $this->parseReturnTagValue($tokens);
break;
case '@throws':
$tagValue = $this->parseThrowsTagValue($tokens);
break;
case '@property':
case '@property-read':
case '@property-write':
@ -149,6 +153,14 @@ class PhpDocParser
}
private function parseThrowsTagValue(TokenIterator $tokens): Ast\PhpDoc\ThrowsTagValueNode
{
$type = $this->typeParser->parse($tokens);
$description = $this->parseOptionalDescription($tokens, true);
return new Ast\PhpDoc\ThrowsTagValueNode($type, $description);
}
private function parsePropertyTagValue(TokenIterator $tokens): Ast\PhpDoc\PropertyTagValueNode
{
$type = $this->typeParser->parse($tokens);