Skip to content

Commit 91f6243

Browse files
committed
Add "@api" and "@psalm-api" tags support
1 parent 4f5b914 commit 91f6243

File tree

5 files changed

+74
-2
lines changed

5 files changed

+74
-2
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ composer require type-lang/phpdoc
3333
## Supported Tags
3434

3535
- [x] `@abstract` - Declare any _Symbol_ as abstract
36-
- [ ] `@api` - TODO
36+
- [x] `@api` - Highlight _Symbol_ as being part of the public API
3737
- [ ] `@author` - TODO
3838
- [ ] `@category` - TODO
3939
- [ ] `@copyright` - TODO
@@ -103,7 +103,7 @@ composer require type-lang/phpdoc
103103
### Psalm Tags
104104

105105
- [ ] `@psalm-allow-private-mutation` - TODO
106-
- [ ] `@psalm-api` - TODO
106+
- [x] `@psalm-api` - Vendor-specific `@api` alias
107107
- [ ] `@psalm-assert` - TODO
108108
- [ ] `@psalm-assert-if-false` - TODO
109109
- [ ] `@psalm-assert-if-true` - TODO

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

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\PHPDoc\DocBlock\Tag\ApiTag;
6+
7+
use TypeLang\PHPDoc\DocBlock\Tag\Tag;
8+
9+
/**
10+
* Used to highlight _Symbol_ as being part of the primary
11+
* public API of a package.
12+
*
13+
* The "`@api`" tag may be applied to public _Symbol_ to highlight them
14+
* in generated documentation, pointing the consumer to the primary public
15+
* API components of a library or framework.
16+
*
17+
* When the "`@api`" tag is used, other _Symbol_ with a public
18+
* visibility serve to support the internal structure and
19+
* are not recommended to be used by the consumer.
20+
*
21+
* The exact meaning of _Symbol_ tagged with "`@api`" MAY differ per project.
22+
* It is however RECOMMENDED that all "`@api`" tagged _Symbol_ SHOULD
23+
* NOT change after publication unless the new version
24+
* is tagged as breaking Backwards Compatibility.
25+
*
26+
* See also the `"@internal"` tag, which can be used to hide internal
27+
* _Symbol_ from generated documentation.
28+
*
29+
* ```
30+
* "@api" [<description>]
31+
* ```
32+
*/
33+
final class ApiTag extends Tag
34+
{
35+
public function __construct(
36+
string $name,
37+
\Stringable|string|null $description = null,
38+
) {
39+
parent::__construct($name, $description);
40+
}
41+
}

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

Diff for: src/Platform/PsalmPlatform.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\ApiTag\ApiTagFactory;
89
use TypeLang\PHPDoc\DocBlock\Tag\MethodTag\MethodTagFactory;
910
use TypeLang\PHPDoc\DocBlock\Tag\ParamTag\ParamTagFactory;
1011
use TypeLang\PHPDoc\DocBlock\Tag\PropertyTag\PropertyReadTagFactory;
@@ -27,6 +28,7 @@ public function getName(): string
2728

2829
protected function load(TypesParserInterface $types): iterable
2930
{
31+
yield 'psalm-api' => new ApiTagFactory();
3032
yield 'psalm-method' => new MethodTagFactory($types);
3133
yield 'psalm-param' => new ParamTagFactory($types);
3234
yield 'psalm-property' => new PropertyTagFactory($types);

Diff for: src/Platform/StandardPlatform.php

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use TypeLang\Parser\ParserInterface as TypesParserInterface;
88
use TypeLang\PHPDoc\DocBlock\Tag\AbstractTag\AbstractTagFactory;
9+
use TypeLang\PHPDoc\DocBlock\Tag\ApiTag\ApiTagFactory;
910
use TypeLang\PHPDoc\DocBlock\Tag\Factory\TagFactoryInterface;
1011
use TypeLang\PHPDoc\DocBlock\Tag\FinalTag\FinalTagFactory;
1112
use TypeLang\PHPDoc\DocBlock\Tag\IgnoreTag\IgnoreTagFactory;
@@ -38,6 +39,7 @@ public function getName(): string
3839
protected function load(TypesParserInterface $types): iterable
3940
{
4041
yield 'abstract' => new AbstractTagFactory();
42+
yield 'api' => new ApiTagFactory();
4143
yield 'extends' => new TemplateExtendsTagFactory($types);
4244
yield 'final' => new FinalTagFactory();
4345
yield 'implements' => new TemplateImplementsTagFactory($types);

0 commit comments

Comments
 (0)