Skip to content

Commit b5676cd

Browse files
committed
Fix the creation of tags with types in StandardTagFactory
1 parent 0d14a1a commit b5676cd

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

src/DocBlock/StandardTagFactory.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,10 @@ final class StandardTagFactory implements TagFactory
9292
'author' => Author::class,
9393
'covers' => Covers::class,
9494
'deprecated' => Deprecated::class,
95-
// 'example' => '\phpDocumentor\Reflection\DocBlock\Tags\Example',
9695
'link' => LinkTag::class,
97-
'method' => Method::class,
9896
'see' => SeeTag::class,
9997
'since' => Since::class,
10098
'source' => Source::class,
101-
'template-covariant' => TemplateCovariant::class,
102-
'throw' => Throws::class,
10399
'uses' => Uses::class,
104100
'version' => Version::class,
105101
];
@@ -161,6 +157,7 @@ public static function createInstance(FqsenResolver $fqsenResolver): self
161157

162158
$tagFactory->addService($descriptionFactory);
163159
$tagFactory->addService($typeResolver);
160+
$tagFactory->registerTagHandler('mixin', $phpstanTagFactory);
164161
$tagFactory->registerTagHandler('param', $phpstanTagFactory);
165162
$tagFactory->registerTagHandler('var', $phpstanTagFactory);
166163
$tagFactory->registerTagHandler('return', $phpstanTagFactory);
@@ -171,6 +168,7 @@ public static function createInstance(FqsenResolver $fqsenResolver): self
171168
$tagFactory->registerTagHandler('extends', $phpstanTagFactory);
172169
$tagFactory->registerTagHandler('implements', $phpstanTagFactory);
173170
$tagFactory->registerTagHandler('template', $phpstanTagFactory);
171+
$tagFactory->registerTagHandler('template-covariant', $phpstanTagFactory);
174172
$tagFactory->registerTagHandler('template-extends', $phpstanTagFactory);
175173
$tagFactory->registerTagHandler('template-implements', $phpstanTagFactory);
176174
$tagFactory->registerTagHandler('throws', $phpstanTagFactory);

tests/unit/DocBlock/StandardTagFactoryTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,18 @@
2525
use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
2626
use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter;
2727
use phpDocumentor\Reflection\DocBlock\Tags\Generic;
28+
use phpDocumentor\Reflection\DocBlock\Tags\Method;
29+
use phpDocumentor\Reflection\DocBlock\Tags\Mixin;
30+
use phpDocumentor\Reflection\DocBlock\Tags\Param;
31+
use phpDocumentor\Reflection\DocBlock\Tags\Property;
32+
use phpDocumentor\Reflection\DocBlock\Tags\PropertyRead;
33+
use phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite;
34+
use phpDocumentor\Reflection\DocBlock\Tags\Return_;
2835
use phpDocumentor\Reflection\DocBlock\Tags\See;
36+
use phpDocumentor\Reflection\DocBlock\Tags\TagWithType;
37+
use phpDocumentor\Reflection\DocBlock\Tags\TemplateCovariant;
38+
use phpDocumentor\Reflection\DocBlock\Tags\Throws;
39+
use phpDocumentor\Reflection\DocBlock\Tags\Var_;
2940
use phpDocumentor\Reflection\Fqsen;
3041
use phpDocumentor\Reflection\FqsenResolver;
3142
use phpDocumentor\Reflection\TypeResolver;
@@ -544,4 +555,36 @@ public function invalidTagProvider(): array
544555
['@tag@invalid'],
545556
];
546557
}
558+
559+
/**
560+
* @dataProvider provideCreateWithTagWithTypesData
561+
*
562+
* @param class-string $expectedClass
563+
*/
564+
public function testCreateWithTagWithTypes(string $input, string $expectedClass): void
565+
{
566+
$tagFactory = StandardTagFactory::createInstance(new FqsenResolver());
567+
$tag = $tagFactory->create($input);
568+
569+
$this->assertInstanceOf($expectedClass, $tag);
570+
}
571+
572+
/**
573+
* @return list<array{string, class-string}>
574+
*/
575+
public static function provideCreateWithTagWithTypesData(): array
576+
{
577+
return [
578+
['@mixin Foo', Mixin::class],
579+
['@method string do()', Method::class],
580+
['@param Foo $bar', Param::class],
581+
['@property-read Foo $bar', PropertyRead::class],
582+
['@property Foo $bar', Property::class],
583+
['@property-write Foo $bar', PropertyWrite::class],
584+
['@return string', Return_::class],
585+
['@throws Throwable', Throws::class],
586+
['@var string $var', Var_::class],
587+
['@template-covariant string', TemplateCovariant::class],
588+
];
589+
}
547590
}

0 commit comments

Comments
 (0)