Skip to content

Commit f55a589

Browse files
committed
Add "@OverRide" and "@phan-override" tags support
1 parent 91f6243 commit f55a589

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ composer require type-lang/phpdoc
5757
- [x] `@no-named-arguments` - Indicates that argument names may be
5858
changed in the future.
5959
- [ ] `@package` - TODO
60-
- [ ] `@override` - TODO
60+
- [x] `@override` - Mention to see if the method is actually overriding a definition
6161
- [x] `@param` - Used to document a single argument of a function or method
6262
- [ ] `@param-closure-this` - TODO
6363
- [ ] `@param-immediately-invoked-callable` - TODO
@@ -226,7 +226,7 @@ composer require type-lang/phpdoc
226226
- [x] `@phan-method` - Vendor-specific `@method` alias
227227
- [ ] `@phan-mixin` - TODO
228228
- [ ] `@phan-output-reference` - TODO
229-
- [ ] `@phan-override` - TODO
229+
- [x] `@phan-override` - Vendor-specific `@override` alias
230230
- [x] `@phan-param` - Vendor-specific `@param` alias
231231
- [x] `@phan-property` - Vendor-specific `@property` alias
232232
- [x] `@phan-property-read` - Vendor-specific `@property-read` alias

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

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\PHPDoc\DocBlock\Tag\OverrideTag;
6+
7+
use TypeLang\PHPDoc\DocBlock\Tag\Tag;
8+
9+
/**
10+
* Used is mention to see if the method is actually overriding a definition
11+
* or implementing an abstract method (Or a phpdoc "`@method`")
12+
* in an ancestor class/trait/interface.
13+
*
14+
* ```
15+
* "@override" [<description>]
16+
* ```
17+
*/
18+
final class OverrideTag extends Tag
19+
{
20+
public function __construct(
21+
string $name,
22+
\Stringable|string|null $description = null,
23+
) {
24+
parent::__construct($name, $description);
25+
}
26+
}

Diff for: src/DocBlock/Tag/OverrideTag/OverrideTagFactory.php

+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\OverrideTag;
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 "`@override`" tags.
13+
*
14+
* See {@see OverrideTag} for details about this tag.
15+
*/
16+
final class OverrideTagFactory implements TagFactoryInterface
17+
{
18+
public function create(string $tag, string $content, DescriptionParserInterface $descriptions): OverrideTag
19+
{
20+
$stream = new Stream($tag, $content);
21+
22+
return new OverrideTag(
23+
name: $tag,
24+
description: $stream->toOptionalDescription($descriptions),
25+
);
26+
}
27+
}

Diff for: src/Platform/PhanPlatform.php

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use TypeLang\Parser\ParserInterface as TypesParserInterface;
88
use TypeLang\PHPDoc\DocBlock\Tag\AbstractTag\AbstractTagFactory;
99
use TypeLang\PHPDoc\DocBlock\Tag\MethodTag\MethodTagFactory;
10+
use TypeLang\PHPDoc\DocBlock\Tag\OverrideTag\OverrideTagFactory;
1011
use TypeLang\PHPDoc\DocBlock\Tag\ParamTag\ParamTagFactory;
1112
use TypeLang\PHPDoc\DocBlock\Tag\PropertyTag\PropertyReadTagFactory;
1213
use TypeLang\PHPDoc\DocBlock\Tag\PropertyTag\PropertyTagFactory;
@@ -27,6 +28,7 @@ protected function load(TypesParserInterface $types): iterable
2728
{
2829
yield 'phan-abstract' => new AbstractTagFactory();
2930
yield 'phan-method' => new MethodTagFactory($types);
31+
yield 'phan-override' => new OverrideTagFactory();
3032
yield 'phan-param' => new ParamTagFactory($types);
3133
yield 'phan-property' => new PropertyTagFactory($types);
3234
yield 'phan-property-read' => new PropertyReadTagFactory($types);

Diff for: src/Platform/StandardPlatform.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use TypeLang\PHPDoc\DocBlock\Tag\LinkTag\LinkTagFactory;
1616
use TypeLang\PHPDoc\DocBlock\Tag\MethodTag\MethodTagFactory;
1717
use TypeLang\PHPDoc\DocBlock\Tag\NoNamedArgumentsTag\NoNamedArgumentsTagFactory;
18+
use TypeLang\PHPDoc\DocBlock\Tag\OverrideTag\OverrideTagFactory;
1819
use TypeLang\PHPDoc\DocBlock\Tag\ParamTag\ParamTagFactory;
1920
use TypeLang\PHPDoc\DocBlock\Tag\PropertyTag\PropertyReadTagFactory;
2021
use TypeLang\PHPDoc\DocBlock\Tag\PropertyTag\PropertyTagFactory;
@@ -49,6 +50,7 @@ protected function load(TypesParserInterface $types): iterable
4950
yield 'link' => new LinkTagFactory();
5051
yield 'method' => new MethodTagFactory($types);
5152
yield 'no-named-arguments' => new NoNamedArgumentsTagFactory();
53+
yield 'override' => new OverrideTagFactory();
5254
yield 'param' => new ParamTagFactory($types);
5355
yield 'property' => new PropertyTagFactory($types);
5456
yield 'property-read' => new PropertyReadTagFactory($types);
@@ -70,9 +72,8 @@ protected function load(TypesParserInterface $types): iterable
7072
*/
7173
protected function loadAliases(TypesParserInterface $types): iterable
7274
{
73-
yield 'inherits' => $extends = new TemplateExtendsTagFactory($types);
7475
yield 'returns' => new ReturnTagFactory($types);
75-
yield 'template-extends' => $extends;
76+
yield ['template-extends', 'inherits'] => new TemplateExtendsTagFactory($types);
7677
yield 'template-implements' => new TemplateImplementsTagFactory($types);
7778
yield 'template-use' => new TemplateExtendsTagFactory($types);
7879
yield 'throw' => new ThrowsTagFactory($types);

0 commit comments

Comments
 (0)