Skip to content

Commit fa28520

Browse files
committed
Support deprecated tags
1 parent c46bef1 commit fa28520

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
4+
5+
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
6+
7+
class DeprecatedTagValueNode implements PhpDocTagValueNode
8+
{
9+
10+
/** @var TypeNode */
11+
public $type;
12+
13+
/** @var string (may be empty) */
14+
public $description;
15+
16+
public function __construct(TypeNode $type, string $description)
17+
{
18+
$this->type = $type;
19+
$this->description = $description;
20+
}
21+
22+
23+
public function __toString(): string
24+
{
25+
return trim("{$this->type} {$this->description}");
26+
}
27+
28+
}

src/Parser/PhpDocParser.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ public function parseTagValue(TokenIterator $tokens, string $tag): Ast\PhpDoc\Ph
9999
$tagValue = $this->parseThrowsTagValue($tokens);
100100
break;
101101

102+
case '@deprecated':
103+
$tagValue = $this->parseDeprecatedTagValue($tokens);
104+
break;
105+
102106
case '@property':
103107
case '@property-read':
104108
case '@property-write':
@@ -159,6 +163,13 @@ private function parseThrowsTagValue(TokenIterator $tokens): Ast\PhpDoc\ThrowsTa
159163
return new Ast\PhpDoc\ThrowsTagValueNode($type, $description);
160164
}
161165

166+
private function parseDeprecatedTagValue(TokenIterator $tokens): Ast\PhpDoc\DeprecatedTagValueNode
167+
{
168+
$type = $this->typeParser->parse($tokens);
169+
$description = $this->parseOptionalDescription($tokens, true);
170+
return new Ast\PhpDoc\DeprecatedTagValueNode($type, $description);
171+
}
172+
162173

163174
private function parsePropertyTagValue(TokenIterator $tokens): Ast\PhpDoc\PropertyTagValueNode
164175
{

0 commit comments

Comments
 (0)