Add Implements tags

This commit is contained in:
AhJ
2024-07-24 12:10:38 +03:30
parent f387e8faa9
commit 3acbe24b17
3 changed files with 47 additions and 20 deletions
@@ -5,13 +5,14 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\DocBlock\Tags\Factory;
use Webmozart\Assert\Assert;
use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\TypeResolver;
use phpDocumentor\Reflection\Types\Context;
use phpDocumentor\Reflection\DocBlock\Tag;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use phpDocumentor\Reflection\DocBlock\Tags\Implements_;
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\ImplementsTagValueNode;
use phpDocumentor\Reflection\DocBlock\Tags\TemplateImplements;
/**
* @internal This class is not part of the BC promise of this library.
@@ -32,7 +33,14 @@ class ImplementsFactory implements PHPStanFactory
$tagValue = $node->value;
Assert::isInstanceOf($tagValue, ImplementsTagValueNode::class);
return new Implements_(
$description = $tagValue->getAttribute('description');
if (is_string($description) === false) {
$description = $tagValue->description;
}
$class = $node->name === '@implements' ? Implements_::class : TemplateImplements::class;
return new $class(
$this->typeResolver->createType($tagValue->type, $context),
$this->descriptionFactory->create($tagValue->description, $context)
);
@@ -40,6 +48,6 @@ class ImplementsFactory implements PHPStanFactory
public function supports(PhpDocTagNode $node, Context $context): bool
{
return $node->value instanceof ImplementsTagValueNode && $node->name === '@implements';
return $node->value instanceof ImplementsTagValueNode && ($node->name === '@implements' || $node->name === '@template-implements');
}
}
+6 -16
View File
@@ -13,6 +13,7 @@ declare(strict_types=1);
namespace phpDocumentor\Reflection\DocBlock\Tags;
use Doctrine\Deprecations\Deprecation;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\Tags\TagWithType;
@@ -20,7 +21,7 @@ use phpDocumentor\Reflection\DocBlock\Tags\TagWithType;
/**
* Reflection class for a {@}implements tag in a Docblock.
*/
final class Implements_ extends TagWithType
class Implements_ extends TagWithType
{
public function __construct(Type $type, ?Description $description = null)
{
@@ -35,23 +36,12 @@ final class Implements_ extends TagWithType
*/
public static function create(string $body)
{
trigger_error(
Deprecation::trigger(
'phpdocumentor/reflection-docblock',
'https://github.com/phpDocumentor/ReflectionDocBlock/issues/361',
'Create using static factory is deprecated, this method should not be called directly
by library consumers',
E_USER_DEPRECATED
);
}
public function __toString(): string
{
if ($this->description) {
$description = $this->description->render();
} else {
$description = '';
}
$type = $this->type;
return $type . ($description !== '' ? ' ' . $description : '');
return null;
}
}
+29
View File
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection\DocBlock\Tags;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\DocBlock\Description;
/**
* Reflection class for a {@}template-implements tag in a Docblock.
*/
final class TemplateImplements extends Implements_
{
public function __construct(Type $type, ?Description $description = null)
{
parent::__construct($type, $description);
$this->name = 'template-implements';
}
}