From b5676cd55420c11cda592e3ee4fe336e9be0243b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A1=D0=BF=D0=B8?= =?UTF-8?q?=D1=80=D0=BA=D0=BE=D0=B2?= Date: Tue, 20 Jan 2026 16:10:37 +0400 Subject: [PATCH] Fix the creation of tags with types in `StandardTagFactory` --- src/DocBlock/StandardTagFactory.php | 6 +-- .../unit/DocBlock/StandardTagFactoryTest.php | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/DocBlock/StandardTagFactory.php b/src/DocBlock/StandardTagFactory.php index e911f7e..57e9639 100644 --- a/src/DocBlock/StandardTagFactory.php +++ b/src/DocBlock/StandardTagFactory.php @@ -92,14 +92,10 @@ final class StandardTagFactory implements TagFactory 'author' => Author::class, 'covers' => Covers::class, 'deprecated' => Deprecated::class, - // 'example' => '\phpDocumentor\Reflection\DocBlock\Tags\Example', 'link' => LinkTag::class, - 'method' => Method::class, 'see' => SeeTag::class, 'since' => Since::class, 'source' => Source::class, - 'template-covariant' => TemplateCovariant::class, - 'throw' => Throws::class, 'uses' => Uses::class, 'version' => Version::class, ]; @@ -161,6 +157,7 @@ final class StandardTagFactory implements TagFactory $tagFactory->addService($descriptionFactory); $tagFactory->addService($typeResolver); + $tagFactory->registerTagHandler('mixin', $phpstanTagFactory); $tagFactory->registerTagHandler('param', $phpstanTagFactory); $tagFactory->registerTagHandler('var', $phpstanTagFactory); $tagFactory->registerTagHandler('return', $phpstanTagFactory); @@ -171,6 +168,7 @@ final class StandardTagFactory implements TagFactory $tagFactory->registerTagHandler('extends', $phpstanTagFactory); $tagFactory->registerTagHandler('implements', $phpstanTagFactory); $tagFactory->registerTagHandler('template', $phpstanTagFactory); + $tagFactory->registerTagHandler('template-covariant', $phpstanTagFactory); $tagFactory->registerTagHandler('template-extends', $phpstanTagFactory); $tagFactory->registerTagHandler('template-implements', $phpstanTagFactory); $tagFactory->registerTagHandler('throws', $phpstanTagFactory); diff --git a/tests/unit/DocBlock/StandardTagFactoryTest.php b/tests/unit/DocBlock/StandardTagFactoryTest.php index 3f8311f..dae8c99 100644 --- a/tests/unit/DocBlock/StandardTagFactoryTest.php +++ b/tests/unit/DocBlock/StandardTagFactoryTest.php @@ -25,7 +25,18 @@ use phpDocumentor\Reflection\DocBlock\Tags\Deprecated; use phpDocumentor\Reflection\DocBlock\Tags\Formatter; use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter; use phpDocumentor\Reflection\DocBlock\Tags\Generic; +use phpDocumentor\Reflection\DocBlock\Tags\Method; +use phpDocumentor\Reflection\DocBlock\Tags\Mixin; +use phpDocumentor\Reflection\DocBlock\Tags\Param; +use phpDocumentor\Reflection\DocBlock\Tags\Property; +use phpDocumentor\Reflection\DocBlock\Tags\PropertyRead; +use phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite; +use phpDocumentor\Reflection\DocBlock\Tags\Return_; use phpDocumentor\Reflection\DocBlock\Tags\See; +use phpDocumentor\Reflection\DocBlock\Tags\TagWithType; +use phpDocumentor\Reflection\DocBlock\Tags\TemplateCovariant; +use phpDocumentor\Reflection\DocBlock\Tags\Throws; +use phpDocumentor\Reflection\DocBlock\Tags\Var_; use phpDocumentor\Reflection\Fqsen; use phpDocumentor\Reflection\FqsenResolver; use phpDocumentor\Reflection\TypeResolver; @@ -544,4 +555,36 @@ class StandardTagFactoryTest extends TestCase ['@tag@invalid'], ]; } + + /** + * @dataProvider provideCreateWithTagWithTypesData + * + * @param class-string $expectedClass + */ + public function testCreateWithTagWithTypes(string $input, string $expectedClass): void + { + $tagFactory = StandardTagFactory::createInstance(new FqsenResolver()); + $tag = $tagFactory->create($input); + + $this->assertInstanceOf($expectedClass, $tag); + } + + /** + * @return list + */ + public static function provideCreateWithTagWithTypesData(): array + { + return [ + ['@mixin Foo', Mixin::class], + ['@method string do()', Method::class], + ['@param Foo $bar', Param::class], + ['@property-read Foo $bar', PropertyRead::class], + ['@property Foo $bar', Property::class], + ['@property-write Foo $bar', PropertyWrite::class], + ['@return string', Return_::class], + ['@throws Throwable', Throws::class], + ['@var string $var', Var_::class], + ['@template-covariant string', TemplateCovariant::class], + ]; + } }