diff --git a/src/DocBlock/Tags/Factory/AbstractExtendsFactory.php b/src/DocBlock/Tags/Factory/AbstractExtendsFactory.php new file mode 100644 index 0000000..3325f2f --- /dev/null +++ b/src/DocBlock/Tags/Factory/AbstractExtendsFactory.php @@ -0,0 +1,32 @@ +descriptionFactory = $descriptionFactory; + $this->typeResolver = $typeResolver; + } + + public function supports(PhpDocTagNode $node, Context $context): bool + { + return $node->value instanceof ExtendsTagValueNode && $node->name === $this->tagName; + } +} diff --git a/src/DocBlock/Tags/Factory/AbstractImplementsFactory.php b/src/DocBlock/Tags/Factory/AbstractImplementsFactory.php new file mode 100644 index 0000000..45341cf --- /dev/null +++ b/src/DocBlock/Tags/Factory/AbstractImplementsFactory.php @@ -0,0 +1,32 @@ +descriptionFactory = $descriptionFactory; + $this->typeResolver = $typeResolver; + } + + public function supports(PhpDocTagNode $node, Context $context): bool + { + return $node->value instanceof ImplementsTagValueNode && $node->name === $this->tagName; + } +} diff --git a/src/DocBlock/Tags/Factory/ExtendsFactory.php b/src/DocBlock/Tags/Factory/ExtendsFactory.php index 87611ab..37d36b0 100644 --- a/src/DocBlock/Tags/Factory/ExtendsFactory.php +++ b/src/DocBlock/Tags/Factory/ExtendsFactory.php @@ -12,20 +12,16 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; use phpDocumentor\Reflection\DocBlock\Tags\Extends_; use PHPStan\PhpDocParser\Ast\PhpDoc\ExtendsTagValueNode; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; -use phpDocumentor\Reflection\DocBlock\Tags\TemplateExtends; /** * @internal This class is not part of the BC promise of this library. */ -class ExtendsFactory implements PHPStanFactory +final class ExtendsFactory extends AbstractExtendsFactory { - private DescriptionFactory $descriptionFactory; - private TypeResolver $typeResolver; - public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) { - $this->descriptionFactory = $descriptionFactory; - $this->typeResolver = $typeResolver; + parent::__construct($typeResolver, $descriptionFactory); + $this->tagName = '@extends'; } public function create(PhpDocTagNode $node, Context $context): Tag @@ -38,16 +34,9 @@ class ExtendsFactory implements PHPStanFactory $description = $tagValue->description; } - $class = $node->name === '@extends' ? Extends_::class : TemplateExtends::class; - - return new $class( + return new Extends_( $this->typeResolver->createType($tagValue->type, $context), - $this->descriptionFactory->create($tagValue->description, $context) + $this->descriptionFactory->create($description, $context) ); } - - public function supports(PhpDocTagNode $node, Context $context): bool - { - return $node->value instanceof ExtendsTagValueNode && ($node->name === '@extends' || $node->name === '@template-extends'); - } } diff --git a/src/DocBlock/Tags/Factory/ImplementsFactory.php b/src/DocBlock/Tags/Factory/ImplementsFactory.php index 5f1e9db..e6266a2 100644 --- a/src/DocBlock/Tags/Factory/ImplementsFactory.php +++ b/src/DocBlock/Tags/Factory/ImplementsFactory.php @@ -12,20 +12,16 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; use phpDocumentor\Reflection\DocBlock\Tags\Implements_; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; use PHPStan\PhpDocParser\Ast\PhpDoc\ImplementsTagValueNode; -use phpDocumentor\Reflection\DocBlock\Tags\TemplateImplements; /** * @internal This class is not part of the BC promise of this library. */ -class ImplementsFactory implements PHPStanFactory +final class ImplementsFactory extends AbstractImplementsFactory { - private DescriptionFactory $descriptionFactory; - private TypeResolver $typeResolver; - public function __construct(TypeResolver $typeResolver, DescriptionFactory $descriptionFactory) { - $this->descriptionFactory = $descriptionFactory; - $this->typeResolver = $typeResolver; + parent::__construct($typeResolver, $descriptionFactory); + $this->tagName = '@implements'; } public function create(PhpDocTagNode $node, Context $context): Tag @@ -38,16 +34,9 @@ class ImplementsFactory implements PHPStanFactory $description = $tagValue->description; } - $class = $node->name === '@implements' ? Implements_::class : TemplateImplements::class; - - return new $class( + return new Implements_( $this->typeResolver->createType($tagValue->type, $context), - $this->descriptionFactory->create($tagValue->description, $context) + $this->descriptionFactory->create($description, $context) ); } - - public function supports(PhpDocTagNode $node, Context $context): bool - { - return $node->value instanceof ImplementsTagValueNode && ($node->name === '@implements' || $node->name === '@template-implements'); - } } diff --git a/src/DocBlock/Tags/Factory/TemplateExtendsFactory.php b/src/DocBlock/Tags/Factory/TemplateExtendsFactory.php new file mode 100644 index 0000000..97475f7 --- /dev/null +++ b/src/DocBlock/Tags/Factory/TemplateExtendsFactory.php @@ -0,0 +1,42 @@ +tagName = '@template-extends'; + } + + public function create(PhpDocTagNode $node, Context $context): Tag + { + $tagValue = $node->value; + Assert::isInstanceOf($tagValue, ExtendsTagValueNode::class); + + $description = $tagValue->getAttribute('description'); + if (is_string($description) === false) { + $description = $tagValue->description; + } + + return new TemplateExtends( + $this->typeResolver->createType($tagValue->type, $context), + $this->descriptionFactory->create($description, $context) + ); + } +} diff --git a/src/DocBlock/Tags/Factory/TemplateFactory.php b/src/DocBlock/Tags/Factory/TemplateFactory.php index 63e0b03..3c1aafd 100644 --- a/src/DocBlock/Tags/Factory/TemplateFactory.php +++ b/src/DocBlock/Tags/Factory/TemplateFactory.php @@ -41,7 +41,7 @@ final class TemplateFactory implements PHPStanFactory $tagValue->name, $this->typeResolver->createType($tagValue->bound, $context), $this->typeResolver->createType($tagValue->default, $context), - $this->descriptionFactory->create($tagValue->description, $context) + $this->descriptionFactory->create($description, $context) ); } diff --git a/src/DocBlock/Tags/Factory/TemplateImplementsFactory.php b/src/DocBlock/Tags/Factory/TemplateImplementsFactory.php new file mode 100644 index 0000000..0f69981 --- /dev/null +++ b/src/DocBlock/Tags/Factory/TemplateImplementsFactory.php @@ -0,0 +1,42 @@ +tagName = '@template-implements'; + } + + public function create(PhpDocTagNode $node, Context $context): Tag + { + $tagValue = $node->value; + Assert::isInstanceOf($tagValue, ImplementsTagValueNode::class); + + $description = $tagValue->getAttribute('description'); + if (is_string($description) === false) { + $description = $tagValue->description; + } + + return new TemplateImplements( + $this->typeResolver->createType($tagValue->type, $context), + $this->descriptionFactory->create($description, $context) + ); + } +} diff --git a/src/DocBlockFactory.php b/src/DocBlockFactory.php index 581cb39..408fbc3 100644 --- a/src/DocBlockFactory.php +++ b/src/DocBlockFactory.php @@ -32,6 +32,8 @@ use phpDocumentor\Reflection\DocBlock\Tags\Factory\ImplementsFactory; use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyReadFactory; use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyWriteFactory; use phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractPHPStanFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\TemplateExtendsFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\TemplateImplementsFactory; use function trim; use function count; @@ -81,8 +83,10 @@ final class DocBlockFactory implements DocBlockFactoryInterface new PropertyWriteFactory($typeResolver, $descriptionFactory), new MethodFactory($typeResolver, $descriptionFactory), new ImplementsFactory($typeResolver, $descriptionFactory), - new TemplateFactory($typeResolver, $descriptionFactory), new ExtendsFactory($typeResolver, $descriptionFactory), + new TemplateFactory($typeResolver, $descriptionFactory), + new TemplateImplementsFactory($typeResolver, $descriptionFactory), + new TemplateExtendsFactory($typeResolver, $descriptionFactory), ); $tagFactory->addService($descriptionFactory);