Skip to content

Commit bfcf718

Browse files
committed
Add phpDocumentor platform
1 parent b77980b commit bfcf718

4 files changed

Lines changed: 126 additions & 45 deletions

File tree

libs/phpdoc/src/DocBlockParser.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use TypeLang\PhpDoc\Parser\Tag\TagParserInterface;
2424
use TypeLang\PhpDoc\Parser\TagFactory;
2525
use TypeLang\PhpDoc\Parser\TagRegistry;
26+
use TypeLang\PhpDoc\Platform\PhpDocumentorPlatform;
2627
use TypeLang\PhpDoc\Platform\PlatformInterface;
2728
use TypeLang\PhpDoc\Platform\StandardPlatform;
2829

@@ -42,7 +43,9 @@
4243
/**
4344
* @param iterable<PlatformInterface> $platforms additional tag platforms
4445
*/
45-
public function __construct(iterable $platforms = [])
46+
public function __construct(iterable $platforms = [
47+
new PhpDocumentorPlatform(),
48+
])
4649
{
4750
$platforms = $this->loadPlatforms($platforms);
4851

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\PhpDoc\Platform;
6+
7+
use TypeLang\PhpDoc\DocBlock\Combinator\AuthorNameCombinator;
8+
use TypeLang\PhpDoc\DocBlock\Combinator\EmailCombinator;
9+
use TypeLang\PhpDoc\DocBlock\Combinator\VisibilityCombinator;
10+
use TypeLang\PhpDoc\DocBlock\Tag\AccessTag\AccessTagDefinition;
11+
use TypeLang\PhpDoc\DocBlock\Tag\AuthorTag\AuthorTagDefinition;
12+
use TypeLang\PhpDoc\DocBlock\Tag\CategoryTag\CategoryTagDefinition;
13+
use TypeLang\PhpDoc\DocBlock\Tag\CopyrightTag\CopyrightTagDefinition;
14+
use TypeLang\PhpDoc\DocBlock\Tag\ExampleTag\ExampleTagDefinition;
15+
use TypeLang\PhpDoc\DocBlock\Tag\FilesourceTag\FilesourceTagDefinition;
16+
use TypeLang\PhpDoc\DocBlock\Tag\GlobalTag\GlobalTagDefinition;
17+
use TypeLang\PhpDoc\DocBlock\Tag\IgnoreTag\IgnoreTagDefinition;
18+
use TypeLang\PhpDoc\DocBlock\Tag\InheritDocTag\InheritDocTagDefinition;
19+
use TypeLang\PhpDoc\DocBlock\Tag\LicenseTag\LicenseTagDefinition;
20+
use TypeLang\PhpDoc\DocBlock\Tag\NameTag\NameTagDefinition;
21+
use TypeLang\PhpDoc\DocBlock\Tag\PackageTag\PackageTagDefinition;
22+
use TypeLang\PhpDoc\DocBlock\Tag\SinceTag\SinceTagDefinition;
23+
use TypeLang\PhpDoc\DocBlock\Tag\SourceTag\SourceTagDefinition;
24+
use TypeLang\PhpDoc\DocBlock\Tag\StaticTag\StaticTagDefinition;
25+
use TypeLang\PhpDoc\DocBlock\Tag\StaticVarTag\StaticVarTagDefinition;
26+
use TypeLang\PhpDoc\DocBlock\Tag\SubpackageTag\SubpackageTagDefinition;
27+
use TypeLang\PhpDoc\DocBlock\Tag\UsedByTag\UsedByTagDefinition;
28+
use TypeLang\PhpDoc\DocBlock\Tag\UsesTag\UsesTagDefinition;
29+
use TypeLang\PhpDoc\DocBlock\TagDefinition\TagDefinitionInterface;
30+
use TypeLang\PhpDoc\Parser\Grammar\CombinatorInterface;
31+
32+
/**
33+
* The phpDocumentor platform: the legacy tag family defined by phpDocumentor
34+
* that a modern, static-analysis-oriented docblock rarely uses.
35+
*
36+
* It extends the {@see StandardPlatform} with these older tags and the few
37+
* combinators only they rely on.
38+
*
39+
* @phpstan-import-type CombinatorType from CombinatorInterface
40+
*/
41+
final class PhpDocumentorPlatform extends Platform
42+
{
43+
/**
44+
* @var non-empty-string
45+
*/
46+
public const string NAME = 'phpDocumentor';
47+
48+
public private(set) string $name = self::NAME;
49+
50+
/**
51+
* @var iterable<non-empty-lowercase-string, TagDefinitionInterface>
52+
*/
53+
public iterable $tags {
54+
get => [
55+
AccessTagDefinition::NAME => new AccessTagDefinition(),
56+
AuthorTagDefinition::NAME => new AuthorTagDefinition(),
57+
CategoryTagDefinition::NAME => new CategoryTagDefinition(),
58+
CopyrightTagDefinition::NAME => new CopyrightTagDefinition(),
59+
ExampleTagDefinition::NAME => new ExampleTagDefinition(),
60+
FilesourceTagDefinition::NAME => new FilesourceTagDefinition(),
61+
GlobalTagDefinition::NAME => new GlobalTagDefinition(),
62+
IgnoreTagDefinition::NAME => new IgnoreTagDefinition(),
63+
InheritDocTagDefinition::NAME => new InheritDocTagDefinition(),
64+
LicenseTagDefinition::NAME => new LicenseTagDefinition(),
65+
NameTagDefinition::NAME => new NameTagDefinition(),
66+
PackageTagDefinition::NAME => new PackageTagDefinition(),
67+
SinceTagDefinition::NAME => new SinceTagDefinition(),
68+
SourceTagDefinition::NAME => new SourceTagDefinition(),
69+
StaticTagDefinition::NAME => new StaticTagDefinition(),
70+
StaticVarTagDefinition::NAME => new StaticVarTagDefinition(),
71+
SubpackageTagDefinition::NAME => new SubpackageTagDefinition(),
72+
UsedByTagDefinition::NAME => new UsedByTagDefinition(),
73+
UsesTagDefinition::NAME => new UsesTagDefinition(),
74+
];
75+
}
76+
77+
/**
78+
* @var iterable<non-empty-string, CombinatorType>
79+
*/
80+
public iterable $combinators {
81+
get => [
82+
VisibilityCombinator::NAME => new VisibilityCombinator(),
83+
AuthorNameCombinator::NAME => new AuthorNameCombinator(),
84+
EmailCombinator::NAME => new EmailCombinator(),
85+
];
86+
}
87+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\PhpDoc\Platform;
6+
7+
use TypeLang\PhpDoc\DocBlock\TagDefinition\TagDefinitionInterface;
8+
use TypeLang\PhpDoc\Parser\Grammar\CombinatorInterface;
9+
10+
/**
11+
* @phpstan-import-type CombinatorType from CombinatorInterface
12+
*/
13+
abstract class Platform implements PlatformInterface
14+
{
15+
/**
16+
* @var iterable<non-empty-lowercase-string, TagDefinitionInterface>
17+
*/
18+
public iterable $tags {
19+
get => [];
20+
}
21+
22+
/**
23+
* @var iterable<non-empty-lowercase-string, non-empty-lowercase-string>
24+
*/
25+
public iterable $aliases {
26+
get => [];
27+
}
28+
29+
/**
30+
* @var iterable<non-empty-string, CombinatorType>
31+
*/
32+
public iterable $combinators {
33+
get => [];
34+
}
35+
}

libs/phpdoc/src/Platform/StandardPlatform.php

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77
use TypeLang\Parser\TypeParser;
88
use TypeLang\Parser\TypeParserInterface;
9-
use TypeLang\PhpDoc\DocBlock\Combinator\AuthorNameCombinator;
109
use TypeLang\PhpDoc\DocBlock\Combinator\CallableTypeCombinator;
11-
use TypeLang\PhpDoc\DocBlock\Combinator\EmailCombinator;
1210
use TypeLang\PhpDoc\DocBlock\Combinator\IntegerCombinator;
1311
use TypeLang\PhpDoc\DocBlock\Combinator\IssueNameCombinator;
1412
use TypeLang\PhpDoc\DocBlock\Combinator\NameCombinator;
@@ -18,32 +16,19 @@
1816
use TypeLang\PhpDoc\DocBlock\Combinator\UrlCombinator;
1917
use TypeLang\PhpDoc\DocBlock\Combinator\VariableCombinator;
2018
use TypeLang\PhpDoc\DocBlock\Combinator\VersionCombinator;
21-
use TypeLang\PhpDoc\DocBlock\Combinator\VisibilityCombinator;
2219
use TypeLang\PhpDoc\DocBlock\Tag\AbstractTag\AbstractTagDefinition;
23-
use TypeLang\PhpDoc\DocBlock\Tag\AccessTag\AccessTagDefinition;
2420
use TypeLang\PhpDoc\DocBlock\Tag\ApiTag\ApiTagDefinition;
25-
use TypeLang\PhpDoc\DocBlock\Tag\AuthorTag\AuthorTagDefinition;
26-
use TypeLang\PhpDoc\DocBlock\Tag\CategoryTag\CategoryTagDefinition;
27-
use TypeLang\PhpDoc\DocBlock\Tag\CopyrightTag\CopyrightTagDefinition;
2821
use TypeLang\PhpDoc\DocBlock\Tag\DeprecatedTag\DeprecatedTagDefinition;
29-
use TypeLang\PhpDoc\DocBlock\Tag\ExampleTag\ExampleTagDefinition;
30-
use TypeLang\PhpDoc\DocBlock\Tag\FilesourceTag\FilesourceTagDefinition;
3122
use TypeLang\PhpDoc\DocBlock\Tag\FinalTag\FinalTagDefinition;
32-
use TypeLang\PhpDoc\DocBlock\Tag\GlobalTag\GlobalTagDefinition;
33-
use TypeLang\PhpDoc\DocBlock\Tag\IgnoreTag\IgnoreTagDefinition;
3423
use TypeLang\PhpDoc\DocBlock\Tag\InheritanceTag\ExtendsTagDefinition;
3524
use TypeLang\PhpDoc\DocBlock\Tag\InheritanceTag\ImplementsTagDefinition;
3625
use TypeLang\PhpDoc\DocBlock\Tag\InheritanceTag\UseTagDefinition;
37-
use TypeLang\PhpDoc\DocBlock\Tag\InheritDocTag\InheritDocTagDefinition;
3826
use TypeLang\PhpDoc\DocBlock\Tag\InternalTag\InternalTagDefinition;
39-
use TypeLang\PhpDoc\DocBlock\Tag\LicenseTag\LicenseTagDefinition;
4027
use TypeLang\PhpDoc\DocBlock\Tag\LinkTag\LinkTagDefinition;
4128
use TypeLang\PhpDoc\DocBlock\Tag\MethodTag\MethodTagDefinition;
4229
use TypeLang\PhpDoc\DocBlock\Tag\MixinTag\MixinTagDefinition;
43-
use TypeLang\PhpDoc\DocBlock\Tag\NameTag\NameTagDefinition;
4430
use TypeLang\PhpDoc\DocBlock\Tag\NoNamedArgumentsTag\NoNamedArgumentsTagDefinition;
4531
use TypeLang\PhpDoc\DocBlock\Tag\OverrideTag\OverrideTagDefinition;
46-
use TypeLang\PhpDoc\DocBlock\Tag\PackageTag\PackageTagDefinition;
4732
use TypeLang\PhpDoc\DocBlock\Tag\ParamClosureThisTag\ParamClosureThisTagDefinition;
4833
use TypeLang\PhpDoc\DocBlock\Tag\ParamInvokedCallableTag\ParamImmediatelyInvokedCallableTagDefinition;
4934
use TypeLang\PhpDoc\DocBlock\Tag\ParamInvokedCallableTag\ParamLaterInvokedCallableTagDefinition;
@@ -60,20 +45,13 @@
6045
use TypeLang\PhpDoc\DocBlock\Tag\SealMethodsTag\SealMethodsTagDefinition;
6146
use TypeLang\PhpDoc\DocBlock\Tag\SealPropertiesTag\SealPropertiesTagDefinition;
6247
use TypeLang\PhpDoc\DocBlock\Tag\SeeTag\SeeTagDefinition;
63-
use TypeLang\PhpDoc\DocBlock\Tag\SinceTag\SinceTagDefinition;
64-
use TypeLang\PhpDoc\DocBlock\Tag\SourceTag\SourceTagDefinition;
65-
use TypeLang\PhpDoc\DocBlock\Tag\StaticTag\StaticTagDefinition;
66-
use TypeLang\PhpDoc\DocBlock\Tag\StaticVarTag\StaticVarTagDefinition;
67-
use TypeLang\PhpDoc\DocBlock\Tag\SubpackageTag\SubpackageTagDefinition;
6848
use TypeLang\PhpDoc\DocBlock\Tag\SuppressTag\SuppressTagDefinition;
6949
use TypeLang\PhpDoc\DocBlock\Tag\TemplateTag\TemplateContravariantTagDefinition;
7050
use TypeLang\PhpDoc\DocBlock\Tag\TemplateTag\TemplateCovariantTagDefinition;
7151
use TypeLang\PhpDoc\DocBlock\Tag\TemplateTag\TemplateTagDefinition;
7252
use TypeLang\PhpDoc\DocBlock\Tag\ThrowsTag\ThrowsTagDefinition;
7353
use TypeLang\PhpDoc\DocBlock\Tag\TodoTag\TodoTagDefinition;
7454
use TypeLang\PhpDoc\DocBlock\Tag\UnusedParamTag\UnusedParamTagDefinition;
75-
use TypeLang\PhpDoc\DocBlock\Tag\UsedByTag\UsedByTagDefinition;
76-
use TypeLang\PhpDoc\DocBlock\Tag\UsesTag\UsesTagDefinition;
7755
use TypeLang\PhpDoc\DocBlock\Tag\VarTag\VarTagDefinition;
7856
use TypeLang\PhpDoc\DocBlock\Tag\VersionTag\VersionTagDefinition;
7957
use TypeLang\PhpDoc\DocBlock\TagDefinition\TagDefinitionInterface;
@@ -124,9 +102,6 @@ final class StandardPlatform implements PlatformInterface
124102
AbstractTagDefinition::NAME => new AbstractTagDefinition(),
125103
ApiTagDefinition::NAME => new ApiTagDefinition(),
126104
FinalTagDefinition::NAME => new FinalTagDefinition(),
127-
FilesourceTagDefinition::NAME => new FilesourceTagDefinition(),
128-
IgnoreTagDefinition::NAME => new IgnoreTagDefinition(),
129-
InheritDocTagDefinition::NAME => new InheritDocTagDefinition(),
130105
InternalTagDefinition::NAME => new InternalTagDefinition(),
131106
NoNamedArgumentsTagDefinition::NAME => new NoNamedArgumentsTagDefinition(),
132107
OverrideTagDefinition::NAME => new OverrideTagDefinition(),
@@ -135,30 +110,14 @@ final class StandardPlatform implements PlatformInterface
135110
SealPropertiesTagDefinition::NAME => new SealPropertiesTagDefinition(),
136111
PureUnlessCallableIsImpureTagDefinition::NAME => new PureUnlessCallableIsImpureTagDefinition(),
137112
TodoTagDefinition::NAME => new TodoTagDefinition(),
138-
CategoryTagDefinition::NAME => new CategoryTagDefinition(),
139-
CopyrightTagDefinition::NAME => new CopyrightTagDefinition(),
140-
PackageTagDefinition::NAME => new PackageTagDefinition(),
141-
SubpackageTagDefinition::NAME => new SubpackageTagDefinition(),
142-
UsesTagDefinition::NAME => new UsesTagDefinition(),
143-
UsedByTagDefinition::NAME => new UsedByTagDefinition(),
144-
AuthorTagDefinition::NAME => new AuthorTagDefinition(),
145113
VersionTagDefinition::NAME => new VersionTagDefinition(),
146114
TemplateTagDefinition::NAME => new TemplateTagDefinition(),
147115
TemplateCovariantTagDefinition::NAME => new TemplateCovariantTagDefinition(),
148116
TemplateContravariantTagDefinition::NAME => new TemplateContravariantTagDefinition(),
149-
SinceTagDefinition::NAME => new SinceTagDefinition(),
150117
DeprecatedTagDefinition::NAME => new DeprecatedTagDefinition(),
151-
LicenseTagDefinition::NAME => new LicenseTagDefinition(),
152118
VarTagDefinition::NAME => new VarTagDefinition(),
153-
GlobalTagDefinition::NAME => new GlobalTagDefinition(),
154119
SuppressTagDefinition::NAME => new SuppressTagDefinition(),
155-
SourceTagDefinition::NAME => new SourceTagDefinition(),
156120
MethodTagDefinition::NAME => new MethodTagDefinition(),
157-
ExampleTagDefinition::NAME => new ExampleTagDefinition(),
158-
AccessTagDefinition::NAME => new AccessTagDefinition(),
159-
NameTagDefinition::NAME => new NameTagDefinition(),
160-
StaticTagDefinition::NAME => new StaticTagDefinition(),
161-
StaticVarTagDefinition::NAME => new StaticVarTagDefinition(),
162121
];
163122
}
164123

@@ -183,15 +142,12 @@ final class StandardPlatform implements PlatformInterface
183142
*/
184143
public iterable $combinators {
185144
get => [
186-
VisibilityCombinator::NAME => new VisibilityCombinator(),
187145
UriCombinator::NAME => new UriCombinator(),
188146
UrlCombinator::NAME => new UrlCombinator(),
189147
ReferenceCombinator::NAME => new ReferenceCombinator(),
190148
TypeCombinator::NAME => new TypeCombinator($this->typeParser),
191149
CallableTypeCombinator::NAME => new CallableTypeCombinator($this->typeParser),
192150
VariableCombinator::NAME => new VariableCombinator(),
193-
AuthorNameCombinator::NAME => new AuthorNameCombinator(),
194-
EmailCombinator::NAME => new EmailCombinator(),
195151
IntegerCombinator::NAME => new IntegerCombinator(),
196152
IssueNameCombinator::NAME => new IssueNameCombinator(),
197153
VersionCombinator::NAME => new VersionCombinator(),

0 commit comments

Comments
 (0)