From f387e8faa9bb405289702eca7cc4bfb1390b00f2 Mon Sep 17 00:00:00 2001 From: AhJ Date: Wed, 24 Jul 2024 12:10:17 +0330 Subject: [PATCH] Add Extends tags --- src/DocBlock/Tags/Extends_.php | 47 +++++++++++++++++ src/DocBlock/Tags/Factory/ExtendsFactory.php | 53 ++++++++++++++++++++ src/DocBlock/Tags/TemplateExtends.php | 29 +++++++++++ 3 files changed, 129 insertions(+) create mode 100644 src/DocBlock/Tags/Extends_.php create mode 100644 src/DocBlock/Tags/Factory/ExtendsFactory.php create mode 100644 src/DocBlock/Tags/TemplateExtends.php diff --git a/src/DocBlock/Tags/Extends_.php b/src/DocBlock/Tags/Extends_.php new file mode 100644 index 0000000..7d54a88 --- /dev/null +++ b/src/DocBlock/Tags/Extends_.php @@ -0,0 +1,47 @@ +name = 'extends'; + $this->type = $type; + $this->description = $description; + } + + /** + * @deprecated Create using static factory is deprecated, + * this method should not be called directly by library consumers + */ + public static function create(string $body) + { + 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', + ); + return null; + } +} diff --git a/src/DocBlock/Tags/Factory/ExtendsFactory.php b/src/DocBlock/Tags/Factory/ExtendsFactory.php new file mode 100644 index 0000000..87611ab --- /dev/null +++ b/src/DocBlock/Tags/Factory/ExtendsFactory.php @@ -0,0 +1,53 @@ +descriptionFactory = $descriptionFactory; + $this->typeResolver = $typeResolver; + } + + public function create(PhpDocTagNode $node, Context $context): Tag + { + $tagValue = $node->value; + Assert::isInstanceOf($tagValue, ExtendsTagValueNode::class); + + $description = $tagValue->getAttribute('description'); + if (is_string($description) === false) { + $description = $tagValue->description; + } + + $class = $node->name === '@extends' ? Extends_::class : TemplateExtends::class; + + return new $class( + $this->typeResolver->createType($tagValue->type, $context), + $this->descriptionFactory->create($tagValue->description, $context) + ); + } + + public function supports(PhpDocTagNode $node, Context $context): bool + { + return $node->value instanceof ExtendsTagValueNode && ($node->name === '@extends' || $node->name === '@template-extends'); + } +} diff --git a/src/DocBlock/Tags/TemplateExtends.php b/src/DocBlock/Tags/TemplateExtends.php new file mode 100644 index 0000000..4c9b257 --- /dev/null +++ b/src/DocBlock/Tags/TemplateExtends.php @@ -0,0 +1,29 @@ +name = 'template-extends'; + } +}