Skip to content

Commit 3acbe24

Browse files
committed
Add Implements tags
1 parent f387e8f commit 3acbe24

File tree

3 files changed

+47
-20
lines changed

3 files changed

+47
-20
lines changed

src/DocBlock/Tags/Factory/ImplementsFactory.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
66

77
use Webmozart\Assert\Assert;
8+
use phpDocumentor\Reflection\DocBlock\Tag;
89
use phpDocumentor\Reflection\TypeResolver;
910
use phpDocumentor\Reflection\Types\Context;
10-
use phpDocumentor\Reflection\DocBlock\Tag;
11+
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
1112
use phpDocumentor\Reflection\DocBlock\Tags\Implements_;
1213
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
13-
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
1414
use PHPStan\PhpDocParser\Ast\PhpDoc\ImplementsTagValueNode;
15+
use phpDocumentor\Reflection\DocBlock\Tags\TemplateImplements;
1516

1617
/**
1718
* @internal This class is not part of the BC promise of this library.
@@ -32,14 +33,21 @@ public function create(PhpDocTagNode $node, Context $context): Tag
3233
$tagValue = $node->value;
3334
Assert::isInstanceOf($tagValue, ImplementsTagValueNode::class);
3435

35-
return new Implements_(
36+
$description = $tagValue->getAttribute('description');
37+
if (is_string($description) === false) {
38+
$description = $tagValue->description;
39+
}
40+
41+
$class = $node->name === '@implements' ? Implements_::class : TemplateImplements::class;
42+
43+
return new $class(
3644
$this->typeResolver->createType($tagValue->type, $context),
3745
$this->descriptionFactory->create($tagValue->description, $context)
3846
);
3947
}
4048

4149
public function supports(PhpDocTagNode $node, Context $context): bool
4250
{
43-
return $node->value instanceof ImplementsTagValueNode && $node->name === '@implements';
51+
return $node->value instanceof ImplementsTagValueNode && ($node->name === '@implements' || $node->name === '@template-implements');
4452
}
4553
}

src/DocBlock/Tags/Implements_.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313

1414
namespace phpDocumentor\Reflection\DocBlock\Tags;
1515

16+
use Doctrine\Deprecations\Deprecation;
1617
use phpDocumentor\Reflection\Type;
1718
use phpDocumentor\Reflection\DocBlock\Description;
1819
use phpDocumentor\Reflection\DocBlock\Tags\TagWithType;
1920

2021
/**
2122
* Reflection class for a {@}implements tag in a Docblock.
2223
*/
23-
final class Implements_ extends TagWithType
24+
class Implements_ extends TagWithType
2425
{
2526
public function __construct(Type $type, ?Description $description = null)
2627
{
@@ -35,23 +36,12 @@ public function __construct(Type $type, ?Description $description = null)
3536
*/
3637
public static function create(string $body)
3738
{
38-
trigger_error(
39+
Deprecation::trigger(
40+
'phpdocumentor/reflection-docblock',
41+
'https://github.com/phpDocumentor/ReflectionDocBlock/issues/361',
3942
'Create using static factory is deprecated, this method should not be called directly
4043
by library consumers',
41-
E_USER_DEPRECATED
4244
);
43-
}
44-
45-
public function __toString(): string
46-
{
47-
if ($this->description) {
48-
$description = $this->description->render();
49-
} else {
50-
$description = '';
51-
}
52-
53-
$type = $this->type;
54-
55-
return $type . ($description !== '' ? ' ' . $description : '');
45+
return null;
5646
}
5747
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link http://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Reflection\DocBlock\Tags;
15+
16+
use phpDocumentor\Reflection\Type;
17+
use phpDocumentor\Reflection\DocBlock\Description;
18+
19+
/**
20+
* Reflection class for a {@}template-implements tag in a Docblock.
21+
*/
22+
final class TemplateImplements extends Implements_
23+
{
24+
public function __construct(Type $type, ?Description $description = null)
25+
{
26+
parent::__construct($type, $description);
27+
$this->name = 'template-implements';
28+
}
29+
}

0 commit comments

Comments
 (0)