Skip to content

Commit bc85b10

Browse files
committed
Add "@abstract" tag support
1 parent 6d1f70b commit bc85b10

File tree

7 files changed

+90
-42
lines changed

7 files changed

+90
-42
lines changed

Diff for: README.md

+14-8
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ composer require type-lang/phpdoc
3232

3333
## Supported Tags
3434

35-
- [ ] `@abstract` - TODO
35+
- [x] `@abstract` - Declare a class-like _Symbol_ or method as abstract
3636
- [ ] `@api` - TODO
3737
- [ ] `@author` - TODO
3838
- [ ] `@category` - TODO
@@ -49,7 +49,8 @@ composer require type-lang/phpdoc
4949
- [x] `@inherits` - An alias of `@extends` tag
5050
- [ ] `@internal` - TODO
5151
- [ ] `@license` - TODO
52-
- [x] `@link` - Indicates a custom relation between the associated _Symbol_ and a website, which is identified by an absolute URI
52+
- [x] `@link` - Indicates a custom relation between the associated _Symbol_
53+
and a website, which is identified by an absolute URI
5354
- [x] `@method` - Allows a class to know which "_magic_" methods are callable
5455
- [ ] `@mixin` - TODO
5556
- [ ] `@no-named-arguments` - TODO
@@ -71,19 +72,24 @@ composer require type-lang/phpdoc
7172
- [x] `@returns` - An alias of `@return` tag
7273
- [ ] `@seal-methods` - TODO
7374
- [ ] `@seal-properties` - TODO
74-
- [x] `@see` - Indicates a reference from the associated _Symbol(s)_ to a website or other _Symbol(s)_
75+
- [x] `@see` - Indicates a reference from the associated _Symbol(s)_ to a
76+
website or other _Symbol(s)_
7577
- [ ] `@since` - TODO
7678
- [ ] `@source` - TODO
7779
- [ ] `@subpackage` - TODO
7880
- [ ] `@suppress` - TODO
79-
- [x] `@template` - Allows classes (and class-like entries), functions and methods to declare a generic type parameter
80-
- [x] `@template-contravariant` - Allows classes (and class-like entries), functions and methods to declare a generic contravariant type parameter
81-
- [x] `@template-covariant` - Allows classes (and class-like entries), functions and methods to declare a generic covariant type parameter
81+
- [x] `@template` - Allows classes (and class-like entries), functions and
82+
methods to declare a generic type parameter
83+
- [x] `@template-contravariant` - Allows classes (and class-like entries),
84+
functions and methods to declare a generic contravariant type parameter
85+
- [x] `@template-covariant` - Allows classes (and class-like entries), functions
86+
and methods to declare a generic covariant type parameter
8287
- [x] `@template-extends` - An alias of `@extends` tag
8388
- [x] `@template-implements` - An alias of `@implements` tag
8489
- [x] `@template-use` - Allows to extend templated traits
8590
- [x] `@throw` - An alias of `@throws` tag
86-
- [x] `@throws` - Used to indicate whether _Symbol_ throw a specific type of `\Throwable` (exception or error)
91+
- [x] `@throws` - Used to indicate whether _Symbol_ throw a specific type
92+
of `\Throwable` (exception or error)
8793
- [ ] `@todo` - TODO
8894
- [ ] `@unused-param` - TODO
8995
- [x] `@use` - An alias of `@template-use` tag
@@ -200,7 +206,7 @@ composer require type-lang/phpdoc
200206

201207
### Phan Tags
202208

203-
- [ ] `@phan-abstract` - TODO
209+
- [x] `@phan-abstract` - Vendor-specific `@abstract` alias
204210
- [ ] `@phan-assert` - TODO
205211
- [ ] `@phan-assert-false-condition` - TODO
206212
- [ ] `@phan-assert-if-false` - TODO

Diff for: src/DocBlock/Tag/AbstractTag/AbstractTag.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\AbstractTag;
6+
7+
use TypeLang\PHPDoc\DocBlock\Tag\Tag;
8+
9+
/**
10+
* Declare a class-like or method as abstract, as well as for declaring
11+
* what methods must be redefined in a child class.
12+
*
13+
* ```
14+
* "@abstract" [<description>]
15+
* ```
16+
*/
17+
final class AbstractTag extends Tag
18+
{
19+
public function __construct(
20+
string $name,
21+
\Stringable|string|null $description = null,
22+
) {
23+
parent::__construct($name, $description);
24+
}
25+
}

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

Diff for: src/Parser.php

-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use TypeLang\PHPDoc\Parser\Tag\RegexTagParser;
2020
use TypeLang\PHPDoc\Parser\Tag\TagParserInterface;
2121
use TypeLang\PHPDoc\Platform\CompoundPlatform;
22-
use TypeLang\PHPDoc\Platform\FallbacksPlatform;
2322
use TypeLang\PHPDoc\Platform\PhanPlatform;
2423
use TypeLang\PHPDoc\Platform\PHPStanPlatform;
2524
use TypeLang\PHPDoc\Platform\PlatformInterface;
@@ -42,7 +41,6 @@ public function __construct(
4241
new PsalmPlatform(),
4342
new PHPStanPlatform(),
4443
new PhanPlatform(),
45-
new FallbacksPlatform(),
4644
]),
4745
) {
4846
$this->factories = new TagFactory($platform->getTags());

Diff for: src/Platform/FallbacksPlatform.php

-28
This file was deleted.

Diff for: src/Platform/PhanPlatform.php

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace TypeLang\PHPDoc\Platform;
66

77
use TypeLang\Parser\ParserInterface as TypesParserInterface;
8+
use TypeLang\PHPDoc\DocBlock\Tag\AbstractTag\AbstractTagFactory;
89
use TypeLang\PHPDoc\DocBlock\Tag\MethodTag\MethodTagFactory;
910
use TypeLang\PHPDoc\DocBlock\Tag\ParamTag\ParamTagFactory;
1011
use TypeLang\PHPDoc\DocBlock\Tag\PropertyTag\PropertyReadTagFactory;
@@ -24,6 +25,7 @@ public function getName(): string
2425

2526
protected function load(TypesParserInterface $types): iterable
2627
{
28+
yield 'phan-abstract' => new AbstractTagFactory();
2729
yield 'phan-method' => new MethodTagFactory($types);
2830
yield 'phan-param' => new ParamTagFactory($types);
2931
yield 'phan-property' => new PropertyTagFactory($types);

Diff for: src/Platform/StandardPlatform.php

+22-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace TypeLang\PHPDoc\Platform;
66

77
use TypeLang\Parser\ParserInterface as TypesParserInterface;
8+
use TypeLang\PHPDoc\DocBlock\Tag\AbstractTag\AbstractTagFactory;
9+
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactoryInterface;
810
use TypeLang\PHPDoc\DocBlock\Tag\LinkTag\LinkTagFactory;
911
use TypeLang\PHPDoc\DocBlock\Tag\MethodTag\MethodTagFactory;
1012
use TypeLang\PHPDoc\DocBlock\Tag\ParamTag\ParamTagFactory;
@@ -30,6 +32,9 @@ public function getName(): string
3032

3133
protected function load(TypesParserInterface $types): iterable
3234
{
35+
yield 'abstract' => new AbstractTagFactory();
36+
yield 'extends' => new TemplateExtendsTagFactory($types);
37+
yield 'implements' => new TemplateImplementsTagFactory($types);
3338
yield 'link' => new LinkTagFactory();
3439
yield 'method' => new MethodTagFactory($types);
3540
yield 'param' => new ParamTagFactory($types);
@@ -39,12 +44,25 @@ protected function load(TypesParserInterface $types): iterable
3944
yield 'return' => new ReturnTagFactory($types);
4045
yield 'see' => new SeeTagFactory($types);
4146
yield 'template' => new TemplateTagFactory($types);
42-
yield 'implements' => new TemplateImplementsTagFactory($types);
43-
yield 'extends' => new TemplateExtendsTagFactory($types);
44-
yield 'use' => new TemplateExtendsTagFactory($types);
45-
yield 'template-covariant' => new TemplateCovariantTagFactory($types);
4647
yield 'template-contravariant' => new TemplateContravariantTagFactory($types);
48+
yield 'template-covariant' => new TemplateCovariantTagFactory($types);
49+
yield 'use' => new TemplateExtendsTagFactory($types);
4750
yield 'throws' => new ThrowsTagFactory($types);
4851
yield 'var' => new VarTagFactory($types);
52+
53+
yield from $this->loadAliases($types);
54+
}
55+
56+
/**
57+
* @return iterable<non-empty-string|iterable<mixed, non-empty-string>, TagFactoryInterface>
58+
*/
59+
protected function loadAliases(TypesParserInterface $types): iterable
60+
{
61+
yield 'inherits' => $extends = new TemplateExtendsTagFactory($types);
62+
yield 'returns' => new ReturnTagFactory($types);
63+
yield 'template-extends' => $extends;
64+
yield 'template-implements' => new TemplateImplementsTagFactory($types);
65+
yield 'template-use' => new TemplateExtendsTagFactory($types);
66+
yield 'throw' => new ThrowsTagFactory($types);
4967
}
5068
}

0 commit comments

Comments
 (0)