Skip to content

Commit 2f5cbed

Browse files
authored
Merge pull request #438 from mspirkov/fix-standard-tag-factory-2
Fix the creation of tags with types in `StandardTagFactory`
2 parents 2ae140d + ab84cf5 commit 2f5cbed

File tree

2 files changed

+53
-7
lines changed

2 files changed

+53
-7
lines changed

src/DocBlock/StandardTagFactory.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,9 @@
3535
use phpDocumentor\Reflection\DocBlock\Tags\Generic;
3636
use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
3737
use phpDocumentor\Reflection\DocBlock\Tags\Link as LinkTag;
38-
use phpDocumentor\Reflection\DocBlock\Tags\Method;
3938
use phpDocumentor\Reflection\DocBlock\Tags\See as SeeTag;
4039
use phpDocumentor\Reflection\DocBlock\Tags\Since;
4140
use phpDocumentor\Reflection\DocBlock\Tags\Source;
42-
use phpDocumentor\Reflection\DocBlock\Tags\TemplateCovariant;
43-
use phpDocumentor\Reflection\DocBlock\Tags\Throws;
4441
use phpDocumentor\Reflection\DocBlock\Tags\Uses;
4542
use phpDocumentor\Reflection\DocBlock\Tags\Version;
4643
use phpDocumentor\Reflection\FqsenResolver;
@@ -92,14 +89,10 @@ final class StandardTagFactory implements TagFactory
9289
'author' => Author::class,
9390
'covers' => Covers::class,
9491
'deprecated' => Deprecated::class,
95-
// 'example' => '\phpDocumentor\Reflection\DocBlock\Tags\Example',
9692
'link' => LinkTag::class,
97-
'method' => Method::class,
9893
'see' => SeeTag::class,
9994
'since' => Since::class,
10095
'source' => Source::class,
101-
'template-covariant' => TemplateCovariant::class,
102-
'throw' => Throws::class,
10396
'uses' => Uses::class,
10497
'version' => Version::class,
10598
];
@@ -172,6 +165,7 @@ public static function createInstance(FqsenResolver $fqsenResolver): self
172165
$tagFactory->registerTagHandler('extends', $phpstanTagFactory);
173166
$tagFactory->registerTagHandler('implements', $phpstanTagFactory);
174167
$tagFactory->registerTagHandler('template', $phpstanTagFactory);
168+
$tagFactory->registerTagHandler('template-covariant', $phpstanTagFactory);
175169
$tagFactory->registerTagHandler('template-extends', $phpstanTagFactory);
176170
$tagFactory->registerTagHandler('template-implements', $phpstanTagFactory);
177171
$tagFactory->registerTagHandler('throws', $phpstanTagFactory);

tests/unit/DocBlock/StandardTagFactoryTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,23 @@
2222
use phpDocumentor\Reflection\Assets\CustomTagFactory;
2323
use phpDocumentor\Reflection\DocBlock\Tags\Author;
2424
use phpDocumentor\Reflection\DocBlock\Tags\Deprecated;
25+
use phpDocumentor\Reflection\DocBlock\Tags\Extends_;
2526
use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
2627
use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter;
2728
use phpDocumentor\Reflection\DocBlock\Tags\Generic;
29+
use phpDocumentor\Reflection\DocBlock\Tags\Implements_;
30+
use phpDocumentor\Reflection\DocBlock\Tags\Method;
31+
use phpDocumentor\Reflection\DocBlock\Tags\Mixin;
32+
use phpDocumentor\Reflection\DocBlock\Tags\Param;
33+
use phpDocumentor\Reflection\DocBlock\Tags\Property;
34+
use phpDocumentor\Reflection\DocBlock\Tags\PropertyRead;
35+
use phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite;
36+
use phpDocumentor\Reflection\DocBlock\Tags\Return_;
2837
use phpDocumentor\Reflection\DocBlock\Tags\See;
38+
use phpDocumentor\Reflection\DocBlock\Tags\Template;
39+
use phpDocumentor\Reflection\DocBlock\Tags\TemplateCovariant;
40+
use phpDocumentor\Reflection\DocBlock\Tags\Throws;
41+
use phpDocumentor\Reflection\DocBlock\Tags\Var_;
2942
use phpDocumentor\Reflection\Fqsen;
3043
use phpDocumentor\Reflection\FqsenResolver;
3144
use phpDocumentor\Reflection\TypeResolver;
@@ -544,4 +557,43 @@ public function invalidTagProvider(): array
544557
['@tag@invalid'],
545558
];
546559
}
560+
561+
/**
562+
* @param class-string $expectedClass
563+
*
564+
* @dataProvider provideCreateWithTagWithTypesData
565+
*/
566+
public function testCreateWithTagWithTypes(string $input, string $expectedClass): void
567+
{
568+
$tagFactory = StandardTagFactory::createInstance(new FqsenResolver());
569+
$tag = $tagFactory->create($input);
570+
571+
$this->assertInstanceOf($expectedClass, $tag);
572+
}
573+
574+
/**
575+
* @return list<array{string, class-string}>
576+
*/
577+
public static function provideCreateWithTagWithTypesData(): array
578+
{
579+
return [
580+
['@mixin Foo', Mixin::class],
581+
['@method string do()', Method::class],
582+
['@param Foo $bar', Param::class],
583+
['@property-read Foo $bar', PropertyRead::class],
584+
['@property Foo $bar', Property::class],
585+
['@property-write Foo $bar', PropertyWrite::class],
586+
['@return string', Return_::class],
587+
['@throws Throwable', Throws::class],
588+
['@var string $var', Var_::class],
589+
['@template T', Template::class],
590+
['@template-covariant T', TemplateCovariant::class],
591+
['@extends Foo<Bar>', Extends_::class],
592+
['@implements Foo<Bar>', Implements_::class],
593+
594+
// TODO: add factories for this tags
595+
// ['@template-extends Foo', TemplateExtends::class],
596+
// ['@template-implements Foo', TemplateImplements::class],
597+
];
598+
}
547599
}

0 commit comments

Comments
 (0)