From 3acbe24b178e80b6a8f5f386c90c38ff380c051e Mon Sep 17 00:00:00 2001 From: AhJ Date: Wed, 24 Jul 2024 12:10:38 +0330 Subject: [PATCH] Add Implements tags --- .../Tags/Factory/ImplementsFactory.php | 16 +++++++--- src/DocBlock/Tags/Implements_.php | 22 ++++---------- src/DocBlock/Tags/TemplateImplements.php | 29 +++++++++++++++++++ 3 files changed, 47 insertions(+), 20 deletions(-) create mode 100644 src/DocBlock/Tags/TemplateImplements.php diff --git a/src/DocBlock/Tags/Factory/ImplementsFactory.php b/src/DocBlock/Tags/Factory/ImplementsFactory.php index ba7ac5f..5f1e9db 100644 --- a/src/DocBlock/Tags/Factory/ImplementsFactory.php +++ b/src/DocBlock/Tags/Factory/ImplementsFactory.php @@ -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'); } } diff --git a/src/DocBlock/Tags/Implements_.php b/src/DocBlock/Tags/Implements_.php index 2e53f2c..a871d43 100644 --- a/src/DocBlock/Tags/Implements_.php +++ b/src/DocBlock/Tags/Implements_.php @@ -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; } } diff --git a/src/DocBlock/Tags/TemplateImplements.php b/src/DocBlock/Tags/TemplateImplements.php new file mode 100644 index 0000000..d6cd689 --- /dev/null +++ b/src/DocBlock/Tags/TemplateImplements.php @@ -0,0 +1,29 @@ +name = 'template-implements'; + } +}