Skip to content

Commit aaa5a53

Browse files
author
Kirill Nesmeyanov
committed
Reorganize tag provider
1 parent 54bbfe4 commit aaa5a53

File tree

1 file changed

+49
-23
lines changed

1 file changed

+49
-23
lines changed

src/Provider/StandardTagProvider.php

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,55 @@
5050
final class StandardTagProvider
5151
{
5252
/**
53-
* @var list<non-empty-lowercase-string>
53+
* - For psalm see {@link https://github.com/vimeo/psalm/blob/5.16.0/src/Psalm/DocComment.php#L21}.
54+
* - For phpstan see {@link https://github.com/phpstan/phpstan-src/blob/1.10.44/src/Rules/PhpDoc/InvalidPHPStanDocTagRule.php#L23}.
55+
* - For phan see {@link https://github.com/phan/phan/blob/5.4.2/src/Phan/Language/Element/Comment/Builder.php}.
56+
*
57+
* @var array<non-empty-lowercase-string, list<non-empty-lowercase-string>>
5458
*/
5559
private const COMMON_PREFIXES = [
56-
'psalm',
57-
'phpstan',
58-
'phan'
60+
'psalm' => [
61+
'return', 'param', 'template', 'var', 'type',
62+
'template-covariant', 'property', 'property-read', 'property-write', 'method',
63+
'assert', 'assert-if-true', 'assert-if-false', 'suppress',
64+
'ignore-nullable-return', 'override-property-visibility',
65+
'override-method-visibility', 'seal-properties', 'seal-methods',
66+
'no-seal-properties', 'no-seal-methods',
67+
'ignore-falsable-return', 'variadic', 'pure',
68+
'ignore-variable-method', 'ignore-variable-property', 'internal',
69+
'taint-sink', 'taint-source', 'assert-untainted', 'scope-this',
70+
'mutation-free', 'external-mutation-free', 'immutable', 'readonly',
71+
'allow-private-mutation', 'readonly-allow-private-mutation',
72+
'yield', 'trace', 'import-type', 'flow', 'taint-specialize', 'taint-escape',
73+
'taint-unescape', 'self-out', 'consistent-constructor', 'stub-override',
74+
'require-extends', 'require-implements', 'param-out', 'ignore-var',
75+
'consistent-templates', 'if-this-is', 'this-out', 'check-type', 'check-type-exact',
76+
'api', 'inheritors',
77+
],
78+
'phpstan' => [
79+
'param', 'param-out', 'var', 'extends', 'implements', 'use',
80+
'template', 'template-contravariant', 'template-covariant',
81+
'return', 'throws', 'ignore-next-line', 'ignore-line', 'method',
82+
'pure', 'impure', 'immutable', 'type', 'import-type', 'property',
83+
'property-read', 'property-write', 'consistent-constructor', 'assert',
84+
'assert-if-true', 'assert-if-false', 'self-out', 'this-out',
85+
'allow-private-mutation', 'readonly', 'readonly-allow-private-mutation',
86+
],
87+
'phan' => [
88+
'abstract', 'assert', 'assert', 'assert-false-condition',
89+
'assert-true-condition', 'closure-scope',
90+
'constructor-used-for-side-effects', 'extends',
91+
'external-mutation-free', 'file-suppress',
92+
'forbid-undeclared-magic-methods', 'forbid-undeclared-magic-properties',
93+
'hardcode-return-type', 'ignore-reference', 'immutable', 'inherits',
94+
'mandatory-param', 'method', 'mixin', 'output-reference', 'override',
95+
'param', 'property', 'property-read', 'property-write', 'pure',
96+
'read-only', 'real-return', 'real-throws', 'return',
97+
'side-effect-free', 'suppress', 'suppress-current-line',
98+
'suppress-next-line', 'suppress-next-next-line',
99+
'suppress-previous-line', 'template', 'type', 'unused-param',
100+
'var', 'write-only',
101+
]
59102
];
60103

61104
/**
@@ -135,23 +178,6 @@ private function getAllTags(): iterable
135178
}
136179
}
137180

138-
/**
139-
* @return iterable<array-key, non-empty-lowercase-string>
140-
*/
141-
private function getAllPrefixes(): iterable
142-
{
143-
return self::COMMON_PREFIXES;
144-
}
145-
146-
/**
147-
* @param non-empty-lowercase-string $tag
148-
* @param non-empty-lowercase-string $prefix
149-
*/
150-
private function isSupportedBy(string $tag, string $prefix): bool
151-
{
152-
return true;
153-
}
154-
155181
/**
156182
* @return iterable<non-empty-lowercase-string, TagFactoryInterface>
157183
*/
@@ -160,8 +186,8 @@ public function getTags(): iterable
160186
foreach ($this->getAllTags() as $tag => $factory) {
161187
yield $tag => $factory;
162188

163-
foreach ($this->getAllPrefixes() as $prefix) {
164-
if (!$this->isSupportedBy($tag, $prefix)) {
189+
foreach (self::COMMON_PREFIXES as $prefix => $tags) {
190+
if (!\in_array($tag, $tags, true)) {
165191
continue;
166192
}
167193

0 commit comments

Comments
 (0)