Skip to content

Commit 9a08482

Browse files
committed
Support deprecated tags
1 parent c46bef1 commit 9a08482

File tree

3 files changed

+75
-0
lines changed

3 files changed

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

src/Parser/PhpDocParser.php

Lines changed: 10 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,12 @@ 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+
$description = $this->parseOptionalDescription($tokens, true);
169+
return new Ast\PhpDoc\DeprecatedTagValueNode($description);
170+
}
171+
162172

163173
private function parsePropertyTagValue(TokenIterator $tokens): Ast\PhpDoc\PropertyTagValueNode
164174
{

tests/PHPStan/Parser/PhpDocParserTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode;
1616
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
1717
use PHPStan\PhpDocParser\Ast\PhpDoc\ThrowsTagValueNode;
18+
use PHPStan\PhpDocParser\Ast\PhpDoc\DeprecatedTagValueNode;
1819
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
1920
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
2021
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
@@ -43,6 +44,7 @@ protected function setUp()
4344
* @dataProvider provideVarTagsData
4445
* @dataProvider provideReturnTagsData
4546
* @dataProvider provideThrowsTagsData
47+
* @dataProvider provideDeprecatedTagsData
4648
* @dataProvider providePropertyTagsData
4749
* @dataProvider provideMethodTagsData
4850
* @dataProvider provideSingleLinePhpDocData
@@ -967,6 +969,47 @@ public function provideThrowsTagsData(): \Iterator
967969
];
968970
}
969971

972+
public function provideDeprecatedTagsData() :\Iterator
973+
{
974+
yield [
975+
'OK with no description',
976+
'/** @deprecated */',
977+
new PhpDocNode([
978+
new PhpDocTagNode(
979+
'@deprecated',
980+
new DeprecatedTagValueNode()
981+
)
982+
]),
983+
];
984+
985+
yield [
986+
'OK with simple description description',
987+
'/** @deprecated text string */',
988+
new PhpDocNode([
989+
new PhpDocTagNode(
990+
'@deprecated',
991+
new DeprecatedTagValueNode('text string')
992+
)
993+
]),
994+
];
995+
996+
yield [
997+
'OK with long descriptions',
998+
'/** @deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. In
999+
* Drupal 9 there will be no way to set the status and in Drupal 8 this
1000+
* ability has been removed because mb_*() functions are supplied using
1001+
* Symfony\'s polyfill. */',
1002+
new PhpDocNode([
1003+
new PhpDocTagNode(
1004+
'@deprecated',
1005+
new DeprecatedTagValueNode('in Drupal 8.6.0 and will be removed before Drupal 9.0.0. In')
1006+
),
1007+
new PhpDocTextNode('Drupal 9 there will be no way to set the status and in Drupal 8 this'),
1008+
new PhpDocTextNode('ability has been removed because mb_*() functions are supplied using'),
1009+
new PhpDocTextNode('Symfony\'s polyfill.'),
1010+
]),
1011+
];
1012+
}
9701013

9711014
public function provideMethodTagsData(): \Iterator
9721015
{

0 commit comments

Comments
 (0)