Skip to content

Commit 6e19f62

Browse files
committed
Add "@inheritdoc" tag support
1 parent bd4d12d commit 6e19f62

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

Diff for: src/DocBlock/Tag/InheritDocTag/InheritDocTag.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\PHPDoc\DocBlock\Tag\InheritDocTag;
6+
7+
use TypeLang\PHPDoc\DocBlock\Tag\Tag;
8+
9+
/**
10+
* Used to directly inherit the long description from the parent
11+
* class in child classes.
12+
*
13+
* ```
14+
* "@inheritDoc" [<description>]
15+
* ```
16+
*/
17+
final class InheritDocTag extends Tag
18+
{
19+
public function __construct(
20+
string $name,
21+
\Stringable|string|null $description = null,
22+
) {
23+
parent::__construct($name, $description);
24+
}
25+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\PHPDoc\DocBlock\Tag\InheritDocTag;
6+
7+
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactoryInterface;
8+
use TypeLang\PHPDoc\Parser\Content\Stream;
9+
use TypeLang\PHPDoc\Parser\Description\DescriptionParserInterface;
10+
11+
/**
12+
* This class is responsible for creating "`@inheritDoc`" tags.
13+
*
14+
* See {@see InheritDocTag} for details about this tag.
15+
*/
16+
final class InheritDocTagFactory implements TagFactoryInterface
17+
{
18+
public function create(string $tag, string $content, DescriptionParserInterface $descriptions): InheritDocTag
19+
{
20+
$stream = new Stream($tag, $content);
21+
22+
return new InheritDocTag(
23+
name: $tag,
24+
description: $stream->toOptionalDescription($descriptions),
25+
);
26+
}
27+
}

Diff for: src/Platform/StandardPlatform.php

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactoryInterface;
1010
use TypeLang\PHPDoc\DocBlock\Tag\FinalTag\FinalTagFactory;
1111
use TypeLang\PHPDoc\DocBlock\Tag\IgnoreTag\IgnoreTagFactory;
12+
use TypeLang\PHPDoc\DocBlock\Tag\InheritDocTag\InheritDocTagFactory;
1213
use TypeLang\PHPDoc\DocBlock\Tag\LinkTag\LinkTagFactory;
1314
use TypeLang\PHPDoc\DocBlock\Tag\MethodTag\MethodTagFactory;
1415
use TypeLang\PHPDoc\DocBlock\Tag\NoNamedArgumentsTag\NoNamedArgumentsTagFactory;
@@ -39,6 +40,7 @@ protected function load(TypesParserInterface $types): iterable
3940
yield 'extends' => new TemplateExtendsTagFactory($types);
4041
yield 'final' => new FinalTagFactory();
4142
yield 'implements' => new TemplateImplementsTagFactory($types);
43+
yield 'inheritdoc' => new InheritDocTagFactory();
4244
yield 'ignore' => new IgnoreTagFactory();
4345
yield 'link' => new LinkTagFactory();
4446
yield 'method' => new MethodTagFactory($types);

0 commit comments

Comments
 (0)